RetrievePassword.vue 11 KB

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