RegisterMail.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <div class="center">
  3. <p style="width: 100%; text-align: center; position: relative; top: -10px">
  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. class="iconfont icon-jubao"
  25. ></span>
  26. {{ emailErrorMsg }}
  27. </div>
  28. <!-- 邮箱验证码 -->
  29. <div class="verify-code">
  30. <span class="verify-code-icon">
  31. <img src="/login/Code.png" alt="">
  32. </span>
  33. <input
  34. type="text"
  35. v-model="emailCode"
  36. :placeholder="L['请输入验证码']"
  37. class="input"
  38. autocomplete="off"
  39. />
  40. <span class="verify-code-accept">
  41. <el-button
  42. type="primary"
  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">
  53. <span
  54. v-if="emailCodeErrorMsg"
  55. style="color: #e1251b; font-size: 14px"
  56. class="iconfont icon-jubao"
  57. ></span>
  58. {{ emailCodeErrorMsg }}
  59. </div>
  60. <el-button
  61. @click="next"
  62. :class="{ submit: true, disabled: nextDisabled }"
  63. :disabled="nextDisabled"
  64. :loading="nextActionLoading"
  65. >{{ L["下一步"] }}</el-button
  66. >
  67. <el-dialog
  68. :title="L['register']['滑动验证']"
  69. destroy-on-close
  70. width="500px"
  71. center
  72. modal-class="register-verify-model"
  73. v-model="modalVisible"
  74. >
  75. <SliderVerify
  76. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  77. @onSuccess="verifySuccess"
  78. @onFail="verifyFail"
  79. />
  80. </el-dialog>
  81. </div>
  82. </template>
  83. <script setup>
  84. import { getCurLanguage } from "@/composables/common.js";
  85. import { showMessage, startCountdown } from "@/utils/common";
  86. const emits = defineEmits(["success"]);
  87. const L = getCurLanguage();
  88. const emailCalc = ref();
  89. const email = ref(""); //邮箱
  90. const emailCode = ref(""); // 邮箱验证码
  91. const emailErrorMsg = ref(); //错误提示
  92. const emailCodeErrorMsg = ref(); //验证码错误提示
  93. // 人机验证弹窗显示标识
  94. const modalVisible = ref(false);
  95. // 重新获取验证码标识
  96. const isReacquireCode = ref(false);
  97. const getVerifyCodeLoading = ref(false);
  98. const nextActionLoading = ref(false);
  99. // 倒计时展示
  100. const countDownNumer = ref(0);
  101. // 获取验证码的文案
  102. const codeText = computed(() => {
  103. return isReacquireCode.value
  104. ? L["register"]["重新获取"]
  105. : L["register"]["获取验证码"];
  106. });
  107. // 注册邮箱时按钮置灰状态
  108. const nextDisabled = computed(() => !email.value || !emailCode.value);
  109. //开启人机校验
  110. const showHMVerify = () => {
  111. // 校验邮箱非空以及格式
  112. if (!validateEmail()) return;
  113. modalVisible.value = true;
  114. };
  115. // 获取验证码
  116. const getVerifyCode = () => {
  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. const verifySuccess = () => {
  145. modalVisible.value = false;
  146. getVerifyCode();
  147. };
  148. // 人机校验失败
  149. const verifyFail = () => {
  150. showMessage({
  151. message: L["register"]["校验不通过"],
  152. type: "warning",
  153. });
  154. };
  155. // 校验邮箱
  156. const validateEmail = () => {
  157. //邮箱非空的验证
  158. if (!email.value) {
  159. emailErrorMsg.value = L["请输入邮箱"];
  160. return false;
  161. }
  162. // 邮箱格式验证
  163. emailCalc.value = checkEmail(email.value);
  164. if (emailCalc.value !== true) {
  165. emailErrorMsg.value = emailCalc.value;
  166. return false;
  167. }
  168. emailErrorMsg.value = "";
  169. return true;
  170. };
  171. // 邮箱验证码验证
  172. const validateEmailCode = () => {
  173. if (!emailCode.value) {
  174. emailCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  175. return false;
  176. }
  177. emailCodeErrorMsg.value = "";
  178. return true;
  179. };
  180. const next = () => {
  181. if (!validateEmail() || !validateEmailCode()) return;
  182. nextActionLoading.value = true;
  183. post("v3/member/front/active/check/verification/code", {
  184. email: email.value,
  185. type: 1,
  186. verificationCode: emailCode.value,
  187. })
  188. .then((res) => {
  189. if (res.state == 200) {
  190. // showMessage({
  191. // message: L["register"]["注册成功"],
  192. // type: "success",
  193. // });
  194. //成功提示,并返回到登录页面
  195. emits("success", email.value);
  196. } else {
  197. //提示错误
  198. showMessage({
  199. message: res.msg,
  200. type: "warning",
  201. });
  202. }
  203. })
  204. .finally(() => {
  205. nextActionLoading.value = false;
  206. });
  207. };
  208. //清空输入框内容
  209. const clearInputVal = (type) => {
  210. email.value = "";
  211. };
  212. </script>
  213. <style lang="scss">
  214. .register-verify-model {
  215. .el-dialog__title {
  216. font-weight: 900 !important;
  217. }
  218. .el-dialog__body {
  219. display: flex;
  220. justify-content: center;
  221. align-items: center;
  222. }
  223. }
  224. </style>
  225. <style lang="scss" scoped>
  226. .center {
  227. flex: 1;
  228. height: 100%;
  229. position: relative;
  230. padding: 0 28px;
  231. margin-top: 60px;
  232. .item {
  233. position: relative;
  234. margin-top: 25px;
  235. border-radius: 2px;
  236. input::placeholder {
  237. // font-weight: 400;
  238. font-size: $fontE;
  239. color: rgba(40,46,48,0.6);
  240. }
  241. ::-webkit-input-placeholder {
  242. // font-weight: 400;
  243. font-size: $fontE;
  244. color: rgba(40,46,48,0.6);
  245. }
  246. /* 使用webkit内核的浏览器 */
  247. :-moz-placeholder {
  248. // font-weight: 400;
  249. font-size: $fontE;
  250. color: rgba(40,46,48,0.6);
  251. }
  252. /* Firefox版本19+ */
  253. :-ms-input-placeholder {
  254. // font-weight: 400;
  255. font-size: $fontE;
  256. color: rgba(40,46,48,0.6);
  257. }
  258. &:first-child {
  259. margin-top: 0;
  260. }
  261. .icon {
  262. display: flex;
  263. align-items: center;
  264. justify-content: flex-end;
  265. position: absolute;
  266. left: 1px;
  267. top: 1px;
  268. width: 50px;
  269. height: 46px;
  270. img {
  271. width: 22px;
  272. height: 22px;
  273. position: relative;
  274. right: 5px;
  275. }
  276. }
  277. .input {
  278. border: 1px solid #e8e8e8;
  279. height: 48px;
  280. padding: 0 44px 0 60px;
  281. width: 431px;
  282. font-size: 14px;
  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. .iconfont {
  308. font-size: 14px;
  309. }
  310. }
  311. .verify-code {
  312. display: flex;
  313. width: 431px;
  314. height: 48px;
  315. margin-top: 10px;
  316. input::placeholder {
  317. // font-weight: 400;
  318. font-size: $fontE;
  319. color: rgba(40,46,48,0.6);
  320. }
  321. ::-webkit-input-placeholder {
  322. // font-weight: 400;
  323. font-size: $fontE;
  324. color: rgba(40,46,48,0.6);
  325. }
  326. /* 使用webkit内核的浏览器 */
  327. :-moz-placeholder {
  328. // font-weight: 400;
  329. font-size: $fontE;
  330. color: rgba(40,46,48,0.6);
  331. }
  332. /* Firefox版本19+ */
  333. :-ms-input-placeholder {
  334. // font-weight: 400;
  335. font-size: $fontE;
  336. color: rgba(40,46,48,0.6);
  337. }
  338. &-icon {
  339. display: flex;
  340. align-items: center;
  341. justify-content: flex-end;
  342. width: 50px;
  343. height: 48px;
  344. border: 1px solid #e8e8e8;
  345. border-right: none;
  346. img {
  347. width: 22px;
  348. height: 22px;
  349. position: relative;
  350. right: 5px;
  351. }
  352. }
  353. input {
  354. flex: 1;
  355. width: 100%;
  356. border: 1px solid #e8e8e8;
  357. border-left: none;
  358. border-right: none;
  359. height: 48px;
  360. padding: 0 0 0 10px;
  361. font-size: 14px;
  362. }
  363. &-accept {
  364. display: flex;
  365. justify-content: center;
  366. align-items: center;
  367. width: 90px;
  368. .el-button {
  369. width: 100%;
  370. height: 100%;
  371. // font-weight: bold;
  372. color: #FFFFFF;
  373. background: $colorMain;
  374. border-left: none;
  375. border-radius: 0;
  376. font-size: 12px;
  377. &:hover {
  378. // border-color: #e8e8e8;
  379. // color: $colorMain;
  380. }
  381. }
  382. }
  383. }
  384. .submit {
  385. margin-top: 160px;
  386. background: $colorMain;
  387. color: #fff;
  388. text-align: center;
  389. border-radius: 2px;
  390. width: 100%;
  391. height: 45px;
  392. font-size: 18px;
  393. letter-spacing: 0px;
  394. &:hover {
  395. opacity: 0.9;
  396. }
  397. &.disabled {
  398. background-color: #909399;
  399. }
  400. }
  401. }
  402. </style>