RetrievePwdByPhone.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <div class="center">
  3. <div class="item account">
  4. <span
  5. style="color: #bbb; font-size: 21px; padding-top: 7px"
  6. class="icon iconfont icon-wode"
  7. ></span>
  8. <input
  9. type="text"
  10. v-model="memberMobile"
  11. :placeholder="L['请输入手机号']"
  12. class="input"
  13. />
  14. <div
  15. data-type="userName"
  16. class="cancel"
  17. @click="clearInputVal('memberMobile')"
  18. >
  19. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  20. </div>
  21. </div>
  22. <div class="error">
  23. <span
  24. v-if="mobileErrorMsg"
  25. style="color: #e1251b; font-size: 14px"
  26. class="iconfont icon-jubao"
  27. ></span>
  28. {{ mobileErrorMsg }}
  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="mobileCode"
  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="mobileCodeErrorMsg"
  56. style="color: #e1251b; font-size: 14px"
  57. class="iconfont icon-jubao"
  58. ></span>
  59. {{ mobileCodeErrorMsg }}
  60. </div>
  61. <div class="item password">
  62. <span
  63. style="color: #bbb; font-size: 21px; padding-top: 7px"
  64. class="icon iconfont icon-mima1"
  65. ></span>
  66. <input
  67. :type="showPwdFlag ? 'text' : 'password'"
  68. v-model="password"
  69. :placeholder="L['请输入密码']"
  70. class="input"
  71. @focus="checkPwdValidate"
  72. @blur="checkPwdValidate"
  73. />
  74. <div class="cancel" @click="isShowPwd">
  75. <span
  76. :style="{
  77. color: '#bbb',
  78. fontSize: showPwdFlag ? '20px' : '16px',
  79. }"
  80. :class="{
  81. iconfont: true,
  82. 'icon-bukejian11': !showPwdFlag,
  83. 'icon-kejian': showPwdFlag,
  84. show_pwd: showPwdFlag,
  85. }"
  86. ></span>
  87. </div>
  88. <div class="error">
  89. <span
  90. v-if="checkPwdErrorMsg"
  91. style="color: #e1251b; font-size: 14px"
  92. class="iconfont icon-jubao"
  93. ></span>
  94. {{ checkPwdErrorMsg }}
  95. </div>
  96. </div>
  97. <div class="item confirm">
  98. <span style="color: #bbb; font-size: 21px; padding-top: 7px" class="icon"
  99. ><img src="/register/pwd_confirm.png" alt=""
  100. /></span>
  101. <input
  102. class="input"
  103. v-model="confirmPassword"
  104. :type="showConfirmPwdFlag ? 'text' : 'password'"
  105. :placeholder="L['register']['请确认密码']"
  106. @blur="checkPwdMatched"
  107. />
  108. <div class="cancel" @click="isShowConfirmPwd">
  109. <span
  110. :style="{
  111. color: '#bbb',
  112. fontSize: showConfirmPwdFlag ? '20px' : '16px',
  113. }"
  114. :class="{
  115. iconfont: true,
  116. 'icon-bukejian11': !showConfirmPwdFlag,
  117. 'icon-kejian': showConfirmPwdFlag,
  118. show_pwd: showConfirmPwdFlag,
  119. }"
  120. ></span>
  121. </div>
  122. </div>
  123. <div class="error">
  124. <span
  125. v-if="checkErrorMsg"
  126. style="color: #e1251b; font-size: 14px"
  127. class="iconfont icon-jubao"
  128. ></span>
  129. {{ checkErrorMsg }}
  130. </div>
  131. <el-button
  132. @click="forgetPwd"
  133. :class="{ submit: true, disabled: forgetPwdDisabled }"
  134. :disabled="forgetPwdDisabled"
  135. :loading="forgetPwdLoading"
  136. >{{ L["确认"] }}</el-button
  137. >
  138. <el-dialog
  139. :title="L['register']['滑动验证']"
  140. destroy-on-close
  141. width="500px"
  142. center
  143. modal-class="retrieve-verify-model"
  144. v-model="modalVisible"
  145. >
  146. <SliderVerify
  147. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  148. @onSuccess="verifySuccess"
  149. @onFail="verifyFail"
  150. />
  151. </el-dialog>
  152. </div>
  153. </template>
  154. <script setup>
  155. import { showMessage, startCountdown } from "@/utils/common";
  156. import { getCurLanguage } from "@/composables/common.js";
  157. const emits = defineEmits(["success"]);
  158. const L = getCurLanguage();
  159. const mobileCalc = ref();
  160. const memberMobile = ref(""); //用户邮箱
  161. const mobileErrorMsg = ref(); //错误提示
  162. const mobileCode = ref(""); // 邮箱验证码
  163. const mobileCodeErrorMsg = ref(); //验证码错误提示
  164. // 倒计时展示
  165. const countDownNumer = ref(0);
  166. const getVerifyCodeLoading = ref(false);
  167. // 人机验证弹窗显示标识
  168. const modalVisible = ref(false);
  169. // 重新获取验证码标识
  170. const isReacquireCode = ref(false);
  171. const checkErrorMsg = ref(""); // 密码一致性错误提示
  172. const password = ref(""); //密码
  173. const confirmPassword = ref(""); //二次确认密码
  174. const showPwdFlag = ref(false); //密码是否明文显示,默认密文
  175. const showConfirmPwdFlag = ref(false); // 二次密码是否明文显示,默认密文
  176. const forgetPwdLoading = ref(false);
  177. const checkPwdErrorMsg = ref("");
  178. const forgetPwdDisabled = computed(
  179. () => !memberMobile.value || !password.value || !confirmPassword.value
  180. );
  181. // 获取验证码的文案
  182. const codeText = computed(() => {
  183. return isReacquireCode.value
  184. ? L["register"]["重新获取"]
  185. : L["register"]["获取验证码"];
  186. });
  187. //密码是否显示
  188. const isShowPwd = () => {
  189. showPwdFlag.value = !showPwdFlag.value;
  190. };
  191. const checkPwdValidate = () => {
  192. const regex = /^[A-Za-z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{6,20}$/;
  193. if (regex.test(password.value)) {
  194. checkPwdErrorMsg.value = "";
  195. return true;
  196. }
  197. checkPwdErrorMsg.value = L["请输入6~20位英文、数字、符号"];
  198. return false;
  199. };
  200. //开启人机校验
  201. const showHMVerify = () => {
  202. // 校验手机非空以及格式
  203. if (!validatePhone()) return;
  204. modalVisible.value = true;
  205. };
  206. // 二次确认密码是否显示
  207. const isShowConfirmPwd = () => {
  208. showConfirmPwdFlag.value = !showConfirmPwdFlag.value;
  209. };
  210. const checkPwdMatched = () => {
  211. if (password.value === confirmPassword.value) {
  212. checkErrorMsg.value = "";
  213. return true;
  214. }
  215. checkErrorMsg.value = L["register"]["两次输入的密码不一致"];
  216. return false;
  217. };
  218. // 人机验证成功
  219. const verifySuccess = () => {
  220. modalVisible.value = false;
  221. getVerifyCode();
  222. };
  223. //清空输入框内容
  224. const clearInputVal = (type) => {
  225. if (type == "memberMobile") {
  226. memberMobile.value = "";
  227. }
  228. };
  229. // 人机校验失败
  230. const verifyFail = () => {
  231. showMessage({
  232. message: L["register"]["校验不通过"],
  233. type: "warning",
  234. });
  235. };
  236. // 校验邮箱
  237. const validatePhone = () => {
  238. //邮箱非空的验证
  239. if (!memberMobile.value) {
  240. mobileErrorMsg.value = L["请输入邮箱"];
  241. return false;
  242. }
  243. // 邮箱格式验证
  244. mobileCalc.value = checkPhone(memberMobile.value);
  245. if (mobileCalc.value !== true) {
  246. mobileErrorMsg.value = mobileCalc.value;
  247. return false;
  248. }
  249. mobileErrorMsg.value = "";
  250. return true;
  251. };
  252. // 邮箱验证码验证
  253. const validateMobileCode = () => {
  254. if (!mobileCode.value) {
  255. mobileCodeErrorMsg.value = L["register"]["请输入邮箱验证码"];
  256. return false;
  257. }
  258. mobileCodeErrorMsg.value = "";
  259. return true;
  260. };
  261. const getVerifyCode = () => {
  262. getVerifyCodeLoading.value = true;
  263. post("v3/member/front/active/verification/code", {
  264. mobile: memberMobile.value,
  265. source: 1,
  266. type: 2, // 忘记密码
  267. })
  268. .then((res) => {
  269. if (res.state === 200) {
  270. showMessage({
  271. message: L["register"]["验证码已发送"],
  272. type: "success",
  273. });
  274. // 设置倒计时
  275. startCountdown(60, (time) => (countDownNumer.value = time));
  276. isReacquireCode.value = true;
  277. } else {
  278. showMessage({
  279. message: res.msg,
  280. type: "warning",
  281. });
  282. }
  283. })
  284. .finally(() => {
  285. getVerifyCodeLoading.value = false;
  286. });
  287. };
  288. const forgetPwd = () => {
  289. if (!validatePhone() || !validateMobileCode()) return;
  290. forgetPwdLoading.value = true;
  291. post("v3/member/front/active/email/reset/pwdNew", {
  292. confirmPassWord: confirmPassword.value,
  293. mobile: memberMobile.value,
  294. loginPwd: password.value,
  295. verificationCode: mobileCode.value,
  296. })
  297. .then((res) => {
  298. if (res.state == 200) {
  299. //成功提示,并返回到登录页面
  300. showMessage({
  301. message: L["register"]["重置成功"],
  302. type: "success",
  303. });
  304. emits("success");
  305. } else {
  306. //提示错误
  307. showMessage({
  308. message: res.msg,
  309. type: "error",
  310. });
  311. }
  312. })
  313. .finally(() => {
  314. forgetPwdLoading.value = false;
  315. });
  316. };
  317. watch(memberMobile, (val) => {
  318. if (val) {
  319. mobileErrorMsg.value = "";
  320. }
  321. });
  322. watch(mobileCode, (val) => {
  323. if (val) {
  324. mobileCodeErrorMsg.value = "";
  325. }
  326. });
  327. </script>
  328. <style lang="scss" scoped>
  329. .center {
  330. flex: 1;
  331. height: 100%;
  332. position: relative;
  333. padding: 0 28px;
  334. margin-top: 60px;
  335. .item {
  336. position: relative;
  337. margin-top: 15px;
  338. border-radius: 2px;
  339. &:first-child {
  340. margin-top: 0;
  341. }
  342. .icon {
  343. position: absolute;
  344. left: 1px;
  345. top: 1px;
  346. width: 50px;
  347. text-align: center;
  348. height: 38px;
  349. background: #f8f8f8;
  350. img {
  351. width: 20px;
  352. }
  353. .input {
  354. border: 1px solid #e8e8e8;
  355. height: 40px;
  356. padding: 0 44px 0 60px;
  357. width: 431px;
  358. }
  359. }
  360. .input {
  361. border: 1px solid #e8e8e8;
  362. height: 40px;
  363. padding: 0 44px 0 60px;
  364. width: 431px;
  365. }
  366. &.code {
  367. .input {
  368. padding-right: 10px;
  369. width: 150px;
  370. }
  371. }
  372. }
  373. .cancel {
  374. position: absolute;
  375. right: 0;
  376. top: 1px;
  377. width: 44px;
  378. height: 38px;
  379. cursor: pointer;
  380. :before {
  381. position: absolute;
  382. top: 9px;
  383. left: 14px;
  384. }
  385. }
  386. .error {
  387. margin-top: 10px;
  388. position: relative;
  389. color: #e2231a;
  390. height: 16px;
  391. line-height: 16px;
  392. }
  393. .verify-code {
  394. display: flex;
  395. width: 431px;
  396. height: 40px;
  397. margin-top: 10px;
  398. &-icon {
  399. width: 50px;
  400. display: flex;
  401. justify-content: center;
  402. align-items: center;
  403. border: 1px solid #e8e8e8;
  404. border-right: none;
  405. background: #f8f8f8;
  406. img {
  407. width: 20px;
  408. }
  409. }
  410. input {
  411. flex: 1;
  412. width: 100%;
  413. border: 1px solid #e8e8e8;
  414. border-left: none;
  415. border-right: none;
  416. height: 40px;
  417. padding: 0 0 0 10px;
  418. width: 190px;
  419. }
  420. &-accept {
  421. display: flex;
  422. justify-content: center;
  423. align-items: center;
  424. width: 90px;
  425. .el-button {
  426. width: 100%;
  427. height: 100%;
  428. color: #fff;
  429. background: $colorMain;
  430. border-left: none;
  431. border-radius: 0;
  432. font-size: 12px;
  433. &:hover {
  434. // border-color: #e8e8e8;
  435. // color: $colorMain;
  436. }
  437. }
  438. }
  439. }
  440. .submit {
  441. margin-top: 50px;
  442. background: $colorMain;
  443. color: #fff;
  444. text-align: center;
  445. border-radius: 2px;
  446. width: 100%;
  447. height: 45px;
  448. font-size: 18px;
  449. letter-spacing: 0px;
  450. &:hover {
  451. opacity: 0.9;
  452. }
  453. &.disabled {
  454. background-color: #909399;
  455. }
  456. }
  457. }
  458. </style>