RetrievePassword.vue 11 KB

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