login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <!--
  2. * @Author: wangwei
  3. * @Date: 2020-12-29 16:05:36
  4. * @LastEditTime: 2021-01-15 19:08:07
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 登录密码
  7. * @FilePath: /java-pc/src/views/member/center/accountSafe.vue
  8. -->
  9. <template>
  10. <div class="sld_login_password_mange" v-if="getLatestMemberInfo">
  11. <MemberTitle :memberTitle="L['登录密码']"></MemberTitle>
  12. <div class="container">
  13. <div class="title">
  14. {{ memberInfo.data.hasLoginPassword ? L["修改"] : L["设置"] }}
  15. {{ L["登录密码"] }}
  16. </div>
  17. <div class="mange_con">
  18. <div class="without_phone_tip" v-if="!memberInfo.data.memberEmail && contactType === 'email'">
  19. {{ L["请先绑定邮箱,再进行登陆密码操作!"] }}
  20. </div>
  21. <div class="without_phone_tip" v-if="!memberInfo.data.memberMobile && contactType === 'mobile'">
  22. {{ L["请先绑定手机号,再进行登陆密码操作!"] }}
  23. </div>
  24. <!-- 修改登录密码 start -->
  25. <template v-if="memberInfo.data.hasLoginPassword">
  26. <span class="current"
  27. >{{ L[contactType ==='email' ? "当前邮箱账号" : '当前手机号'] }}
  28. {{
  29. contactType ==='email' ? memberInfo.data.memberEmail ? memberInfo.data.memberEmail : "--" : memberInfo.data.memberMobile
  30. }}</span
  31. >
  32. <div class="sms_code_con">
  33. <el-input
  34. v-model="sms_code"
  35. :placeholder="L[contactType === 'email' ? '请输入邮件验证码' : '请输入短信验证码']"
  36. ></el-input>
  37. <el-button :disabled="countDownM" :loading="getSmsLoading" class="get_sms pointer" @click="showHMVerify">
  38. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  39. </el-button>
  40. </div>
  41. <el-input
  42. type="password"
  43. class="password input"
  44. v-model="old_password"
  45. :placeholder="L['请输入原密码']"
  46. ></el-input>
  47. <el-input
  48. type="password"
  49. class="password input"
  50. v-model="password"
  51. :placeholder="L['请输入新密码']"
  52. ></el-input>
  53. <el-input
  54. type="password"
  55. class="password input"
  56. v-model="confirm_password"
  57. :placeholder="L['请再次输入新密码']"
  58. ></el-input>
  59. <div class="error_tip">
  60. <span
  61. v-if="errorMsg"
  62. style="color: #e1251b; font-size: 14px"
  63. class="iconfont icon-jubao"
  64. ></span>
  65. {{ errorMsg }}
  66. </div>
  67. <div class="next flex_row_center_center pointer" @click="next">
  68. {{ L["修改密码"] }}
  69. </div>
  70. </template>
  71. <!-- 修改登录密码 end -->
  72. </div>
  73. <!-- <div class="manage_tips">-->
  74. <!-- <p class="tips_title">{{ L["温馨提示"] }}:</p>-->
  75. <!-- <p>• {{ L["为了保障您的账号安全,变更重要信息需进行身份验证。"] }}</p>-->
  76. <!-- <p>• {{ L["变更过程中有任何疑问请联系在线客服解决。"] }}</p>-->
  77. <!-- <p>-->
  78. <!-- •-->
  79. <!-- {{ L["如手机号/邮箱已不再使用无法获取验证码,请联系在线客服解决。"] }}-->
  80. <!-- </p>-->
  81. <!-- <p>• {{ L["复杂的密码可使账号更安全且建议定期更换密码。"] }}</p>-->
  82. <!-- </div>-->
  83. </div>
  84. <el-dialog
  85. :title="L['register']['滑动验证']"
  86. destroy-on-close
  87. width="500px"
  88. center
  89. modal-class="register-verify-model"
  90. v-model="modalVisible"
  91. >
  92. <SliderVerify
  93. :slideVerifyOptions="{ show: false, w: 450, h: 220 }"
  94. @onSuccess="verifySuccess"
  95. @onFail="verifyFail"
  96. />
  97. </el-dialog>
  98. </div>
  99. </template>
  100. <script setup>
  101. import { ElInput, ElMessage } from "element-plus";
  102. import { getCurrentInstance, reactive, ref, watch } from "vue";
  103. // import { lang_zn } from "@/assets/language/zh";
  104. import { getCurLanguage } from "@/composables/common.js";
  105. import { useFiltersStore } from "@/store/filter.js";
  106. import { getContactType } from "@/utils/common";
  107. const contactType = getContactType();
  108. const filtersStore = useFiltersStore();
  109. // const L = lang_zn;
  110. const L = getCurLanguage();
  111. definePageMeta({
  112. layout: "member",
  113. middleware: ["auth"],
  114. });
  115. const sms_code = ref("");
  116. const errorMsg = ref("");
  117. const password = ref(""); //输入新密码
  118. const confirm_password = ref(""); //再次输入新密码
  119. const old_password = ref(""); //输入旧密码
  120. // const confirm_password = ref("");
  121. const timeOutId = ref(""); //定时器的返回值
  122. const countDownM = ref(0); //短信验证码倒计时
  123. const memberInfo = reactive({ data: {} });
  124. const isSmsClick = ref(false);
  125. const getLatestMemberInfo = ref(false);
  126. const modalVisible = ref(false);
  127. const getSmsLoading = ref(false)
  128. const getMemberInfo = () => {
  129. get("v3/member/front/member/getInfo").then((res) => {
  130. if (res.state == 200) {
  131. memberInfo.data = res.data;
  132. filtersStore.setMemberInfo(res.data);
  133. getLatestMemberInfo.value = true;
  134. }
  135. });
  136. };
  137. getMemberInfo();
  138. //开启人机校验
  139. const showHMVerify = () => {
  140. modalVisible.value = true;
  141. };
  142. // 人机验证成功
  143. const verifySuccess = () => {
  144. modalVisible.value = false;
  145. getSmsCode();
  146. };
  147. // 人机校验失败
  148. const verifyFail = () => {
  149. showMessage({
  150. message: L["register"]["校验不通过"],
  151. type: "warning",
  152. });
  153. };
  154. const getSmsCode = () => {
  155. var param = {};
  156. param.verifyType = contactType === 'email' ? 1 : 2;
  157. const verifyAddr = contactType === 'email' ? memberInfo.data.memberEmail : memberInfo.data.memberMobile
  158. param.verifyAddr = verifyAddr;
  159. getSmsLoading.value = true;
  160. get("v3/msg/front/commons/sendVerifyCode", param).then((res) => {
  161. if (res.state == 200) {
  162. countDownM.value = 60;
  163. countDown();
  164. } else {
  165. ElMessage.error(res.msg);
  166. }
  167. }).finally(() => {
  168. getSmsLoading.value = false;
  169. })
  170. };
  171. const next = () => {
  172. let url = "";
  173. let param = {};
  174. if (memberInfo.data.hasLoginPassword) {
  175. if (!sms_code.value) {
  176. errorMsg.value = L["请输入验证码"];
  177. return false;
  178. }
  179. //修改登录密码
  180. if (!old_password.value) {
  181. errorMsg.value = L["请输入原密码"];
  182. return false;
  183. }
  184. if (!password.value) {
  185. errorMsg.value = L["请输入新密码"];
  186. return false;
  187. }
  188. if (!confirm_password.value) {
  189. errorMsg.value = L["请再次输入新密码"];
  190. return false;
  191. }
  192. if (password.value != confirm_password.value) {
  193. errorMsg.value = L["请输入一致的新密码"];
  194. return false;
  195. }
  196. //验证新密码是否符合规则
  197. let checkPwdVal = checkPwd(password.value);
  198. if (checkPwdVal !== true) {
  199. errorMsg.value = checkPwdVal;
  200. return false;
  201. }
  202. url = "v3/member/front/memberPassword/editLoginPwd";
  203. param.oldLoginPwd = old_password.value;
  204. param.loginPwd = password.value;
  205. if(contactType === 'email') {
  206. param.memberEmail = memberInfo.data.memberEmail;
  207. } else {
  208. param.memberMobile = memberInfo.data.memberMobile;
  209. }
  210. param.verifyCode = sms_code.value;
  211. }
  212. post(url, param).then((res) => {
  213. if (res.state == 200) {
  214. ElMessage.success(res.msg);
  215. if (!memberInfo.data.hasLoginPassword) {
  216. memberInfo.data.hasLoginPassword = 1;
  217. filtersStore.setMemberInfo(memberInfo.data);
  218. }
  219. errorMsg.value = "";
  220. password.value = "";
  221. confirm_password.value = "";
  222. old_password.value = "";
  223. } else {
  224. errorMsg.value = res.msg;
  225. }
  226. });
  227. };
  228. //倒计时
  229. const countDown = () => {
  230. countDownM.value--;
  231. if (countDownM.value == 0) {
  232. clearTimeout(timeOutId.value);
  233. } else {
  234. timeOutId.value = setTimeout(countDown, 1000);
  235. }
  236. };
  237. watch([old_password, password, confirm_password], () => {
  238. old_password.value = old_password.value.substring(0, 20);
  239. password.value = password.value.substring(0, 20);
  240. confirm_password.value = confirm_password.value.substring(0, 20);
  241. });
  242. </script>
  243. <style lang="scss">
  244. .register-verify-model {
  245. .el-dialog__title {
  246. font-weight: 900 !important;
  247. }
  248. .el-dialog__body {
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. }
  253. }
  254. </style>
  255. <style lang="scss" scoped>
  256. @import "@/assets/style/theme.scss";
  257. .sld_login_password_mange {
  258. width: 957px;
  259. float: left;
  260. margin-left: 10px;
  261. .container {
  262. background-color: white;
  263. width: 100%;
  264. box-sizing: border-box;
  265. border: 1px solid #eaeaea;
  266. padding: 25px 40px;
  267. .manage_tips {
  268. width: 938px;
  269. background: #fffdee;
  270. border: 1px solid #edd28b;
  271. padding: 15px 36px;
  272. margin-top: 117px;
  273. p {
  274. color: #555555;
  275. margin-top: 10px;
  276. }
  277. .tips_title {
  278. font-weight: bold;
  279. margin-bottom: 11px;
  280. margin-top: 0;
  281. }
  282. }
  283. .title {
  284. font-size: 18px;
  285. border-bottom: 1px dashed #eaeaea;
  286. padding-bottom: 25px;
  287. font-weight: 600;
  288. margin-bottom: 20px;
  289. }
  290. .mange_con {
  291. width: 360px;
  292. margin: 62px auto 0;
  293. .current {
  294. line-height: 56px;
  295. font-size: 14px;
  296. color: #000000;
  297. }
  298. .error_tip {
  299. height: 15px;
  300. margin-top: 10px;
  301. color: #f30213;
  302. i {
  303. margin-right: 10px;
  304. }
  305. }
  306. .without_phone_tip {
  307. line-height: 56px;
  308. font-size: 16px;
  309. color: $colorMain2;
  310. }
  311. .sms_code_con {
  312. position: relative;
  313. width: 100%;
  314. :deep(.el-input) {
  315. width: 250px;
  316. z-index: 1;
  317. }
  318. :deep(.el-input__inner) {
  319. width: 250px;
  320. }
  321. .get_sms {
  322. display: flex;
  323. justify-content: center; /* 水平居中 */
  324. align-items: center; /* 垂直居中 */
  325. text-align: center; /* 多行文本居中 */
  326. position: absolute;
  327. white-space: pre-wrap;
  328. right: -25px;
  329. top: 0;
  330. width: 120px;
  331. height: 40px;
  332. background: #00985e;
  333. color: white;
  334. font-size: 14px;
  335. border-radius: 0 3px 3px 0;
  336. padding: 5px 10px;
  337. }
  338. }
  339. .margin {
  340. margin-top: 20px;
  341. }
  342. .next {
  343. width: 170px;
  344. height: 40px;
  345. background: #00985e;
  346. color: #fff;
  347. font-size: 18px;
  348. font-weight: bold;
  349. text-align: center;
  350. color: white;
  351. margin-top: 20px;
  352. line-height: 40px;
  353. border-radius: 3px;
  354. margin: 42px auto 0;
  355. }
  356. }
  357. }
  358. }
  359. </style>
  360. <style lang="scss">
  361. .sld_login_password_mange {
  362. .el-input {
  363. width: 280px;
  364. height: 40px;
  365. border-radius: 3px 0 0 3px;
  366. position: inherit;
  367. }
  368. .el-input__inner {
  369. width: 280px;
  370. height: 40px;
  371. border-radius: 3px 0 0 3px;
  372. }
  373. .input {
  374. width: 100%;
  375. height: 40px;
  376. margin-top: 20px;
  377. border-radius: 3px;
  378. .el-input__wrapper {
  379. width: 100%;
  380. }
  381. .el-input__inner {
  382. height: 40px;
  383. border-radius: 3px;
  384. width: 100%;
  385. }
  386. }
  387. }
  388. .el-input__inner:focus {
  389. border-color: $colorMain;
  390. outline: 0;
  391. }
  392. /**
  393. * 解决el-input设置类型为number时,中文输入法光标上移问题
  394. **/
  395. .el-input__inner {
  396. line-height: 1px !important;
  397. }
  398. </style>