RegisterMail.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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="showHMVerify"
  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. const getVerifyCodeLoading = ref(false);
  97. const nextActionLoading = ref(false);
  98. // 倒计时展示
  99. const countDownNumer = ref(0);
  100. // 获取验证码的文案
  101. const codeText = computed(() => {
  102. return isReacquireCode.value
  103. ? L["register"]["重新获取"]
  104. : L["register"]["获取验证码"];
  105. });
  106. // 注册邮箱时按钮置灰状态
  107. const nextDisabled = computed(() => !email.value || !emailCode.value);
  108. //开启人机校验
  109. const showHMVerify = () => {
  110. // 校验邮箱非空以及格式
  111. if (!validateEmail()) return;
  112. modalVisible.value = true;
  113. };
  114. // 获取验证码
  115. const getVerifyCode = () => {
  116. getVerifyCodeLoading.value = true;
  117. post("v3/member/front/active/verification/code", {
  118. email: email.value,
  119. source: 1,
  120. type: 1,
  121. })
  122. .then((res) => {
  123. if (res.state === 200) {
  124. showMessage({
  125. message: L["register"]["验证码已发送"],
  126. type: "success",
  127. });
  128. // 设置倒计时
  129. startCountdown(60, (time) => (countDownNumer.value = time));
  130. isReacquireCode.value = true;
  131. } else {
  132. showMessage({
  133. message: res.msg,
  134. type: "warning",
  135. });
  136. }
  137. })
  138. .finally(() => {
  139. getVerifyCodeLoading.value = false;
  140. });
  141. };
  142. // 人机验证成功
  143. const verifySuccess = () => {
  144. modalVisible.value = false;
  145. getVerifyCode();
  146. };
  147. // 人机校验失败
  148. const verifyFail = () => {
  149. showMessage({
  150. message: L["register"]["校验不通过"],
  151. type: "warning",
  152. });
  153. };
  154. // 校验邮箱
  155. const validateEmail = () => {
  156. //邮箱非空的验证
  157. if (!email.value) {
  158. emailErrorMsg.value = L["请输入邮箱"];
  159. return false;
  160. }
  161. // 邮箱格式验证
  162. emailCalc.value = checkEmail(email.value);
  163. if (emailCalc.value !== true) {
  164. emailErrorMsg.value = emailCalc.value;
  165. return false;
  166. }
  167. emailErrorMsg.value = "";
  168. return true;
  169. };
  170. // 邮箱验证码验证
  171. const validateEmailCode = () => {
  172. if (!emailCode.value) {
  173. emailCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  174. return false;
  175. }
  176. emailCodeErrorMsg.value = "";
  177. return true;
  178. };
  179. const next = () => {
  180. if (!validateEmail() || !validateEmailCode()) return;
  181. nextActionLoading.value = true;
  182. post("v3/member/front/active/check/verification/code", {
  183. email: email.value,
  184. type: 1,
  185. verificationCode: emailCode.value,
  186. })
  187. .then((res) => {
  188. if (res.state == 200) {
  189. // showMessage({
  190. // message: L["register"]["注册成功"],
  191. // type: "success",
  192. // });
  193. //成功提示,并返回到登录页面
  194. emits("success", email.value);
  195. } else {
  196. //提示错误
  197. showMessage({
  198. message: res.msg,
  199. type: "warning",
  200. });
  201. }
  202. })
  203. .finally(() => {
  204. nextActionLoading.value = false;
  205. });
  206. };
  207. //清空输入框内容
  208. const clearInputVal = (type) => {
  209. email.value = "";
  210. };
  211. </script>
  212. <style lang="scss">
  213. .register-verify-model {
  214. .el-dialog__title {
  215. font-weight: 900 !important;
  216. }
  217. .el-dialog__body {
  218. display: flex;
  219. justify-content: center;
  220. align-items: center;
  221. }
  222. }
  223. </style>
  224. <style lang="scss" scoped>
  225. .center {
  226. padding: 30px 30px 40px;
  227. .item {
  228. position: relative;
  229. margin-top: 15px;
  230. border-radius: 2px;
  231. &:first-child {
  232. margin-top: 0;
  233. }
  234. .icon {
  235. position: absolute;
  236. left: 1px;
  237. top: 1px;
  238. width: 50px;
  239. text-align: center;
  240. height: 38px;
  241. background: #f8f8f8;
  242. .input {
  243. border: 1px solid #e8e8e8;
  244. height: 40px;
  245. padding: 0 44px 0 60px;
  246. width: 326px;
  247. }
  248. }
  249. .input {
  250. border: 1px solid #e8e8e8;
  251. height: 40px;
  252. padding: 0 44px 0 60px;
  253. width: 326px;
  254. }
  255. &.code {
  256. .input {
  257. padding-right: 10px;
  258. width: 150px;
  259. }
  260. }
  261. }
  262. .cancel {
  263. position: absolute;
  264. right: 0;
  265. top: 1px;
  266. width: 44px;
  267. height: 38px;
  268. cursor: pointer;
  269. :before {
  270. position: absolute;
  271. top: 9px;
  272. left: 14px;
  273. }
  274. }
  275. .error {
  276. margin-top: 10px;
  277. position: relative;
  278. color: $colorMain;
  279. height: 16px;
  280. line-height: 16px;
  281. }
  282. .verify-code {
  283. display: flex;
  284. width: 326px;
  285. height: 40px;
  286. margin-top: 10px;
  287. &-icon {
  288. width: 50px;
  289. display: flex;
  290. justify-content: center;
  291. align-items: center;
  292. border: 1px solid #e8e8e8;
  293. border-right: none;
  294. background: #f8f8f8;
  295. img {
  296. width: 20px;
  297. }
  298. }
  299. input {
  300. border: 1px solid #e8e8e8;
  301. border-left: none;
  302. border-right: none;
  303. height: 40px;
  304. padding: 0 0 0 10px;
  305. width: 190px;
  306. }
  307. &-accept {
  308. display: flex;
  309. justify-content: center;
  310. align-items: center;
  311. width: 90px;
  312. .el-button {
  313. width: 100%;
  314. height: 100%;
  315. color: #666;
  316. background: #f8f8f8;
  317. border-left: none;
  318. border-radius: 0;
  319. font-size: 12px;
  320. &:hover {
  321. border-color: #e8e8e8;
  322. color: $colorMain;
  323. }
  324. }
  325. }
  326. }
  327. .submit {
  328. margin-top: 35px;
  329. background: $colorMain;
  330. color: #fff;
  331. text-align: center;
  332. border-radius: 2px;
  333. width: 100%;
  334. height: 45px;
  335. font-size: 18px;
  336. letter-spacing: 0px;
  337. &:hover {
  338. opacity: 0.9;
  339. }
  340. &.disabled {
  341. background-color: #909399;
  342. }
  343. }
  344. }
  345. </style>