RegisterMail.vue 8.1 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 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. // 人机校验通过标识符
  100. const isHMVerifySuccess = ref(false);
  101. const getVerifyCodeLoading = ref(false);
  102. // 倒计时展示
  103. const countDownNumer = ref(0);
  104. // 获取验证码的文案
  105. const codeText = computed(() => {
  106. return isReacquireCode.value
  107. ? L["register"]["重新获取"]
  108. : L["register"]["获取验证码"];
  109. });
  110. // 注册邮箱时按钮置灰状态
  111. const nextDisabled = computed(() => !email.value || !emailCode.value);
  112. // 获取验证码
  113. const getVerifyCode = () => {
  114. // 校验邮箱非空以及格式
  115. if (!validateEmail()) return;
  116. if (!isHMVerifySuccess.value) {
  117. modalVisible.value = true;
  118. } else {
  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. // 人机验证成功
  147. const verifySuccess = () => {
  148. isHMVerifySuccess.value = true;
  149. modalVisible.value = false;
  150. getVerifyCode();
  151. };
  152. // 人机校验失败
  153. const verifyFail = () => {
  154. showMessage({
  155. message: L["register"]["校验不通过"],
  156. type: "warning",
  157. });
  158. };
  159. // 校验邮箱
  160. const validateEmail = () => {
  161. //邮箱非空的验证
  162. if (!email.value) {
  163. emailErrorMsg.value = L["请输入邮箱"];
  164. return false;
  165. }
  166. // 邮箱格式验证
  167. emailCalc.value = checkEmail(email.value);
  168. if (emailCalc.value !== true) {
  169. emailErrorMsg.value = emailCalc.value;
  170. return false;
  171. }
  172. emailErrorMsg.value = "";
  173. return true;
  174. };
  175. // 邮箱验证码验证
  176. const validateEmailCode = () => {
  177. if (!emailCode.value) {
  178. emailCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  179. return false;
  180. }
  181. emailCodeErrorMsg.value = "";
  182. return true;
  183. };
  184. const next = () => {
  185. if (!validateEmail() || !validateEmailCode()) return;
  186. post("v3/member/front/active/check/verification/code", {
  187. email: email.value,
  188. type: 1,
  189. verificationCode: emailCode.value,
  190. }).then((res) => {
  191. if (res.state == 200) {
  192. showMessage({
  193. message: L["register"]["注册成功"],
  194. type: "success",
  195. });
  196. //成功提示,并返回到登录页面
  197. emits('success')
  198. } else {
  199. //提示错误
  200. showMessage({
  201. message: res.msg,
  202. type: "warning",
  203. });
  204. }
  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. display: block;
  329. margin-top: 35px;
  330. background: $colorMain;
  331. color: #fff;
  332. text-align: center;
  333. border-radius: 2px;
  334. height: 45px;
  335. line-height: 45px;
  336. font-size: 18px;
  337. letter-spacing: 0px;
  338. &:hover {
  339. opacity: 0.9;
  340. }
  341. &.disabled {
  342. background-color: #909399;
  343. pointer-events: none;
  344. }
  345. }
  346. }
  347. </style>