RegisterMail.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. @click="showHMVerify"
  43. :disabled="countDownNumer"
  44. :loading="getVerifyCodeLoading"
  45. >
  46. <span>{{ codeText }}</span>
  47. <span v-if="countDownNumer">{{ `(${countDownNumer})` }}</span>
  48. </el-button>
  49. </span>
  50. </div>
  51. <div class="error">
  52. <span
  53. v-if="emailCodeErrorMsg"
  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. flex: 1;
  227. height: 100%;
  228. position: relative;
  229. padding: 0 28px;
  230. margin-top: 60px;
  231. .item {
  232. position: relative;
  233. margin-top: 25px;
  234. border-radius: 2px;
  235. input::placeholder {
  236. // font-weight: 400;
  237. font-size: $fontE;
  238. color: rgba(40,46,48,0.6);
  239. }
  240. ::-webkit-input-placeholder {
  241. // font-weight: 400;
  242. font-size: $fontE;
  243. color: rgba(40,46,48,0.6);
  244. }
  245. /* 使用webkit内核的浏览器 */
  246. :-moz-placeholder {
  247. // font-weight: 400;
  248. font-size: $fontE;
  249. color: rgba(40,46,48,0.6);
  250. }
  251. /* Firefox版本19+ */
  252. :-ms-input-placeholder {
  253. // font-weight: 400;
  254. font-size: $fontE;
  255. color: rgba(40,46,48,0.6);
  256. }
  257. &:first-child {
  258. margin-top: 0;
  259. }
  260. .icon {
  261. display: flex;
  262. align-items: center;
  263. justify-content: flex-end;
  264. position: absolute;
  265. left: 1px;
  266. top: 1px;
  267. width: 50px;
  268. height: 46px;
  269. img {
  270. width: 22px;
  271. height: 22px;
  272. position: relative;
  273. right: 5px;
  274. }
  275. }
  276. .input {
  277. border: 1px solid #e8e8e8;
  278. height: 48px;
  279. padding: 0 44px 0 60px;
  280. width: 431px;
  281. font-size: 14px;
  282. }
  283. &.code {
  284. .input {
  285. padding-right: 10px;
  286. width: 150px;
  287. }
  288. }
  289. }
  290. .cancel {
  291. position: absolute;
  292. right: 0px;
  293. top: 2px;
  294. width: 44px;
  295. height: 46px;
  296. text-align: center;
  297. line-height: 46px;
  298. cursor: pointer;
  299. }
  300. .error {
  301. margin-top: 10px;
  302. position: relative;
  303. color: #e2231a;
  304. height: 16px;
  305. line-height: 16px;
  306. .iconfont {
  307. font-size: 14px;
  308. }
  309. }
  310. .verify-code {
  311. display: flex;
  312. width: 431px;
  313. height: 48px;
  314. margin-top: 10px;
  315. input::placeholder {
  316. // font-weight: 400;
  317. font-size: $fontE;
  318. color: rgba(40,46,48,0.6);
  319. }
  320. ::-webkit-input-placeholder {
  321. // font-weight: 400;
  322. font-size: $fontE;
  323. color: rgba(40,46,48,0.6);
  324. }
  325. /* 使用webkit内核的浏览器 */
  326. :-moz-placeholder {
  327. // font-weight: 400;
  328. font-size: $fontE;
  329. color: rgba(40,46,48,0.6);
  330. }
  331. /* Firefox版本19+ */
  332. :-ms-input-placeholder {
  333. // font-weight: 400;
  334. font-size: $fontE;
  335. color: rgba(40,46,48,0.6);
  336. }
  337. &-icon {
  338. display: flex;
  339. align-items: center;
  340. justify-content: flex-end;
  341. width: 50px;
  342. height: 48px;
  343. border: 1px solid #e8e8e8;
  344. border-right: none;
  345. img {
  346. width: 22px;
  347. height: 22px;
  348. position: relative;
  349. right: 5px;
  350. }
  351. }
  352. input {
  353. flex: 1;
  354. width: 100%;
  355. border: 1px solid #e8e8e8;
  356. border-left: none;
  357. border-right: none;
  358. height: 48px;
  359. padding: 0 0 0 10px;
  360. font-size: 14px;
  361. }
  362. &-accept {
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. width: 90px;
  367. .el-button {
  368. width: 100%;
  369. height: 100%;
  370. // font-weight: bold;
  371. color: #FFFFFF;
  372. background-color: $colorMain;
  373. border-left: none;
  374. border-radius: 0;
  375. font-size: 12px;
  376. &.is-disabled {
  377. background-color: #909399;
  378. }
  379. &:hover {
  380. // border-color: #e8e8e8;
  381. // color: $colorMain;
  382. }
  383. }
  384. }
  385. }
  386. .submit {
  387. margin-top: 160px;
  388. background: $colorMain;
  389. color: #fff;
  390. text-align: center;
  391. border-radius: 2px;
  392. width: 100%;
  393. height: 45px;
  394. font-size: 18px;
  395. letter-spacing: 0px;
  396. &:hover {
  397. opacity: 0.9;
  398. }
  399. &.disabled {
  400. background-color: #909399;
  401. }
  402. }
  403. }
  404. </style>