RegisterMail.vue 9.2 KB

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