RetrievePwdByPhone.vue 11 KB

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