RegisterMail.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <div class="center">
  3. <p style="width: 100%; text-align: center;">
  4. {{ L["register"]["我们将向您的邮箱发送验证码,该邮件将用作登录用户名"] }}
  5. </p>
  6. <div class="item account">
  7. <span
  8. style="color: #bbb; font-size: 19px"
  9. class="icon iconfont icon-wode"
  10. ></span>
  11. <input
  12. type="text"
  13. v-model="email"
  14. :placeholder="L['请输入邮箱']"
  15. class="input"
  16. autocomplete="off"
  17. />
  18. <div data-type="userName" class="cancel" @click="clearInputVal">
  19. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  20. </div>
  21. </div>
  22. <div class="error">
  23. <span
  24. v-if="emailErrorMsg"
  25. style="color: #e1251b; font-size: 14px"
  26. class="iconfont icon-jubao"
  27. ></span>
  28. {{ emailErrorMsg }}
  29. </div>
  30. <!-- 邮箱验证码 -->
  31. <div class="verify-code">
  32. <span class="verify-code-icon">
  33. <img src="/register/mail_success.png" alt="" />
  34. </span>
  35. <input
  36. type="text"
  37. v-model="emailCode"
  38. :placeholder="L['请输入验证码']"
  39. class="input"
  40. autocomplete="off"
  41. />
  42. <span class="verify-code-accept">
  43. <el-button
  44. type="primary"
  45. @click="showHMVerify"
  46. :disabled="countDownNumer"
  47. :loading="getVerifyCodeLoading"
  48. >
  49. <span>{{ codeText }}</span>
  50. <span v-if="countDownNumer">{{ `(${countDownNumer})` }}</span>
  51. </el-button>
  52. </span>
  53. </div>
  54. <div class="error">
  55. <span
  56. v-if="emailCodeErrorMsg"
  57. style="color: #e1251b; font-size: 14px"
  58. class="iconfont icon-jubao"
  59. ></span>
  60. {{ emailCodeErrorMsg }}
  61. </div>
  62. <el-button
  63. @click="next"
  64. :class="{ submit: true, disabled: nextDisabled }"
  65. :disabled="nextDisabled"
  66. :loading="nextActionLoading"
  67. >{{ L["下一步"] }}</el-button
  68. >
  69. <el-dialog
  70. :title="L['register']['滑动验证']"
  71. destroy-on-close
  72. width="500px"
  73. center
  74. modal-class="register-verify-model"
  75. v-model="modalVisible"
  76. >
  77. <SliderVerify
  78. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  79. @onSuccess="verifySuccess"
  80. @onFail="verifyFail"
  81. />
  82. </el-dialog>
  83. </div>
  84. </template>
  85. <script setup>
  86. import { getCurLanguage } from "@/composables/common.js";
  87. import { showMessage, startCountdown } from "@/utils/common";
  88. const emits = defineEmits(["success"]);
  89. const L = getCurLanguage();
  90. const emailCalc = ref();
  91. const email = ref(""); //邮箱
  92. const emailCode = ref(""); // 邮箱验证码
  93. const emailErrorMsg = ref(); //错误提示
  94. const emailCodeErrorMsg = ref(); //验证码错误提示
  95. // 人机验证弹窗显示标识
  96. const modalVisible = ref(false);
  97. // 重新获取验证码标识
  98. const isReacquireCode = ref(false);
  99. const getVerifyCodeLoading = ref(false);
  100. const nextActionLoading = ref(false);
  101. // 倒计时展示
  102. const countDownNumer = ref(0);
  103. // 获取验证码的文案
  104. const codeText = computed(() => {
  105. return isReacquireCode.value
  106. ? L["register"]["重新获取"]
  107. : L["register"]["获取验证码"];
  108. });
  109. // 注册邮箱时按钮置灰状态
  110. const nextDisabled = computed(() => !email.value || !emailCode.value);
  111. //开启人机校验
  112. const showHMVerify = () => {
  113. // 校验邮箱非空以及格式
  114. if (!validateEmail()) return;
  115. modalVisible.value = true;
  116. };
  117. // 获取验证码
  118. const getVerifyCode = () => {
  119. getVerifyCodeLoading.value = true;
  120. post("v3/member/front/active/verification/code", {
  121. email: email.value,
  122. source: 1,
  123. type: 1,
  124. })
  125. .then((res) => {
  126. if (res.state === 200) {
  127. showMessage({
  128. message: L["register"]["验证码已发送"],
  129. type: "success",
  130. });
  131. // 设置倒计时
  132. startCountdown(60, (time) => (countDownNumer.value = time));
  133. isReacquireCode.value = true;
  134. } else {
  135. showMessage({
  136. message: res.msg,
  137. type: "warning",
  138. });
  139. }
  140. })
  141. .finally(() => {
  142. getVerifyCodeLoading.value = false;
  143. });
  144. };
  145. // 人机验证成功
  146. const verifySuccess = () => {
  147. modalVisible.value = false;
  148. getVerifyCode();
  149. };
  150. // 人机校验失败
  151. const verifyFail = () => {
  152. showMessage({
  153. message: L["register"]["校验不通过"],
  154. type: "warning",
  155. });
  156. };
  157. // 校验邮箱
  158. const validateEmail = () => {
  159. //邮箱非空的验证
  160. if (!email.value) {
  161. emailErrorMsg.value = L["请输入邮箱"];
  162. return false;
  163. }
  164. // 邮箱格式验证
  165. emailCalc.value = checkEmail(email.value);
  166. if (emailCalc.value !== true) {
  167. emailErrorMsg.value = emailCalc.value;
  168. return false;
  169. }
  170. emailErrorMsg.value = "";
  171. return true;
  172. };
  173. // 邮箱验证码验证
  174. const validateEmailCode = () => {
  175. if (!emailCode.value) {
  176. emailCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  177. return false;
  178. }
  179. emailCodeErrorMsg.value = "";
  180. return true;
  181. };
  182. const next = () => {
  183. if (!validateEmail() || !validateEmailCode()) return;
  184. nextActionLoading.value = true;
  185. post("v3/member/front/active/check/verification/code", {
  186. email: email.value,
  187. type: 1,
  188. verificationCode: emailCode.value,
  189. })
  190. .then((res) => {
  191. if (res.state == 200) {
  192. // showMessage({
  193. // message: L["register"]["注册成功"],
  194. // type: "success",
  195. // });
  196. //成功提示,并返回到登录页面
  197. emits("success", email.value);
  198. } else {
  199. //提示错误
  200. showMessage({
  201. message: res.msg,
  202. type: "warning",
  203. });
  204. }
  205. })
  206. .finally(() => {
  207. nextActionLoading.value = false;
  208. });
  209. };
  210. //清空输入框内容
  211. const clearInputVal = (type) => {
  212. email.value = "";
  213. };
  214. </script>
  215. <style lang="scss">
  216. .register-verify-model {
  217. .el-dialog__title {
  218. font-weight: 900 !important;
  219. }
  220. .el-dialog__body {
  221. display: flex;
  222. justify-content: center;
  223. align-items: center;
  224. }
  225. }
  226. </style>
  227. <style lang="scss" scoped>
  228. .center {
  229. flex: 1;
  230. height: 100%;
  231. position: relative;
  232. padding: 0 28px;
  233. margin-top: 60px;
  234. .item {
  235. position: relative;
  236. margin-top: 25px;
  237. border-radius: 2px;
  238. input::placeholder {
  239. // font-weight: 400;
  240. font-size: $fontE;
  241. color: rgba(40,46,48,0.6);
  242. }
  243. ::-webkit-input-placeholder {
  244. // font-weight: 400;
  245. font-size: $fontE;
  246. color: rgba(40,46,48,0.6);
  247. }
  248. /* 使用webkit内核的浏览器 */
  249. :-moz-placeholder {
  250. // font-weight: 400;
  251. font-size: $fontE;
  252. color: rgba(40,46,48,0.6);
  253. }
  254. /* Firefox版本19+ */
  255. :-ms-input-placeholder {
  256. // font-weight: 400;
  257. font-size: $fontE;
  258. color: rgba(40,46,48,0.6);
  259. }
  260. &:first-child {
  261. margin-top: 0;
  262. }
  263. .icon {
  264. position: absolute;
  265. left: 1px;
  266. top: 1px;
  267. width: 50px;
  268. text-align: center;
  269. height: 46px;
  270. line-height: 46px;
  271. background: #f8f8f8;
  272. }
  273. .input {
  274. border: 1px solid #e8e8e8;
  275. height: 48px;
  276. padding: 0 44px 0 60px;
  277. width: 431px;
  278. }
  279. &.code {
  280. .input {
  281. padding-right: 10px;
  282. width: 150px;
  283. }
  284. }
  285. }
  286. .cancel {
  287. position: absolute;
  288. right: 0px;
  289. top: 2px;
  290. width: 44px;
  291. height: 46px;
  292. text-align: center;
  293. line-height: 46px;
  294. cursor: pointer;
  295. }
  296. .error {
  297. margin-top: 10px;
  298. position: relative;
  299. color: #e2231a;
  300. height: 16px;
  301. line-height: 16px;
  302. }
  303. .verify-code {
  304. display: flex;
  305. width: 431px;
  306. height: 48px;
  307. margin-top: 10px;
  308. input::placeholder {
  309. // font-weight: 400;
  310. font-size: $fontE;
  311. color: rgba(40,46,48,0.6);
  312. }
  313. ::-webkit-input-placeholder {
  314. // font-weight: 400;
  315. font-size: $fontE;
  316. color: rgba(40,46,48,0.6);
  317. }
  318. /* 使用webkit内核的浏览器 */
  319. :-moz-placeholder {
  320. // font-weight: 400;
  321. font-size: $fontE;
  322. color: rgba(40,46,48,0.6);
  323. }
  324. /* Firefox版本19+ */
  325. :-ms-input-placeholder {
  326. // font-weight: 400;
  327. font-size: $fontE;
  328. color: rgba(40,46,48,0.6);
  329. }
  330. &-icon {
  331. width: 50px;
  332. display: flex;
  333. justify-content: center;
  334. align-items: center;
  335. border: 1px solid #e8e8e8;
  336. border-right: none;
  337. background: #f8f8f8;
  338. img {
  339. width: 20px;
  340. }
  341. }
  342. input {
  343. flex: 1;
  344. width: 100%;
  345. border: 1px solid #e8e8e8;
  346. border-left: none;
  347. border-right: none;
  348. height: 48px;
  349. padding: 0 0 0 10px;
  350. }
  351. &-accept {
  352. display: flex;
  353. justify-content: center;
  354. align-items: center;
  355. width: 90px;
  356. .el-button {
  357. width: 100%;
  358. height: 100%;
  359. // font-weight: bold;
  360. color: #FFFFFF;
  361. background: $colorMain;
  362. border-left: none;
  363. border-radius: 0;
  364. font-size: 12px;
  365. &:hover {
  366. // border-color: #e8e8e8;
  367. // color: $colorMain;
  368. }
  369. }
  370. }
  371. }
  372. .submit {
  373. margin-top: 160px;
  374. background: $colorMain;
  375. color: #fff;
  376. text-align: center;
  377. border-radius: 2px;
  378. width: 100%;
  379. height: 45px;
  380. font-size: 18px;
  381. letter-spacing: 0px;
  382. &:hover {
  383. opacity: 0.9;
  384. }
  385. &.disabled {
  386. background-color: #909399;
  387. }
  388. }
  389. }
  390. </style>