RegisterPhone.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. class="iconfont icon-jubao"
  25. ></span>
  26. {{ phoneErrorMsg }}
  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="phoneCode"
  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="phoneCodeErrorMsg"
  54. class="iconfont icon-jubao"
  55. ></span>
  56. {{ phoneCodeErrorMsg }}
  57. </div>
  58. <el-button
  59. @click="next"
  60. :class="{ submit: true, disabled: nextDisabled }"
  61. :disabled="nextDisabled"
  62. :loading="nextActionLoading"
  63. >{{ L["下一步"] }}</el-button
  64. >
  65. <el-dialog
  66. :title="L['register']['滑动验证']"
  67. destroy-on-close
  68. width="500px"
  69. center
  70. modal-class="register-verify-model"
  71. v-model="modalVisible"
  72. >
  73. <SliderVerify
  74. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  75. @onSuccess="verifySuccess"
  76. @onFail="verifyFail"
  77. />
  78. </el-dialog>
  79. </div>
  80. </template>
  81. <script setup>
  82. import { getCurLanguage } from "@/composables/common.js";
  83. import { showMessage, startCountdown } from "@/utils/common";
  84. const emits = defineEmits(["success"]);
  85. const L = getCurLanguage();
  86. const phoneCalc = ref();
  87. const mobile = ref(""); //手机号
  88. const phoneCode = ref(""); // 手机号验证码
  89. const phoneErrorMsg = ref(); //错误提示
  90. const phoneCodeErrorMsg = ref(); //验证码错误提示
  91. // 人机验证弹窗显示标识
  92. const modalVisible = ref(false);
  93. // 重新获取验证码标识
  94. const isReacquireCode = ref(false);
  95. const getVerifyCodeLoading = ref(false);
  96. const nextActionLoading = ref(false);
  97. // 倒计时展示
  98. const countDownNumer = ref(0);
  99. // 获取验证码的文案
  100. const codeText = computed(() => {
  101. return isReacquireCode.value
  102. ? L["register"]["重新获取"]
  103. : L["register"]["获取验证码"];
  104. });
  105. // 注册手机号时按钮置灰状态
  106. const nextDisabled = computed(() => !mobile.value || !phoneCode.value);
  107. //开启人机校验
  108. const showHMVerify = () => {
  109. // 校验手机号非空以及格式
  110. if (!validatePhone()) return;
  111. modalVisible.value = true;
  112. };
  113. // 获取验证码
  114. const getVerifyCode = () => {
  115. getVerifyCodeLoading.value = true;
  116. post("v3/member/front/active/verification/code", {
  117. mobile: mobile.value,
  118. source: 1,
  119. type: 1,
  120. })
  121. .then((res) => {
  122. if (res.state === 200) {
  123. showMessage({
  124. message: L["register"]["验证码已发送"],
  125. type: "success",
  126. });
  127. // 设置倒计时
  128. startCountdown(60, (time) => (countDownNumer.value = time));
  129. isReacquireCode.value = true;
  130. } else {
  131. showMessage({
  132. message: res.msg,
  133. type: "warning",
  134. });
  135. }
  136. })
  137. .finally(() => {
  138. getVerifyCodeLoading.value = false;
  139. });
  140. };
  141. // 人机验证成功
  142. const verifySuccess = () => {
  143. modalVisible.value = false;
  144. getVerifyCode();
  145. };
  146. // 人机校验失败
  147. const verifyFail = () => {
  148. showMessage({
  149. message: L["register"]["校验不通过"],
  150. type: "warning",
  151. });
  152. };
  153. // 校验手机号
  154. const validatePhone = () => {
  155. //手机号非空的验证
  156. if (!mobile.value) {
  157. phoneErrorMsg.value = L["请输入手机号"];
  158. return false;
  159. }
  160. // 手机号格式验证
  161. phoneCalc.value = checkPhone(mobile.value);
  162. if (phoneCalc.value !== true) {
  163. phoneErrorMsg.value = phoneCalc.value;
  164. return false;
  165. }
  166. phoneErrorMsg.value = "";
  167. return true;
  168. };
  169. // 手机号验证码验证
  170. const validatePhoneCode = () => {
  171. if (!phoneCode.value) {
  172. phoneCodeErrorMsg.value = L["register"]["请输入手机号验证码"];
  173. return false;
  174. }
  175. phoneCodeErrorMsg.value = "";
  176. return true;
  177. };
  178. const next = () => {
  179. if (!validatePhone() || !validatePhoneCode()) return;
  180. nextActionLoading.value = true;
  181. post("v3/member/front/active/check/verification/code", {
  182. mobile: mobile.value,
  183. type: 1,
  184. verificationCode: phoneCode.value,
  185. })
  186. .then((res) => {
  187. if (res.state == 200) {
  188. // showMessage({
  189. // message: L["register"]["注册成功"],
  190. // type: "success",
  191. // });
  192. //成功提示,并返回到登录页面
  193. emits("success", mobile.value);
  194. } else {
  195. //提示错误
  196. showMessage({
  197. message: res.msg,
  198. type: "warning",
  199. });
  200. }
  201. })
  202. .finally(() => {
  203. nextActionLoading.value = false;
  204. });
  205. };
  206. //清空输入框内容
  207. const clearInputVal = (type) => {
  208. mobile.value = "";
  209. };
  210. </script>
  211. <style lang="scss">
  212. .register-verify-model {
  213. .el-dialog__title {
  214. font-weight: 900 !important;
  215. }
  216. .el-dialog__body {
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. }
  221. }
  222. </style>
  223. <style lang="scss" scoped>
  224. .center {
  225. flex: 1;
  226. height: 100%;
  227. position: relative;
  228. padding: 0 28px;
  229. margin-top: 60px;
  230. .item {
  231. position: relative;
  232. margin-top: 15px;
  233. border-radius: 2px;
  234. &:first-child {
  235. margin-top: 0;
  236. }
  237. .icon {
  238. display: flex;
  239. align-items: center;
  240. justify-content: flex-end;
  241. position: absolute;
  242. left: 1px;
  243. top: 1px;
  244. width: 50px;
  245. height: 46px;
  246. img {
  247. width: 22px;
  248. height: 22px;
  249. position: relative;
  250. right: 5px;
  251. }
  252. }
  253. .input {
  254. border: 1px solid #e8e8e8;
  255. height: 48px;
  256. padding: 0 44px 0 60px;
  257. width: 431px;
  258. font-size: 14px;
  259. }
  260. &.code {
  261. .input {
  262. padding-right: 10px;
  263. width: 150px;
  264. }
  265. }
  266. }
  267. .cancel {
  268. position: absolute;
  269. right: 0;
  270. top: 1px;
  271. width: 44px;
  272. height: 46px;
  273. line-height: 46px;
  274. text-align: center;
  275. cursor: pointer;
  276. }
  277. .error {
  278. margin-top: 10px;
  279. position: relative;
  280. color: #e2231a;
  281. height: 16px;
  282. line-height: 16px;
  283. .iconfont {
  284. font-size: 14px;
  285. }
  286. }
  287. .verify-code {
  288. display: flex;
  289. width: 431px;
  290. height: 48px;
  291. margin-top: 10px;
  292. &-icon {
  293. display: flex;
  294. align-items: center;
  295. justify-content: flex-end;
  296. width: 50px;
  297. height: 48px;
  298. border: 1px solid #e8e8e8;
  299. border-right: none;
  300. img {
  301. width: 22px;
  302. height: 22px;
  303. position: relative;
  304. right: 5px;
  305. }
  306. }
  307. input {
  308. flex: 1;
  309. border: 1px solid #e8e8e8;
  310. border-left: none;
  311. border-right: none;
  312. height: 48px;
  313. padding: 0 0 0 10px;
  314. width: 100%;
  315. font-size: 14px;
  316. }
  317. &-accept {
  318. display: flex;
  319. justify-content: center;
  320. align-items: center;
  321. width: 90px;
  322. .el-button {
  323. width: 100%;
  324. height: 100%;
  325. color: #fff;
  326. background: $colorMain;
  327. border-left: none;
  328. border-radius: 0;
  329. font-size: 12px;
  330. &:hover {
  331. // border-color: #e8e8e8;
  332. // color: $colorMain;
  333. }
  334. }
  335. }
  336. }
  337. .submit {
  338. margin-top: 160px;
  339. background: $colorMain;
  340. color: #fff;
  341. text-align: center;
  342. border-radius: 2px;
  343. width: 100%;
  344. height: 45px;
  345. font-size: 18px;
  346. letter-spacing: 0px;
  347. &:hover {
  348. opacity: 0.9;
  349. }
  350. &.disabled {
  351. background-color: #909399;
  352. }
  353. }
  354. }
  355. </style>