RegisterMail.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div class="center">
  3. <p style="width: 296px">
  4. {{ L["register"]["我们将向您的邮箱发送验证码,该邮件将用作登录用户名"] }}
  5. </p>
  6. <div class="item account">
  7. <span
  8. style="color: #bbb; font-size: 19px; padding-top: 7px"
  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
  19. data-type="userName"
  20. class="cancel"
  21. @click="clearInputVal"
  22. >
  23. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  24. </div>
  25. </div>
  26. <div class="error" v-if="emailErrorMsg">
  27. <span
  28. style="color: #e1251b; font-size: 14px"
  29. class="iconfont icon-jubao"
  30. ></span>
  31. {{ emailErrorMsg }}
  32. </div>
  33. <!-- 邮箱验证码 -->
  34. <div class="verify-code">
  35. <span class="verify-code-icon">
  36. <img src="/mail_success.png" alt="" />
  37. </span>
  38. <input
  39. type="text"
  40. v-model="emailCode"
  41. :placeholder="L['请输入验证码']"
  42. class="input"
  43. autocomplete="off"
  44. />
  45. <span class="verify-code-accept">
  46. <el-button
  47. @click="getVerifyCode"
  48. :disabled="countDownNumer"
  49. :loading="getVerifyCodeLoading"
  50. >
  51. <span>{{ codeText }}</span>
  52. <span v-if="countDownNumer">{{ `(${countDownNumer})` }}</span>
  53. </el-button>
  54. </span>
  55. </div>
  56. <div class="error" v-if="emailCodeErrorMsg">
  57. <span
  58. style="color: #e1251b; font-size: 14px"
  59. class="iconfont icon-jubao"
  60. ></span>
  61. {{ emailCodeErrorMsg }}
  62. </div>
  63. <a
  64. href="javascript:void(0)"
  65. @click="next"
  66. :class="{ submit: true, disabled: nextDisabled }"
  67. >{{ L["下一步"] }}</a
  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 L = getCurLanguage();
  89. const emailCalc = ref();
  90. const email = ref(""); //邮箱
  91. const emailCode = ref(""); // 邮箱验证码
  92. const emailErrorMsg = ref(); //错误提示
  93. const emailCodeErrorMsg = ref(); //验证码错误提示
  94. // 人机验证弹窗显示标识
  95. const modalVisible = ref(false);
  96. // 重新获取验证码标识
  97. const isReacquireCode = ref(false);
  98. // 人机校验通过标识符
  99. const isHMVerifySuccess = ref(false);
  100. const getVerifyCodeLoading = 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 getVerifyCode = () => {
  113. // 校验邮箱非空以及格式
  114. if (!validateEmail()) return;
  115. if (!isHMVerifySuccess.value) {
  116. modalVisible.value = true;
  117. } else {
  118. getVerifyCodeLoading.value = true;
  119. post("v3/member/front/active/verification/code", {
  120. email: email.value,
  121. source: 1,
  122. type: 1,
  123. })
  124. .then((res) => {
  125. if (res.state === 200) {
  126. showMessage({
  127. message: L["register"]["验证码已发送"],
  128. type: "success",
  129. });
  130. // 设置倒计时
  131. startCountdown(60, (time) => (countDownNumer.value = time));
  132. isReacquireCode.value = true;
  133. } else {
  134. showMessage({
  135. message: res.msg,
  136. type: "warning",
  137. });
  138. }
  139. })
  140. .finally(() => {
  141. getVerifyCodeLoading.value = false;
  142. });
  143. }
  144. };
  145. // 人机验证成功
  146. const verifySuccess = () => {
  147. isHMVerifySuccess.value = true;
  148. modalVisible.value = false;
  149. getVerifyCode();
  150. };
  151. // 人机校验失败
  152. const verifyFail = () => {
  153. showMessage({
  154. message: L["register"]["校验不通过"],
  155. type: "warning",
  156. });
  157. };
  158. // 校验邮箱
  159. const validateEmail = () => {
  160. //邮箱非空的验证
  161. if (!email.value) {
  162. emailErrorMsg.value = L["请输入邮箱"];
  163. return false;
  164. }
  165. // 邮箱格式验证
  166. emailCalc.value = checkEmail(email.value);
  167. if (emailCalc.value !== true) {
  168. emailErrorMsg.value = emailCalc.value;
  169. return false;
  170. }
  171. emailErrorMsg.value = "";
  172. return true;
  173. };
  174. // 邮箱验证码验证
  175. const validateEmailCode = () => {
  176. if (!emailCode.value) {
  177. emailCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  178. return false;
  179. }
  180. emailCodeErrorMsg.value = "";
  181. return true;
  182. };
  183. const next = () => {
  184. if (!validateEmail() || !validateEmailCode()) return;
  185. post("v3/member/front/active/check/verification/code", {
  186. email: email.value,
  187. type: 1,
  188. verificationCode: emailCode.value,
  189. }).then((res) => {
  190. if (res.state == 200) {
  191. showMessage({
  192. message: L["register"]["注册成功"],
  193. type: "success",
  194. });
  195. //成功提示,并返回到登录页面
  196. currentStep.value = "registerAccount";
  197. // setTimeout(() => {
  198. // goToPage("/login");
  199. // }, 500);
  200. } else {
  201. //提示错误
  202. showMessage({
  203. message: res.msg,
  204. type: "warning",
  205. });
  206. }
  207. });
  208. };
  209. //清空输入框内容
  210. const clearInputVal = (type) => {
  211. email.value = "";
  212. };
  213. </script>
  214. <style lang="scss">
  215. .register-verify-model {
  216. .el-dialog__title {
  217. font-weight: 900 !important;
  218. }
  219. .el-dialog__body {
  220. display: flex;
  221. justify-content: center;
  222. align-items: center;
  223. }
  224. }
  225. </style>
  226. <style lang="scss" scoped>
  227. .center {
  228. padding: 30px 30px 40px;
  229. .item {
  230. position: relative;
  231. margin-top: 15px;
  232. border-radius: 2px;
  233. &:first-child {
  234. margin-top: 0;
  235. }
  236. .icon {
  237. position: absolute;
  238. left: 1px;
  239. top: 1px;
  240. width: 50px;
  241. text-align: center;
  242. height: 38px;
  243. background: #f8f8f8;
  244. .input {
  245. border: 1px solid #e8e8e8;
  246. height: 40px;
  247. padding: 0 44px 0 60px;
  248. width: 326px;
  249. }
  250. }
  251. .input {
  252. border: 1px solid #e8e8e8;
  253. height: 40px;
  254. padding: 0 44px 0 60px;
  255. width: 326px;
  256. }
  257. &.code {
  258. .input {
  259. padding-right: 10px;
  260. width: 150px;
  261. }
  262. }
  263. }
  264. .cancel {
  265. position: absolute;
  266. right: 0;
  267. top: 1px;
  268. width: 44px;
  269. height: 38px;
  270. cursor: pointer;
  271. :before {
  272. position: absolute;
  273. top: 9px;
  274. left: 14px;
  275. }
  276. }
  277. .error {
  278. margin-top: 10px;
  279. position: relative;
  280. color: $colorMain;
  281. height: 16px;
  282. line-height: 16px;
  283. }
  284. .verify-code {
  285. display: flex;
  286. width: 326px;
  287. height: 40px;
  288. margin-top: 10px;
  289. &-icon {
  290. width: 50px;
  291. display: flex;
  292. justify-content: center;
  293. align-items: center;
  294. border: 1px solid #e8e8e8;
  295. border-right: none;
  296. background: #f8f8f8;
  297. img {
  298. width: 20px;
  299. }
  300. }
  301. input {
  302. border: 1px solid #e8e8e8;
  303. border-left: none;
  304. border-right: none;
  305. height: 40px;
  306. padding: 0 0 0 10px;
  307. width: 190px;
  308. }
  309. &-accept {
  310. display: flex;
  311. justify-content: center;
  312. align-items: center;
  313. width: 90px;
  314. .el-button {
  315. width: 100%;
  316. height: 100%;
  317. color: #666;
  318. background: #f8f8f8;
  319. border-left: none;
  320. border-radius: 0;
  321. font-size: 12px;
  322. &:hover {
  323. border-color: #e8e8e8;
  324. color: $colorMain;
  325. }
  326. }
  327. }
  328. }
  329. .submit {
  330. display: block;
  331. margin-top: 35px;
  332. background: $colorMain;
  333. color: #fff;
  334. text-align: center;
  335. border-radius: 2px;
  336. height: 45px;
  337. line-height: 45px;
  338. font-size: 18px;
  339. letter-spacing: 0px;
  340. &:hover {
  341. opacity: 0.9;
  342. }
  343. &.disabled {
  344. background-color: #909399;
  345. pointer-events: none;
  346. }
  347. }
  348. }
  349. </style>