RetrievePassword.vue 11 KB

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