RegisterMail.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 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" v-if="emailErrorMsg">
  23. <span
  24. style="color: #e1251b; font-size: 14px"
  25. class="iconfont icon-jubao"
  26. ></span>
  27. {{ emailErrorMsg }}
  28. </div>
  29. <!-- 邮箱验证码 -->
  30. <div class="verify-code">
  31. <span class="verify-code-icon">
  32. <img src="/register/mail_success.png" alt="" />
  33. </span>
  34. <input
  35. type="text"
  36. v-model="emailCode"
  37. :placeholder="L['请输入验证码']"
  38. class="input"
  39. autocomplete="off"
  40. />
  41. <span class="verify-code-accept">
  42. <el-button
  43. @click="getVerifyCode"
  44. :disabled="countDownNumer"
  45. :loading="getVerifyCodeLoading"
  46. >
  47. <span>{{ codeText }}</span>
  48. <span v-if="countDownNumer">{{ `(${countDownNumer})` }}</span>
  49. </el-button>
  50. </span>
  51. </div>
  52. <div class="error" v-if="emailCodeErrorMsg">
  53. <span
  54. style="color: #e1251b; font-size: 14px"
  55. class="iconfont icon-jubao"
  56. ></span>
  57. {{ emailCodeErrorMsg }}
  58. </div>
  59. <el-button
  60. @click="next"
  61. :class="{ submit: true, disabled: nextDisabled }"
  62. :disabled="nextDisabled"
  63. :loading="nextActionLoading"
  64. >{{ L["下一步"] }}</el-button
  65. >
  66. <el-dialog
  67. :title="L['register']['滑动验证']"
  68. destroy-on-close
  69. width="500px"
  70. center
  71. modal-class="register-verify-model"
  72. v-model="modalVisible"
  73. >
  74. <SliderVerify
  75. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  76. @onSuccess="verifySuccess"
  77. @onFail="verifyFail"
  78. />
  79. </el-dialog>
  80. </div>
  81. </template>
  82. <script setup>
  83. import { getCurLanguage } from "@/composables/common.js";
  84. import { showMessage, startCountdown } from "@/utils/common";
  85. const emits = defineEmits(["success"]);
  86. const L = getCurLanguage();
  87. const emailCalc = ref();
  88. const email = ref(""); //邮箱
  89. const emailCode = ref(""); // 邮箱验证码
  90. const emailErrorMsg = ref(); //错误提示
  91. const emailCodeErrorMsg = ref(); //验证码错误提示
  92. // 人机验证弹窗显示标识
  93. const modalVisible = ref(false);
  94. // 重新获取验证码标识
  95. const isReacquireCode = ref(false);
  96. // 人机校验通过标识符
  97. const isHMVerifySuccess = ref(false);
  98. const getVerifyCodeLoading = ref(false);
  99. const nextActionLoading = ref(false);
  100. // 倒计时展示
  101. const countDownNumer = ref(0);
  102. // 获取验证码的文案
  103. const codeText = computed(() => {
  104. return isReacquireCode.value
  105. ? L["register"]["重新获取"]
  106. : L["register"]["获取验证码"];
  107. });
  108. // 注册邮箱时按钮置灰状态
  109. const nextDisabled = computed(() => !email.value || !emailCode.value);
  110. // 获取验证码
  111. const getVerifyCode = () => {
  112. // 校验邮箱非空以及格式
  113. if (!validateEmail()) return;
  114. if (!isHMVerifySuccess.value) {
  115. modalVisible.value = true;
  116. } else {
  117. getVerifyCodeLoading.value = true;
  118. post("v3/member/front/active/verification/code", {
  119. email: email.value,
  120. source: 1,
  121. type: 1,
  122. })
  123. .then((res) => {
  124. if (res.state === 200) {
  125. showMessage({
  126. message: L["register"]["验证码已发送"],
  127. type: "success",
  128. });
  129. // 设置倒计时
  130. startCountdown(60, (time) => (countDownNumer.value = time));
  131. isReacquireCode.value = true;
  132. } else {
  133. showMessage({
  134. message: res.msg,
  135. type: "warning",
  136. });
  137. }
  138. })
  139. .finally(() => {
  140. getVerifyCodeLoading.value = false;
  141. });
  142. }
  143. };
  144. // 人机验证成功
  145. const verifySuccess = () => {
  146. isHMVerifySuccess.value = true;
  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. padding: 30px 30px 40px;
  230. .item {
  231. position: relative;
  232. margin-top: 15px;
  233. border-radius: 2px;
  234. &:first-child {
  235. margin-top: 0;
  236. }
  237. .icon {
  238. position: absolute;
  239. left: 1px;
  240. top: 1px;
  241. width: 50px;
  242. text-align: center;
  243. height: 38px;
  244. background: #f8f8f8;
  245. .input {
  246. border: 1px solid #e8e8e8;
  247. height: 40px;
  248. padding: 0 44px 0 60px;
  249. width: 326px;
  250. }
  251. }
  252. .input {
  253. border: 1px solid #e8e8e8;
  254. height: 40px;
  255. padding: 0 44px 0 60px;
  256. width: 326px;
  257. }
  258. &.code {
  259. .input {
  260. padding-right: 10px;
  261. width: 150px;
  262. }
  263. }
  264. }
  265. .cancel {
  266. position: absolute;
  267. right: 0;
  268. top: 1px;
  269. width: 44px;
  270. height: 38px;
  271. cursor: pointer;
  272. :before {
  273. position: absolute;
  274. top: 9px;
  275. left: 14px;
  276. }
  277. }
  278. .error {
  279. margin-top: 10px;
  280. position: relative;
  281. color: $colorMain;
  282. height: 16px;
  283. line-height: 16px;
  284. }
  285. .verify-code {
  286. display: flex;
  287. width: 326px;
  288. height: 40px;
  289. margin-top: 10px;
  290. &-icon {
  291. width: 50px;
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. border: 1px solid #e8e8e8;
  296. border-right: none;
  297. background: #f8f8f8;
  298. img {
  299. width: 20px;
  300. }
  301. }
  302. input {
  303. border: 1px solid #e8e8e8;
  304. border-left: none;
  305. border-right: none;
  306. height: 40px;
  307. padding: 0 0 0 10px;
  308. width: 190px;
  309. }
  310. &-accept {
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. width: 90px;
  315. .el-button {
  316. width: 100%;
  317. height: 100%;
  318. color: #666;
  319. background: #f8f8f8;
  320. border-left: none;
  321. border-radius: 0;
  322. font-size: 12px;
  323. &:hover {
  324. border-color: #e8e8e8;
  325. color: $colorMain;
  326. }
  327. }
  328. }
  329. }
  330. .submit {
  331. margin-top: 35px;
  332. background: $colorMain;
  333. color: #fff;
  334. text-align: center;
  335. border-radius: 2px;
  336. width: 100%;
  337. height: 45px;
  338. font-size: 18px;
  339. letter-spacing: 0px;
  340. &:hover {
  341. opacity: 0.9;
  342. }
  343. &.disabled {
  344. background-color: #909399;
  345. }
  346. }
  347. }
  348. </style>