RegisterPhone.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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
  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="mobile"
  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">
  23. <span
  24. v-if="phoneErrorMsg"
  25. style="color: #e1251b; font-size: 14px"
  26. class="iconfont icon-jubao"
  27. ></span>
  28. {{ phoneErrorMsg }}
  29. </div>
  30. <!-- 手机号验证码 -->
  31. <div class="verify-code">
  32. <span class="verify-code-icon">
  33. <img src="/register/mail_success.png" alt="" />
  34. </span>
  35. <input
  36. type="text"
  37. v-model="phoneCode"
  38. :placeholder="L['请输入验证码']"
  39. class="input"
  40. autocomplete="off"
  41. />
  42. <span class="verify-code-accept">
  43. <el-button
  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="phoneCodeErrorMsg"
  56. style="color: #e1251b; font-size: 14px"
  57. class="iconfont icon-jubao"
  58. ></span>
  59. {{ phoneCodeErrorMsg }}
  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 phoneCalc = ref();
  90. const mobile = ref(""); //手机号
  91. const phoneCode = ref(""); // 手机号验证码
  92. const phoneErrorMsg = ref(); //错误提示
  93. const phoneCodeErrorMsg = 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(() => !mobile.value || !phoneCode.value);
  110. //开启人机校验
  111. const showHMVerify = () => {
  112. // 校验手机号非空以及格式
  113. if (!validatePhone()) return;
  114. modalVisible.value = true;
  115. };
  116. // 获取验证码
  117. const getVerifyCode = () => {
  118. getVerifyCodeLoading.value = true;
  119. post("v3/member/front/active/verification/code", {
  120. mobile: mobile.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 validatePhone = () => {
  158. //手机号非空的验证
  159. if (!mobile.value) {
  160. phoneErrorMsg.value = L["请输入手机号"];
  161. return false;
  162. }
  163. // 手机号格式验证
  164. phoneCalc.value = checkPhone(mobile.value);
  165. if (phoneCalc.value !== true) {
  166. phoneErrorMsg.value = phoneCalc.value;
  167. return false;
  168. }
  169. phoneErrorMsg.value = "";
  170. return true;
  171. };
  172. // 手机号验证码验证
  173. const validatePhoneCode = () => {
  174. if (!phoneCode.value) {
  175. phoneCodeErrorMsg.value = L["register"]["请输入手机号验证码"];
  176. return false;
  177. }
  178. phoneCodeErrorMsg.value = "";
  179. return true;
  180. };
  181. const next = () => {
  182. if (!validatePhone() || !validatePhoneCode()) return;
  183. nextActionLoading.value = true;
  184. post("v3/member/front/active/check/verification/code", {
  185. mobile: mobile.value,
  186. type: 1,
  187. verificationCode: phoneCode.value,
  188. })
  189. .then((res) => {
  190. if (res.state == 200) {
  191. // showMessage({
  192. // message: L["register"]["注册成功"],
  193. // type: "success",
  194. // });
  195. //成功提示,并返回到登录页面
  196. emits("success", mobile.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. mobile.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: 15px;
  236. border-radius: 2px;
  237. &:first-child {
  238. margin-top: 0;
  239. }
  240. .icon {
  241. position: absolute;
  242. left: 1px;
  243. top: 1px;
  244. width: 50px;
  245. text-align: center;
  246. height: 38px;
  247. background: #f8f8f8;
  248. .input {
  249. border: 1px solid #e8e8e8;
  250. height: 40px;
  251. padding: 0 44px 0 60px;
  252. width: 326px;
  253. }
  254. }
  255. .input {
  256. border: 1px solid #e8e8e8;
  257. height: 40px;
  258. padding: 0 44px 0 60px;
  259. width: 431px;
  260. }
  261. &.code {
  262. .input {
  263. padding-right: 10px;
  264. width: 150px;
  265. }
  266. }
  267. }
  268. .cancel {
  269. position: absolute;
  270. right: 0;
  271. top: 1px;
  272. width: 44px;
  273. height: 38px;
  274. cursor: pointer;
  275. :before {
  276. position: absolute;
  277. top: 9px;
  278. left: 14px;
  279. }
  280. }
  281. .error {
  282. margin-top: 10px;
  283. position: relative;
  284. color: #e2231a;
  285. height: 16px;
  286. line-height: 16px;
  287. }
  288. .verify-code {
  289. display: flex;
  290. width: 431px;
  291. height: 40px;
  292. margin-top: 10px;
  293. &-icon {
  294. width: 50px;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. border: 1px solid #e8e8e8;
  299. border-right: none;
  300. background: #f8f8f8;
  301. img {
  302. width: 20px;
  303. }
  304. }
  305. input {
  306. flex: 1;
  307. border: 1px solid #e8e8e8;
  308. border-left: none;
  309. border-right: none;
  310. height: 40px;
  311. padding: 0 0 0 10px;
  312. width: 100%;
  313. }
  314. &-accept {
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. width: 90px;
  319. .el-button {
  320. width: 100%;
  321. height: 100%;
  322. color: #fff;
  323. background: $colorMain;
  324. border-left: none;
  325. border-radius: 0;
  326. font-size: 12px;
  327. &:hover {
  328. // border-color: #e8e8e8;
  329. // color: $colorMain;
  330. }
  331. }
  332. }
  333. }
  334. .submit {
  335. margin-top: 160px;
  336. background: $colorMain;
  337. color: #fff;
  338. text-align: center;
  339. border-radius: 2px;
  340. width: 100%;
  341. height: 45px;
  342. font-size: 18px;
  343. letter-spacing: 0px;
  344. &:hover {
  345. opacity: 0.9;
  346. }
  347. &.disabled {
  348. background-color: #909399;
  349. }
  350. }
  351. }
  352. </style>