email.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <!--
  2. * @Author: wangwei
  3. * @Date: 2020-12-29 16:05:36
  4. * @LastEditTime: 2021-01-25 09:56:17
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 邮箱管理
  7. * @FilePath: /java-pc/src/views/member/center/accountSafe.vue
  8. -->
  9. <template>
  10. <div class="sld_email_mange" v-if="getLatestMemberInfo">
  11. <MemberTitle :memberTitle="L['邮箱管理']"></MemberTitle>
  12. <div class="container" >
  13. <div class="title">
  14. {{ memberInfo.data.memberEmail ? L["修改电子邮箱"] : L["绑定电子邮箱"] }}
  15. </div>
  16. <div class="mange_con">
  17. <!--会员未绑定邮箱 start-->
  18. <template v-if="!memberInfo.data.memberEmail">
  19. <el-input
  20. class="password input"
  21. v-model="new_mobile"
  22. :placeholder="L['请输入新邮箱']"
  23. ></el-input>
  24. <div class="sms_code_con flex_row_center_center margin">
  25. <el-input
  26. v-model="new_sms_code"
  27. :placeholder="L['请输入邮箱验证码']"
  28. type="number"
  29. ></el-input>
  30. <div class="get_sms pointer" @click="showHMVerify">
  31. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  32. </div>
  33. </div>
  34. <div class="error_tip">
  35. <span
  36. v-if="errorMsg"
  37. style="color: #e1251b; font-size: 14px"
  38. class="iconfont icon-jubao"
  39. ></span>
  40. {{ errorMsg }}
  41. </div>
  42. <div class="next flex_row_center_center" @click="bindEmail">{{L["确定提交"]}}</div>
  43. </template>
  44. <!--会员未绑定邮箱 end-->
  45. <!--会员修改邮箱 start-->
  46. <template v-if="memberInfo.data.memberEmail">
  47. <span class="current"
  48. >{{L["当前邮箱账号"]}} {{ memberInfo.data.memberEmail }}</span
  49. >
  50. <div v-if="step == 1" class="sms_code_con flex_row_center_center">
  51. <el-input
  52. v-model="old_sms_code"
  53. :placeholder="L['请输入邮箱验证码']"
  54. type="number"
  55. ></el-input>
  56. <el-button :disabled="countDownM" :loading="getSmsLoading" class="get_sms pointer" @click="showHMVerify">
  57. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  58. </el-button>
  59. </div>
  60. <el-input
  61. v-if="step == 2"
  62. class="password input"
  63. v-model="new_mobile"
  64. :placeholder="L['请输入新邮箱']"
  65. >
  66. </el-input>
  67. <div class="error_tip" v-if="emailErrorMsg">
  68. <span
  69. style="color: #e1251b; font-size: 14px"
  70. class="iconfont icon-jubao"
  71. ></span>
  72. {{ emailErrorMsg }}
  73. </div>
  74. <div
  75. v-if="step == 2"
  76. class="sms_code_con flex_row_center_center margin"
  77. >
  78. <el-input
  79. v-model="new_sms_code"
  80. :placeholder="L['请输入邮箱验证码']"
  81. maxlength="6"
  82. ></el-input>
  83. <el-button :disabled="countDownM" :loading="getSmsLoading" class="get_sms pointer" @click="showHMVerify">
  84. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  85. </el-button>
  86. </div>
  87. <div class="error_tip">
  88. <span
  89. v-if="errorMsg"
  90. style="color: #e1251b; font-size: 14px"
  91. class="iconfont icon-jubao"
  92. ></span>
  93. {{ errorMsg }}
  94. </div>
  95. <div class="next flex_row_center_center" @click="next">
  96. {{ step == 1 ? L['下一步'] : L['确定'] }}
  97. </div>
  98. </template>
  99. <!--会员修改邮箱 start-->
  100. </div>
  101. <!-- <div class="manage_tips">-->
  102. <!-- <p class="tips_title">{{ L["温馨提示"] }}:</p>-->
  103. <!-- <p>• {{ L["为了保障您的账号安全,变更重要信息需进行身份验证。"] }}</p>-->
  104. <!-- <p>• {{ L["变更过程中有任何疑问请联系在线客服解决。"] }}</p>-->
  105. <!-- <p>-->
  106. <!-- •-->
  107. <!-- {{ L["如手机号/邮箱已不再使用无法获取验证码,请联系在线客服解决。"] }}-->
  108. <!-- </p>-->
  109. <!-- </div>-->
  110. </div>
  111. <el-dialog
  112. :title="L['register']['滑动验证']"
  113. destroy-on-close
  114. width="500px"
  115. center
  116. modal-class="email-verify-model"
  117. v-model="modalVisible"
  118. >
  119. <SliderVerify
  120. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  121. @onSuccess="verifySuccess"
  122. @onFail="verifyFail"
  123. />
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script setup>
  128. import { ElInput, ElMessage, ElMessageBox } from "element-plus";
  129. import { getCurrentInstance, reactive, ref, onMounted, watch } from "vue";
  130. // import { lang_zn } from "@/assets/language/zh";
  131. import { getCurLanguage } from '@/composables/common.js';
  132. import { useFiltersStore } from "@/store/filter.js";
  133. const filtersStore = useFiltersStore();
  134. // const L = lang_zn;
  135. const L = getCurLanguage();
  136. definePageMeta({
  137. layout: "member",
  138. middleware: ["auth"],
  139. });
  140. const { proxy } = getCurrentInstance();
  141. const step = ref(1);
  142. const errorMsg = ref("");
  143. const emailErrorMsg = ref("");
  144. const old_sms_code = ref("");
  145. const new_sms_code = ref("");
  146. const new_mobile = ref("");
  147. const timeOutId = ref(""); //定时器的返回值
  148. const countDownM = ref(0); //短信验证码倒计时
  149. const memberInfo = reactive({ data: filtersStore.getMemberInfo });
  150. const getLatestMemberInfo = ref(false)
  151. const modalVisible = ref(false);
  152. const getSmsLoading = ref(false)
  153. const getMemberInfo = () => {
  154. get("v3/member/front/member/getInfo").then((res) => {
  155. if (res.state == 200) {
  156. filtersStore.setMemberInfo(res.data)
  157. getLatestMemberInfo.value = true
  158. }
  159. });
  160. }
  161. //开启人机校验
  162. const showHMVerify = () => {
  163. //验证新邮箱是否正确
  164. if (step.value == 2) {
  165. if (!new_mobile.value) {
  166. emailErrorMsg.value = L["请输入邮箱号"];
  167. return;
  168. } else {
  169. let checkEmailVal = checkEmail(new_mobile.value);
  170. if (checkEmailVal !== true) {
  171. emailErrorMsg.value = checkEmailVal;
  172. return;
  173. } else {
  174. emailErrorMsg.value = "";
  175. }
  176. }
  177. }
  178. modalVisible.value = true;
  179. };
  180. // 人机验证成功
  181. const verifySuccess = () => {
  182. modalVisible.value = false;
  183. getSmsCode();
  184. };
  185. // 人机校验失败
  186. const verifyFail = () => {
  187. showMessage({
  188. message: L["register"]["校验不通过"],
  189. type: "warning",
  190. });
  191. };
  192. const getSmsCode = () => {
  193. var param = {};
  194. param.verifyType = 1;
  195. //未绑定邮箱
  196. if (!memberInfo.data.memberEmail) {
  197. param.verifyAddr = new_mobile.value;
  198. param.changeType = "";
  199. } else {
  200. param.verifyAddr =
  201. step.value == 1 ? memberInfo.data.memberEmail : new_mobile.value;
  202. param.changeType = step.value == 1 ? "old" : "new";
  203. }
  204. getSmsLoading.value = true;
  205. get("v3/msg/front/commons/sendVerifyCode", param).then((res) => {
  206. if (res.state == 200) {
  207. countDownM.value = 60;
  208. countDown();
  209. } else {
  210. ElMessage.error(res.msg);
  211. }
  212. }).finally(() => {
  213. getSmsLoading.value = false;
  214. })
  215. };
  216. //绑定邮箱
  217. const bindEmail = () => {
  218. //验证邮箱是否正确
  219. if (step.value == 2) {
  220. if (!new_mobile.value) {
  221. emailErrorMsg.value = L["请输入邮箱号"];
  222. return false;
  223. } else {
  224. let checkEmailVal = checkEmail(new_mobile.value);
  225. if (checkEmailVal !== true) {
  226. emailErrorMsg.value = checkEmailVal;
  227. return false;
  228. }
  229. }
  230. emailErrorMsg.value = ''
  231. }
  232. //验证码校验
  233. if (!new_sms_code.value) {
  234. errorMsg.value = L["请输入邮箱验证码"];
  235. return false;
  236. } else {
  237. let checkEmailCodeVal = checkEmailCode(new_sms_code.value);
  238. if (checkEmailCodeVal !== true) {
  239. errorMsg.value = checkEmailCodeVal;
  240. return false;
  241. } else {
  242. errorMsg.value = "";
  243. }
  244. }
  245. post("v3/member/front/memberPassword/editEmail", {
  246. memberEmail: new_mobile.value,
  247. emailCode: new_sms_code.value,
  248. })
  249. .then((res) => {
  250. if (res.state == 200) {
  251. clearTimeout(timeOutId.value);
  252. countDownM.value = 0;
  253. errorMsg.value = "";
  254. new_sms_code.value = "";
  255. ElMessage.success(res.msg);
  256. //更新个人信息
  257. memberInfo.data.memberEmail = new_mobile.value;
  258. filtersStore.setMemberInfo(memberInfo.data)
  259. } else if (res.state == 267) {
  260. ElMessageBox.confirm(res.msg, L["提示"], {
  261. confirmButtonText: L["确定"],
  262. cancelButtonText: L["取消"],
  263. type: "warning",
  264. }).then(() => {
  265. post("v3/member/front/memberPassword/editEmail", {
  266. memberEmail: new_mobile.value,
  267. emailCode: new_sms_code.value,
  268. isUnbound: 1,
  269. })
  270. .then((res) => {
  271. if (res.state == 200) {
  272. ElMessage.success(res.msg);
  273. memberInfo.data.memberEmail = new_mobile.value;
  274. filtersStore.setMemberInfo(memberInfo.data)
  275. errorMsg.value = "";
  276. new_mobile.value = "";
  277. new_sms_code.value = "";
  278. //更新个人信息
  279. } else {
  280. ElMessage.error(res.msg);
  281. }
  282. });
  283. });
  284. } else {
  285. errorMsg.value = res.msg;
  286. }
  287. });
  288. };
  289. const next = () => {
  290. let param = {};
  291. let url = "";
  292. if (step.value == 1) {
  293. //验证码校验
  294. if (!old_sms_code.value) {
  295. errorMsg.value = L["请输入邮箱验证码"];
  296. return false;
  297. } else {
  298. let checkEmailCodeVal = checkEmailCode(old_sms_code.value);
  299. if (checkEmailCodeVal !== true) {
  300. errorMsg.value = checkEmailCodeVal;
  301. return false;
  302. }
  303. }
  304. url = "v3/member/front/memberPassword/verifyOldEmail";
  305. param.memberEmail = memberInfo.data.memberEmail;
  306. param.emailCode = old_sms_code.value;
  307. } else if (step.value == 2) {
  308. let checkEmailVal = checkEmail(new_mobile.value);
  309. if (checkEmailVal !== true) {
  310. return false;
  311. }
  312. url = "v3/member/front/memberPassword/editEmail";
  313. param.memberEmail = new_mobile.value;
  314. param.emailCode = new_sms_code.value;
  315. }
  316. post(url, param).then((res) => {
  317. if (res.state == 200) {
  318. if (step.value == 1) {
  319. step.value = 2;
  320. }
  321. if (step.value == 2) {
  322. //更新个人信息
  323. memberInfo.data.memberEmail = new_mobile.value;
  324. filtersStore.setMemberInfo(memberInfo.data)
  325. step.value = 1;
  326. }
  327. errorMsg.value = "";
  328. clearTimeout(timeOutId.value);
  329. countDownM.value = 0;
  330. } else if (res.state == 267) {
  331. ElMessageBox.confirm(res.msg, L["提示"], {
  332. confirmButtonText: L["确定"],
  333. cancelButtonText: L["取消"],
  334. type: "warning",
  335. }).then(() => {
  336. post("v3/member/front/memberPassword/editEmail", {
  337. memberEmail: new_mobile.value,
  338. emailCode: new_sms_code.value,
  339. isUnbound: 1,
  340. })
  341. .then((res) => {
  342. if (res.state == 200) {
  343. ElMessage.success(res.msg);
  344. //更新个人信息
  345. memberInfo.data.memberEmail = new_mobile.value;
  346. filtersStore.setMemberInfo(memberInfo.data)
  347. errorMsg.value = "";
  348. step.value = 1;
  349. } else {
  350. ElMessage.error(res.msg);
  351. }
  352. });
  353. });
  354. } else {
  355. errorMsg.value = res.msg;
  356. }
  357. });
  358. };
  359. //倒计时
  360. const countDown = () => {
  361. countDownM.value--;
  362. if (countDownM.value == 0) {
  363. clearTimeout(timeOutId.value);
  364. } else {
  365. timeOutId.value = setTimeout(countDown, 1000);
  366. }
  367. };
  368. watch(new_mobile, () => {
  369. new_mobile.value = new_mobile.value.substring(0, 50);
  370. errorMsg.value = "";
  371. });
  372. watch([old_sms_code, new_sms_code], () => {
  373. old_sms_code.value = old_sms_code.value.substring(0, 4);
  374. new_sms_code.value = new_sms_code.value.substring(0, 4);
  375. errorMsg.value = "";
  376. });
  377. onMounted(() => {
  378. getMemberInfo()
  379. if (!memberInfo.data.memberEmail) {
  380. step.value = 2;
  381. }
  382. });
  383. onUnmounted(() => {
  384. getMemberInfo()
  385. })
  386. </script>
  387. <style lang="scss">
  388. .email-verify-model {
  389. .el-dialog__title {
  390. font-weight: 900 !important;
  391. }
  392. .el-dialog__body {
  393. display: flex;
  394. justify-content: center;
  395. align-items: center;
  396. }
  397. }
  398. </style>
  399. <style lang="scss" scoped>
  400. .sld_email_mange {
  401. width: 957px;
  402. float: left;
  403. margin-left: 10px;
  404. .container {
  405. background-color: white;
  406. width: 100%;
  407. box-sizing: border-box;
  408. border: 1px solid #eaeaea;
  409. padding: 25px 40px;
  410. min-height: 600px;
  411. .manage_tips {
  412. width: 938px;
  413. background: #fffdee;
  414. border: 1px solid #edd28b;
  415. padding: 15px 36px;
  416. margin-top: 117px;
  417. p {
  418. color: #555555;
  419. margin-top: 10px;
  420. }
  421. .tips_title {
  422. font-weight: bold;
  423. margin-bottom: 11px;
  424. margin-top: 0;
  425. }
  426. }
  427. .title {
  428. font-size: 18px;
  429. border-bottom: 1px dashed #eaeaea;
  430. padding-bottom: 25px;
  431. font-weight: 600;
  432. margin-bottom: 20px;
  433. }
  434. .mange_con {
  435. width: 460px;
  436. margin: 62px auto 0;
  437. .current {
  438. line-height: 56px;
  439. font-size: 14px;
  440. color: #333333;
  441. width: 100%;
  442. text-align: center;
  443. display: block;
  444. }
  445. .error_tip {
  446. height: 15px;
  447. margin-top: 10px;
  448. color: #f30213;
  449. i {
  450. margin-right: 10px;
  451. }
  452. }
  453. .sms_code_con {
  454. position: relative;
  455. width: 100%;
  456. .get_sms {
  457. // display: flex;
  458. // justify-content: center; /* 水平居中 */
  459. // align-items: center; /* 垂直居中 */
  460. // text-align: center; /* 多行文本居中 */
  461. // position: absolute;
  462. white-space: pre-wrap;
  463. right: -25px;
  464. top: 0;
  465. width: 120px;
  466. height: 40px;
  467. background: #00985e;
  468. color: white;
  469. font-size: 14px;
  470. border-radius: 0 3px 3px 0;
  471. padding: 5px 10px;
  472. }
  473. }
  474. .margin {
  475. margin-top: 20px;
  476. }
  477. .input {
  478. width: 100%;
  479. height: 44px;
  480. margin-top: 20px;
  481. .el-input__inner {
  482. height: 54px;
  483. }
  484. }
  485. .next {
  486. width: 170px;
  487. height: 40px;
  488. background: #00985e;
  489. color: #fff;
  490. font-size: 18px;
  491. font-weight: bold;
  492. text-align: center;
  493. color: white;
  494. margin-top: 20px;
  495. line-height: 40px;
  496. border-radius: 3px;
  497. margin: 42px auto 0;
  498. cursor: pointer;
  499. }
  500. }
  501. }
  502. }
  503. </style>
  504. <style lang="scss">
  505. .sld_email_mange {
  506. .el-input {
  507. width: 360px;
  508. height: 40px;
  509. border-radius: 3px 0 0 3px;
  510. position: inherit;
  511. }
  512. .el-input__inner {
  513. width: 280px;
  514. height: 40px;
  515. border-radius: 3px 0 0 3px;
  516. }
  517. .input {
  518. width: 100%;
  519. height: 40px;
  520. margin-top: 20px;
  521. border-radius: 3px;
  522. .el-input__inner {
  523. height: 40px;
  524. border-radius: 3px;
  525. width: 100%;
  526. }
  527. }
  528. }
  529. .el-input__inner:focus {
  530. border-color: $colorMain;
  531. outline: 0;
  532. }
  533. input[type="number"] {
  534. -moz-appearance: textfield;
  535. }
  536. input[type="number"]::-webkit-inner-spin-button,
  537. input[type="number"]::-webkit-outer-spin-button {
  538. -webkit-appearance: none;
  539. margin: 0;
  540. }
  541. /**
  542. * 解决el-input设置类型为number时,中文输入法光标上移问题
  543. **/
  544. .el-input__inner {
  545. line-height: 1px !important;
  546. }
  547. </style>