login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 = 1;
  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. param.memberEmail = memberInfo.data.memberEmail;
  206. param.verifyCode = sms_code.value;
  207. }
  208. post(url, param).then((res) => {
  209. if (res.state == 200) {
  210. ElMessage.success(res.msg);
  211. if (!memberInfo.data.hasLoginPassword) {
  212. memberInfo.data.hasLoginPassword = 1;
  213. filtersStore.setMemberInfo(memberInfo.data);
  214. }
  215. errorMsg.value = "";
  216. password.value = "";
  217. confirm_password.value = "";
  218. old_password.value = "";
  219. } else {
  220. errorMsg.value = res.msg;
  221. }
  222. });
  223. };
  224. //倒计时
  225. const countDown = () => {
  226. countDownM.value--;
  227. if (countDownM.value == 0) {
  228. clearTimeout(timeOutId.value);
  229. } else {
  230. timeOutId.value = setTimeout(countDown, 1000);
  231. }
  232. };
  233. watch([old_password, password, confirm_password], () => {
  234. old_password.value = old_password.value.substring(0, 20);
  235. password.value = password.value.substring(0, 20);
  236. confirm_password.value = confirm_password.value.substring(0, 20);
  237. });
  238. </script>
  239. <style lang="scss">
  240. .register-verify-model {
  241. .el-dialog__title {
  242. font-weight: 900 !important;
  243. }
  244. .el-dialog__body {
  245. display: flex;
  246. justify-content: center;
  247. align-items: center;
  248. }
  249. }
  250. </style>
  251. <style lang="scss" scoped>
  252. @import "@/assets/style/theme.scss";
  253. .sld_login_password_mange {
  254. width: 957px;
  255. float: left;
  256. margin-left: 10px;
  257. .container {
  258. background-color: white;
  259. width: 100%;
  260. box-sizing: border-box;
  261. border: 1px solid #eaeaea;
  262. padding: 25px 40px;
  263. .manage_tips {
  264. width: 938px;
  265. background: #fffdee;
  266. border: 1px solid #edd28b;
  267. padding: 15px 36px;
  268. margin-top: 117px;
  269. p {
  270. color: #555555;
  271. margin-top: 10px;
  272. }
  273. .tips_title {
  274. font-weight: bold;
  275. margin-bottom: 11px;
  276. margin-top: 0;
  277. }
  278. }
  279. .title {
  280. font-size: 18px;
  281. border-bottom: 1px dashed #eaeaea;
  282. padding-bottom: 25px;
  283. font-weight: 600;
  284. margin-bottom: 20px;
  285. }
  286. .mange_con {
  287. width: 360px;
  288. margin: 62px auto 0;
  289. .current {
  290. line-height: 56px;
  291. font-size: 14px;
  292. color: #000000;
  293. }
  294. .error_tip {
  295. height: 15px;
  296. margin-top: 10px;
  297. color: #f30213;
  298. i {
  299. margin-right: 10px;
  300. }
  301. }
  302. .without_phone_tip {
  303. line-height: 56px;
  304. font-size: 16px;
  305. color: $colorMain2;
  306. }
  307. .sms_code_con {
  308. position: relative;
  309. width: 100%;
  310. :deep(.el-input) {
  311. width: 250px;
  312. z-index: 1;
  313. }
  314. :deep(.el-input__inner) {
  315. width: 250px;
  316. }
  317. .get_sms {
  318. display: flex;
  319. justify-content: center; /* 水平居中 */
  320. align-items: center; /* 垂直居中 */
  321. text-align: center; /* 多行文本居中 */
  322. position: absolute;
  323. white-space: pre-wrap;
  324. right: -25px;
  325. top: 0;
  326. width: 120px;
  327. height: 40px;
  328. background: #00985e;
  329. color: white;
  330. font-size: 14px;
  331. border-radius: 0 3px 3px 0;
  332. padding: 5px 10px;
  333. }
  334. }
  335. .margin {
  336. margin-top: 20px;
  337. }
  338. .next {
  339. width: 170px;
  340. height: 40px;
  341. background: #00985e;
  342. color: #fff;
  343. font-size: 18px;
  344. font-weight: bold;
  345. text-align: center;
  346. color: white;
  347. margin-top: 20px;
  348. line-height: 40px;
  349. border-radius: 3px;
  350. margin: 42px auto 0;
  351. }
  352. }
  353. }
  354. }
  355. </style>
  356. <style lang="scss">
  357. .sld_login_password_mange {
  358. .el-input {
  359. width: 280px;
  360. height: 40px;
  361. border-radius: 3px 0 0 3px;
  362. position: inherit;
  363. }
  364. .el-input__inner {
  365. width: 280px;
  366. height: 40px;
  367. border-radius: 3px 0 0 3px;
  368. }
  369. .input {
  370. width: 100%;
  371. height: 40px;
  372. margin-top: 20px;
  373. border-radius: 3px;
  374. .el-input__wrapper {
  375. width: 100%;
  376. }
  377. .el-input__inner {
  378. height: 40px;
  379. border-radius: 3px;
  380. width: 100%;
  381. }
  382. }
  383. }
  384. .el-input__inner:focus {
  385. border-color: $colorMain;
  386. outline: 0;
  387. }
  388. /**
  389. * 解决el-input设置类型为number时,中文输入法光标上移问题
  390. **/
  391. .el-input__inner {
  392. line-height: 1px !important;
  393. }
  394. </style>