RegisterPhone.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/User.png" alt="">
  9. </span>
  10. <input
  11. type="text"
  12. v-model="mobile"
  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="phoneErrorMsg"
  24. style="color: #e1251b; font-size: 14px"
  25. class="iconfont icon-jubao"
  26. ></span>
  27. {{ phoneErrorMsg }}
  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="phoneCode"
  37. :placeholder="L['请输入验证码']"
  38. class="input"
  39. autocomplete="off"
  40. />
  41. <span class="verify-code-accept">
  42. <el-button
  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="phoneCodeErrorMsg"
  55. style="color: #e1251b; font-size: 14px"
  56. class="iconfont icon-jubao"
  57. ></span>
  58. {{ phoneCodeErrorMsg }}
  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 phoneCalc = ref();
  89. const mobile = ref(""); //手机号
  90. const phoneCode = ref(""); // 手机号验证码
  91. const phoneErrorMsg = ref(); //错误提示
  92. const phoneCodeErrorMsg = 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(() => !mobile.value || !phoneCode.value);
  109. //开启人机校验
  110. const showHMVerify = () => {
  111. // 校验手机号非空以及格式
  112. if (!validatePhone()) return;
  113. modalVisible.value = true;
  114. };
  115. // 获取验证码
  116. const getVerifyCode = () => {
  117. getVerifyCodeLoading.value = true;
  118. post("v3/member/front/active/verification/code", {
  119. mobile: mobile.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 validatePhone = () => {
  157. //手机号非空的验证
  158. if (!mobile.value) {
  159. phoneErrorMsg.value = L["请输入手机号"];
  160. return false;
  161. }
  162. // 手机号格式验证
  163. phoneCalc.value = checkPhone(mobile.value);
  164. if (phoneCalc.value !== true) {
  165. phoneErrorMsg.value = phoneCalc.value;
  166. return false;
  167. }
  168. phoneErrorMsg.value = "";
  169. return true;
  170. };
  171. // 手机号验证码验证
  172. const validatePhoneCode = () => {
  173. if (!phoneCode.value) {
  174. phoneCodeErrorMsg.value = L["register"]["请输入手机号验证码"];
  175. return false;
  176. }
  177. phoneCodeErrorMsg.value = "";
  178. return true;
  179. };
  180. const next = () => {
  181. if (!validatePhone() || !validatePhoneCode()) return;
  182. nextActionLoading.value = true;
  183. post("v3/member/front/active/check/verification/code", {
  184. mobile: mobile.value,
  185. type: 1,
  186. verificationCode: phoneCode.value,
  187. })
  188. .then((res) => {
  189. if (res.state == 200) {
  190. // showMessage({
  191. // message: L["register"]["注册成功"],
  192. // type: "success",
  193. // });
  194. //成功提示,并返回到登录页面
  195. emits("success", mobile.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. mobile.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: 15px;
  235. border-radius: 2px;
  236. &:first-child {
  237. margin-top: 0;
  238. }
  239. .icon {
  240. display: flex;
  241. align-items: center;
  242. justify-content: flex-end;
  243. position: absolute;
  244. left: 1px;
  245. top: 1px;
  246. width: 50px;
  247. height: 46px;
  248. img {
  249. width: 22px;
  250. height: 22px;
  251. position: relative;
  252. right: 5px;
  253. }
  254. }
  255. .input {
  256. border: 1px solid #e8e8e8;
  257. height: 48px;
  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: 46px;
  274. line-height: 46px;
  275. text-align: center;
  276. cursor: pointer;
  277. }
  278. .error {
  279. margin-top: 10px;
  280. position: relative;
  281. color: #e2231a;
  282. height: 16px;
  283. line-height: 16px;
  284. }
  285. .verify-code {
  286. display: flex;
  287. width: 431px;
  288. height: 48px;
  289. margin-top: 10px;
  290. &-icon {
  291. display: flex;
  292. align-items: center;
  293. justify-content: flex-end;
  294. width: 50px;
  295. height: 48px;
  296. border: 1px solid #e8e8e8;
  297. border-right: none;
  298. img {
  299. width: 22px;
  300. height: 22px;
  301. position: relative;
  302. right: 5px;
  303. }
  304. }
  305. input {
  306. flex: 1;
  307. border: 1px solid #e8e8e8;
  308. border-left: none;
  309. border-right: none;
  310. height: 48px;
  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>