emailTemplate.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. const sendEmail = require('./Email')
  2. class emailTemplate {
  3. stramptoTime(time) {
  4. if (time < 10)
  5. return '';
  6. return new Date(+time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
  7. }
  8. async checkEmail(email, code) {
  9. const time = new Date().getTime()
  10. await sendEmail(email, 'RunForge - 邮箱验证码',
  11. `<html lang="zh-CN">
  12. <head>
  13. <meta charset="UTF-8">
  14. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  15. <title>RunForge - 邮箱验证码</title>
  16. <style>
  17. body {
  18. font-family: Arial, sans-serif;
  19. background-color: #f4f4f4;
  20. margin: 0;
  21. padding: 0;
  22. }
  23. .container {
  24. width: 80%;
  25. margin: 20px auto;
  26. background-color: #fff;
  27. padding: 20px;
  28. border-radius: 8px;
  29. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  30. }
  31. .head {
  32. display: flex;
  33. justify-content: center;
  34. align-items: center;
  35. gap:10px;
  36. color: #2c3e50;
  37. }
  38. p {
  39. font-size: 16px;
  40. color: #34495e;
  41. line-height: 1.6;
  42. text-indent: 2em;
  43. }
  44. .code {
  45. margin: 20px 0;
  46. font-size: 1.5em;
  47. text-align: center;
  48. font-weight: bold;
  49. }
  50. .important {
  51. color: #e74c3c;
  52. font-weight: bold;
  53. }
  54. .footer {
  55. font-size: 14px;
  56. text-align: center;
  57. color: #7f8c8d;
  58. margin-top: 50px;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="container">
  64. <div class="head">
  65. <h2>RunForge - 邮箱验证码</h2>
  66. </div>
  67. <p>尊敬的用户:</p>
  68. <p>您正在本站进行邮箱验证操作,如非您本人操作,请忽略此邮件。</p>
  69. <p>您的验证码为:</p>
  70. <div class="code">
  71. ${code}
  72. </div>
  73. <p class="important">验证码5分钟内有效,超时请重新获取</p>
  74. <p class="footer">Copyright © 2025 RunForge</p>
  75. </div>
  76. </body>
  77. </html>`
  78. )
  79. }
  80. async registerSuccess(email, username) {
  81. const time = new Date().getTime()
  82. await sendEmail(email, '您已成功注册RunForge账号',
  83. `<html lang="zh-CN">
  84. <head>
  85. <meta charset="UTF-8">
  86. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  87. <title>RunForge - 邮箱验证码</title>
  88. <style>
  89. body {
  90. font-family: Arial, sans-serif;
  91. background-color: #f4f4f4;
  92. margin: 0;
  93. padding: 0;
  94. }
  95. .container {
  96. width: 80%;
  97. margin: 20px auto;
  98. background-color: #fff;
  99. padding: 20px;
  100. border-radius: 8px;
  101. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  102. }
  103. .head {
  104. display: flex;
  105. justify-content: center;
  106. align-items: center;
  107. gap: 10px;
  108. color: #2c3e50;
  109. }
  110. p {
  111. font-size: 16px;
  112. color: #34495e;
  113. line-height: 1.6;
  114. text-indent: 2em;
  115. }
  116. .info {
  117. background-color: #ecf0f1;
  118. padding: 15px;
  119. border-radius: 5px;
  120. margin: 20px 0;
  121. }
  122. .info p {
  123. margin: 5px 0;
  124. }
  125. .important {
  126. color: #e74c3c;
  127. font-weight: bold;
  128. }
  129. .footer {
  130. font-size: 14px;
  131. text-align: center;
  132. color: #7f8c8d;
  133. margin-top: 50px;
  134. }
  135. </style>
  136. </head>
  137. <body>
  138. <div class="container">
  139. <div class="head">
  140. <h2>RunForge - 邮箱验证码</h2>
  141. </div>
  142. <p>尊敬的 ${username}:</p>
  143. <p>您已成功注册RunForge账号:</p>
  144. <div class="info">
  145. <p><strong>用户名:</strong> ${username}</p>
  146. <p><strong>注册时间:</strong> ${this.stramptoTime(time)}</p>
  147. </div>
  148. <p class="footer">Copyright © 2025 RunForge</p>
  149. </div>
  150. </body>
  151. </html>`
  152. )
  153. }
  154. async updateSuccess(email, data) {
  155. await sendEmail(email, 'RunForge - 乐跑账号更新成功提醒',
  156. `<html lang="zh-CN">
  157. <head>
  158. <meta charset="UTF-8">
  159. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  160. <title>RunForge - 乐跑账号更新成功提醒</title>
  161. <style>
  162. body {
  163. font-family: Arial, sans-serif;
  164. background-color: #f4f4f4;
  165. margin: 0;
  166. padding: 0;
  167. }
  168. .container {
  169. width: 80%;
  170. margin: 20px auto;
  171. background-color: #fff;
  172. padding: 20px;
  173. border-radius: 8px;
  174. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  175. }
  176. .head {
  177. display: flex;
  178. justify-content: center;
  179. align-items: center;
  180. gap: 10px;
  181. color: #2c3e50;
  182. }
  183. p {
  184. font-size: 16px;
  185. color: #34495e;
  186. line-height: 1.6;
  187. text-indent: 2em;
  188. }
  189. .info {
  190. background-color: #ecf0f1;
  191. padding: 15px;
  192. border-radius: 5px;
  193. margin: 20px 0;
  194. }
  195. .info p {
  196. margin: 5px 0;
  197. }
  198. .important {
  199. color: #e74c3c;
  200. font-weight: bold;
  201. }
  202. .footer {
  203. font-size: 14px;
  204. text-align: center;
  205. color: #7f8c8d;
  206. margin-top: 50px;
  207. }
  208. </style>
  209. </head>
  210. <body>
  211. <div class="container">
  212. <div class="head">
  213. <h2>RunForge - 乐跑账号更新成功提醒</h2>
  214. </div>
  215. <p>尊敬的 ${data.name}:</p>
  216. <p>您已成功更新乐跑账号登录信息:</p>
  217. <div class="info">
  218. <p><strong>学号:</strong> ${data.account}</p>
  219. <p><strong>年级:</strong> ${data.grade_id}</p>
  220. <p><strong>学院:</strong> ${data.academy_name}</p>
  221. <p><strong>更新时间:</strong> ${this.stramptoTime(new Date().getTime())}</p>
  222. </div>
  223. <p class="important">${data.auto_run === 0 ? '当前未开启自动乐跑,登录成功后如需进行乐跑,请前往 RunForge 手动执行乐跑操作。' : '当前已开启自动乐跑,登录成功后系统将自动进行乐跑,请留意邮箱提醒。'}</p>
  224. <p class="important">请避免在其他设备上登录“智慧体育”小程序,否则将导致登录失效,届时需要重新进行登录操作。</p>
  225. <p class="important">如有疑问请联系RunForge客服。</p>
  226. <p class="footer">Copyright © 2025 RunForge</p>
  227. </div>
  228. </body>
  229. </html>`
  230. )
  231. }
  232. async lepaoSuccess(email, data) {
  233. await sendEmail(email, 'RunForge - 乐跑成功提醒',
  234. `<html lang="zh-CN">
  235. <head>
  236. <meta charset="UTF-8">
  237. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  238. <title>RunForge - 乐跑成功提醒</title>
  239. <style>
  240. body {
  241. font-family: Arial, sans-serif;
  242. background-color: #f4f4f4;
  243. margin: 0;
  244. padding: 0;
  245. }
  246. .container {
  247. width: 80%;
  248. margin: 20px auto;
  249. background-color: #fff;
  250. padding: 20px;
  251. border-radius: 8px;
  252. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  253. }
  254. .head {
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. gap: 10px;
  259. color: #2c3e50;
  260. }
  261. p {
  262. font-size: 16px;
  263. color: #34495e;
  264. line-height: 1.6;
  265. text-indent: 2em;
  266. }
  267. .info {
  268. background-color: #ecf0f1;
  269. padding: 15px;
  270. border-radius: 5px;
  271. margin: 20px 0;
  272. }
  273. .info p {
  274. margin: 5px 0;
  275. }
  276. .important {
  277. color: #e74c3c;
  278. font-weight: bold;
  279. }
  280. .footer {
  281. font-size: 14px;
  282. text-align: center;
  283. color: #7f8c8d;
  284. margin-top: 50px;
  285. }
  286. </style>
  287. </head>
  288. <body>
  289. <div class="container">
  290. <div class="head">
  291. <h2>RunForge - 乐跑成功提醒</h2>
  292. </div>
  293. <p>尊敬的 ${data.name}:</p>
  294. <p>RunForge已成功为您进行乐跑:</p>
  295. <div class="info">
  296. <p><strong>学号:</strong> ${data.account}</p>
  297. <p><strong>跑区:</strong> ${data.pass_tit}</p>
  298. <p><strong>跑步时间:</strong> ${this.formatSecondsToMinSec(data.time)}</p>
  299. <p><strong>平均配速:</strong> ${this.calculatePace(data.time, data.distance)}</p>
  300. <p><strong>跑步距离:</strong> ${data.distance} Km</p>
  301. </div>
  302. <p class="important">请您开启了自动乐跑,请避免在其他设备上登录“智慧体育”小程序,否则将导致登录失效。</p>
  303. <p class="important">如有疑问请联系RunForge客服。</p>
  304. <p class="footer">Copyright © 2025 RunForge</p>
  305. </div>
  306. </body>
  307. </html>`
  308. )
  309. }
  310. async lepaoFail(email, data) {
  311. const time = new Date().getTime()
  312. await sendEmail(email, 'RunForge - 乐跑失败提醒',
  313. `<html lang="zh-CN">
  314. <head>
  315. <meta charset="UTF-8">
  316. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  317. <title>RunForge - 乐跑失败提醒</title>
  318. <style>
  319. body {
  320. font-family: Arial, sans-serif;
  321. background-color: #f4f4f4;
  322. margin: 0;
  323. padding: 0;
  324. }
  325. .container {
  326. width: 80%;
  327. margin: 20px auto;
  328. background-color: #fff;
  329. padding: 20px;
  330. border-radius: 8px;
  331. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  332. }
  333. .head {
  334. display: flex;
  335. justify-content: center;
  336. align-items: center;
  337. gap: 10px;
  338. color: #2c3e50;
  339. }
  340. p {
  341. font-size: 16px;
  342. color: #34495e;
  343. line-height: 1.6;
  344. text-indent: 2em;
  345. }
  346. .info {
  347. background-color: #ecf0f1;
  348. padding: 15px;
  349. border-radius: 5px;
  350. margin: 20px 0;
  351. }
  352. .info p {
  353. margin: 5px 0;
  354. }
  355. .important {
  356. color: #e74c3c;
  357. font-weight: bold;
  358. }
  359. .footer {
  360. font-size: 14px;
  361. text-align: center;
  362. color: #7f8c8d;
  363. margin-top: 50px;
  364. }
  365. </style>
  366. </head>
  367. <body>
  368. <div class="container">
  369. <div class="head">
  370. <h2>RunForge - 乐跑失败提醒</h2>
  371. </div>
  372. <p>尊敬的 ${data.name}:</p>
  373. <p>RunForge在尝试为您乐跑时遇到错误:</p>
  374. <div class="info">
  375. <p><strong>学号:</strong> ${data.account}</p>
  376. <p><strong>时间:</strong> ${this.stramptoTime(time)}</p>
  377. <p><strong>失败原因:</strong> ${data.reason}</p>
  378. </div>
  379. <p class="important">若登录失效请启动RunForge乐跑登录器重新登录“智慧体育”小程序。</p>
  380. <p class="important">如有疑问请联系RunForge客服。</p>
  381. <p class="footer">Copyright © 2025 RunForge</p>
  382. </div>
  383. </body>
  384. </html>`
  385. )
  386. }
  387. // 时长计算
  388. formatSecondsToMinSec(totalSeconds) {
  389. const minutes = Math.floor(totalSeconds / 60);
  390. const seconds = totalSeconds % 60;
  391. return `${minutes}分${seconds.toString().padStart(2, '0')}秒`;
  392. }
  393. // 配速计算
  394. calculatePace(seconds, kilometers) {
  395. const paceInSeconds = seconds / kilometers;
  396. const minutes = Math.floor(paceInSeconds / 60);
  397. const remainingSeconds = Math.round(paceInSeconds % 60);
  398. return `${minutes}'${remainingSeconds.toString().padStart(2, '0')}''`;
  399. }
  400. }
  401. const EmailTemplate = new emailTemplate()
  402. module.exports = EmailTemplate