RegisterMail.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 class="icon">
  8. <img src="/login/Mail.png" alt="">
  9. </span>
  10. <input
  11. type="text"
  12. v-model="email"
  13. :placeholder="L['请输入邮箱']"
  14. class="input"
  15. autocomplete="off"
  16. />
  17. <div data-type="userName" class="cancel" @click="clearInputVal">
  18. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  19. </div>
  20. </div>
  21. <div class="error">
  22. <span
  23. v-if="emailErrorMsg"
  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="/login/Code.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. type="primary"
  44. @click="showHMVerify"
  45. :disabled="countDownNumer"
  46. :loading="getVerifyCodeLoading"
  47. >
  48. <span>{{ codeText }}</span>
  49. <span v-if="countDownNumer">{{ `(${countDownNumer})` }}</span>
  50. </el-button>
  51. </span>
  52. </div>
  53. <div class="error">
  54. <span
  55. v-if="emailCodeErrorMsg"
  56. style="color: #e1251b; font-size: 14px"
  57. class="iconfont icon-jubao"
  58. ></span>
  59. {{ emailCodeErrorMsg }}
  60. </div>
  61. <el-button
  62. @click="next"
  63. :class="{ submit: true, disabled: nextDisabled }"
  64. :disabled="nextDisabled"
  65. :loading="nextActionLoading"
  66. >{{ L["下一步"] }}</el-button
  67. >
  68. <el-dialog
  69. :title="L['register']['滑动验证']"
  70. destroy-on-close
  71. width="500px"
  72. center
  73. modal-class="register-verify-model"
  74. v-model="modalVisible"
  75. >
  76. <SliderVerify
  77. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  78. @onSuccess="verifySuccess"
  79. @onFail="verifyFail"
  80. />
  81. </el-dialog>
  82. </div>
  83. </template>
  84. <script setup>
  85. import { getCurLanguage } from "@/composables/common.js";
  86. import { showMessage, startCountdown } from "@/utils/common";
  87. const emits = defineEmits(["success"]);
  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. 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 showHMVerify = () => {
  112. // 校验邮箱非空以及格式
  113. if (!validateEmail()) return;
  114. modalVisible.value = true;
  115. };
  116. // 获取验证码
  117. const getVerifyCode = () => {
  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. const verifySuccess = () => {
  146. modalVisible.value = false;
  147. getVerifyCode();
  148. };
  149. // 人机校验失败
  150. const verifyFail = () => {
  151. showMessage({
  152. message: L["register"]["校验不通过"],
  153. type: "warning",
  154. });
  155. };
  156. // 校验邮箱
  157. const validateEmail = () => {
  158. //邮箱非空的验证
  159. if (!email.value) {
  160. emailErrorMsg.value = L["请输入邮箱"];
  161. return false;
  162. }
  163. // 邮箱格式验证
  164. emailCalc.value = checkEmail(email.value);
  165. if (emailCalc.value !== true) {
  166. emailErrorMsg.value = emailCalc.value;
  167. return false;
  168. }
  169. emailErrorMsg.value = "";
  170. return true;
  171. };
  172. // 邮箱验证码验证
  173. const validateEmailCode = () => {
  174. if (!emailCode.value) {
  175. emailCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  176. return false;
  177. }
  178. emailCodeErrorMsg.value = "";
  179. return true;
  180. };
  181. const next = () => {
  182. if (!validateEmail() || !validateEmailCode()) return;
  183. nextActionLoading.value = true;
  184. post("v3/member/front/active/check/verification/code", {
  185. email: email.value,
  186. type: 1,
  187. verificationCode: emailCode.value,
  188. })
  189. .then((res) => {
  190. if (res.state == 200) {
  191. // showMessage({
  192. // message: L["register"]["注册成功"],
  193. // type: "success",
  194. // });
  195. //成功提示,并返回到登录页面
  196. emits("success", email.value);
  197. } else {
  198. //提示错误
  199. showMessage({
  200. message: res.msg,
  201. type: "warning",
  202. });
  203. }
  204. })
  205. .finally(() => {
  206. nextActionLoading.value = false;
  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. flex: 1;
  229. height: 100%;
  230. position: relative;
  231. padding: 0 28px;
  232. margin-top: 60px;
  233. .item {
  234. position: relative;
  235. margin-top: 25px;
  236. border-radius: 2px;
  237. input::placeholder {
  238. // font-weight: 400;
  239. font-size: $fontE;
  240. color: rgba(40,46,48,0.6);
  241. }
  242. ::-webkit-input-placeholder {
  243. // font-weight: 400;
  244. font-size: $fontE;
  245. color: rgba(40,46,48,0.6);
  246. }
  247. /* 使用webkit内核的浏览器 */
  248. :-moz-placeholder {
  249. // font-weight: 400;
  250. font-size: $fontE;
  251. color: rgba(40,46,48,0.6);
  252. }
  253. /* Firefox版本19+ */
  254. :-ms-input-placeholder {
  255. // font-weight: 400;
  256. font-size: $fontE;
  257. color: rgba(40,46,48,0.6);
  258. }
  259. &:first-child {
  260. margin-top: 0;
  261. }
  262. .icon {
  263. display: flex;
  264. align-items: center;
  265. justify-content: flex-end;
  266. position: absolute;
  267. left: 1px;
  268. top: 1px;
  269. width: 50px;
  270. height: 46px;
  271. img {
  272. width: 22px;
  273. height: 22px;
  274. position: relative;
  275. right: 5px;
  276. }
  277. }
  278. .input {
  279. border: 1px solid #e8e8e8;
  280. height: 48px;
  281. padding: 0 44px 0 60px;
  282. width: 431px;
  283. }
  284. &.code {
  285. .input {
  286. padding-right: 10px;
  287. width: 150px;
  288. }
  289. }
  290. }
  291. .cancel {
  292. position: absolute;
  293. right: 0px;
  294. top: 2px;
  295. width: 44px;
  296. height: 46px;
  297. text-align: center;
  298. line-height: 46px;
  299. cursor: pointer;
  300. }
  301. .error {
  302. margin-top: 10px;
  303. position: relative;
  304. color: #e2231a;
  305. height: 16px;
  306. line-height: 16px;
  307. }
  308. .verify-code {
  309. display: flex;
  310. width: 431px;
  311. height: 48px;
  312. margin-top: 10px;
  313. input::placeholder {
  314. // font-weight: 400;
  315. font-size: $fontE;
  316. color: rgba(40,46,48,0.6);
  317. }
  318. ::-webkit-input-placeholder {
  319. // font-weight: 400;
  320. font-size: $fontE;
  321. color: rgba(40,46,48,0.6);
  322. }
  323. /* 使用webkit内核的浏览器 */
  324. :-moz-placeholder {
  325. // font-weight: 400;
  326. font-size: $fontE;
  327. color: rgba(40,46,48,0.6);
  328. }
  329. /* Firefox版本19+ */
  330. :-ms-input-placeholder {
  331. // font-weight: 400;
  332. font-size: $fontE;
  333. color: rgba(40,46,48,0.6);
  334. }
  335. &-icon {
  336. display: flex;
  337. align-items: center;
  338. justify-content: flex-end;
  339. width: 50px;
  340. height: 48px;
  341. border: 1px solid #e8e8e8;
  342. border-right: none;
  343. img {
  344. width: 22px;
  345. height: 22px;
  346. position: relative;
  347. right: 5px;
  348. }
  349. }
  350. input {
  351. flex: 1;
  352. width: 100%;
  353. border: 1px solid #e8e8e8;
  354. border-left: none;
  355. border-right: none;
  356. height: 48px;
  357. padding: 0 0 0 10px;
  358. }
  359. &-accept {
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. width: 90px;
  364. .el-button {
  365. width: 100%;
  366. height: 100%;
  367. // font-weight: bold;
  368. color: #FFFFFF;
  369. background: $colorMain;
  370. border-left: none;
  371. border-radius: 0;
  372. font-size: 12px;
  373. &:hover {
  374. // border-color: #e8e8e8;
  375. // color: $colorMain;
  376. }
  377. }
  378. }
  379. }
  380. .submit {
  381. margin-top: 160px;
  382. background: $colorMain;
  383. color: #fff;
  384. text-align: center;
  385. border-radius: 2px;
  386. width: 100%;
  387. height: 45px;
  388. font-size: 18px;
  389. letter-spacing: 0px;
  390. &:hover {
  391. opacity: 0.9;
  392. }
  393. &.disabled {
  394. background-color: #909399;
  395. }
  396. }
  397. }
  398. </style>