login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. <div class="get_sms pointer" @click="getSmsCode">
  38. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  39. </div>
  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. </div>
  85. </template>
  86. <script setup>
  87. import { ElInput, ElMessage } from "element-plus";
  88. import { getCurrentInstance, reactive, ref, watch } from "vue";
  89. // import { lang_zn } from "@/assets/language/zh";
  90. import { getCurLanguage } from "@/composables/common.js";
  91. import { useFiltersStore } from "@/store/filter.js";
  92. import { getContactType } from "@/utils/common";
  93. const contactType = getContactType();
  94. const filtersStore = useFiltersStore();
  95. // const L = lang_zn;
  96. const L = getCurLanguage();
  97. definePageMeta({
  98. layout: "member",
  99. middleware: ["auth"],
  100. });
  101. const sms_code = ref("");
  102. const errorMsg = ref("");
  103. const password = ref(""); //输入新密码
  104. const confirm_password = ref(""); //再次输入新密码
  105. const old_password = ref(""); //输入旧密码
  106. // const confirm_password = ref("");
  107. const timeOutId = ref(""); //定时器的返回值
  108. const countDownM = ref(0); //短信验证码倒计时
  109. const memberInfo = reactive({ data: {} });
  110. const isSmsClick = ref(false);
  111. const getLatestMemberInfo = ref(false);
  112. const getMemberInfo = () => {
  113. get("v3/member/front/member/getInfo").then((res) => {
  114. if (res.state == 200) {
  115. memberInfo.data = res.data;
  116. filtersStore.setMemberInfo(res.data);
  117. getLatestMemberInfo.value = true;
  118. }
  119. });
  120. };
  121. getMemberInfo();
  122. const getSmsCode = () => {
  123. if (isSmsClick.value) {
  124. return;
  125. } else if (countDownM.value) {
  126. return;
  127. }
  128. isSmsClick.value = true;
  129. var param = {};
  130. param.verifyType = 1;
  131. param.verifyAddr = memberInfo.data.memberEmail;
  132. get("v3/msg/front/commons/sendVerifyCode", param).then((res) => {
  133. if (res.state == 200) {
  134. countDownM.value = 60;
  135. countDown();
  136. isSmsClick.value = false;
  137. } else {
  138. ElMessage.error(res.msg);
  139. isSmsClick.value = false;
  140. }
  141. });
  142. };
  143. const next = () => {
  144. isSmsClick.value = false;
  145. let url = "";
  146. let param = {};
  147. if (memberInfo.data.hasLoginPassword) {
  148. if (!sms_code.value) {
  149. errorMsg.value = L["请输入验证码"];
  150. return false;
  151. }
  152. //修改登录密码
  153. if (!old_password.value) {
  154. errorMsg.value = L["请输入原密码"];
  155. return false;
  156. }
  157. if (!password.value) {
  158. errorMsg.value = L["请输入新密码"];
  159. return false;
  160. }
  161. if (!confirm_password.value) {
  162. errorMsg.value = L["请再次输入新密码"];
  163. return false;
  164. }
  165. if (password.value != confirm_password.value) {
  166. errorMsg.value = L["请输入一致的新密码"];
  167. return false;
  168. }
  169. //验证新密码是否符合规则
  170. let checkPwdVal = checkPwd(password.value);
  171. if (checkPwdVal !== true) {
  172. errorMsg.value = checkPwdVal;
  173. return false;
  174. }
  175. url = "v3/member/front/memberPassword/editLoginPwd";
  176. param.oldLoginPwd = old_password.value;
  177. param.loginPwd = password.value;
  178. param.memberEmail = memberInfo.data.memberEmail;
  179. param.verifyCode = sms_code.value;
  180. }
  181. post(url, param).then((res) => {
  182. if (res.state == 200) {
  183. ElMessage.success(res.msg);
  184. if (!memberInfo.data.hasLoginPassword) {
  185. memberInfo.data.hasLoginPassword = 1;
  186. filtersStore.setMemberInfo(memberInfo.data);
  187. }
  188. errorMsg.value = "";
  189. password.value = "";
  190. confirm_password.value = "";
  191. old_password.value = "";
  192. } else {
  193. errorMsg.value = res.msg;
  194. }
  195. });
  196. };
  197. //倒计时
  198. const countDown = () => {
  199. countDownM.value--;
  200. if (countDownM.value == 0) {
  201. isSmsClick.value = false;
  202. clearTimeout(timeOutId.value);
  203. } else {
  204. timeOutId.value = setTimeout(countDown, 1000);
  205. }
  206. };
  207. watch([old_password, password, confirm_password], () => {
  208. old_password.value = old_password.value.substring(0, 20);
  209. password.value = password.value.substring(0, 20);
  210. confirm_password.value = confirm_password.value.substring(0, 20);
  211. });
  212. </script>
  213. <style lang="scss" scoped>
  214. @import "@/assets/style/theme.scss";
  215. .sld_login_password_mange {
  216. width: 957px;
  217. float: left;
  218. margin-left: 10px;
  219. .container {
  220. background-color: white;
  221. width: 100%;
  222. box-sizing: border-box;
  223. border: 1px solid #eaeaea;
  224. padding: 25px 40px;
  225. .manage_tips {
  226. width: 938px;
  227. background: #fffdee;
  228. border: 1px solid #edd28b;
  229. padding: 15px 36px;
  230. margin-top: 117px;
  231. p {
  232. color: #555555;
  233. margin-top: 10px;
  234. }
  235. .tips_title {
  236. font-weight: bold;
  237. margin-bottom: 11px;
  238. margin-top: 0;
  239. }
  240. }
  241. .title {
  242. font-size: 18px;
  243. border-bottom: 1px dashed #eaeaea;
  244. padding-bottom: 25px;
  245. font-weight: 600;
  246. margin-bottom: 20px;
  247. }
  248. .mange_con {
  249. width: 360px;
  250. margin: 62px auto 0;
  251. .current {
  252. line-height: 56px;
  253. font-size: 14px;
  254. color: #000000;
  255. }
  256. .error_tip {
  257. height: 15px;
  258. margin-top: 10px;
  259. color: #f30213;
  260. i {
  261. margin-right: 10px;
  262. }
  263. }
  264. .without_phone_tip {
  265. line-height: 56px;
  266. font-size: 16px;
  267. color: $colorMain2;
  268. }
  269. .sms_code_con {
  270. position: relative;
  271. width: 100%;
  272. :deep(.el-input) {
  273. width: 250px;
  274. z-index: 1;
  275. }
  276. :deep(.el-input__inner) {
  277. width: 250px;
  278. }
  279. .get_sms {
  280. display: flex;
  281. justify-content: center; /* 水平居中 */
  282. align-items: center; /* 垂直居中 */
  283. text-align: center; /* 多行文本居中 */
  284. position: absolute;
  285. right: -25px;
  286. top: 0;
  287. width: 120px;
  288. height: 40px;
  289. background: #00985e;
  290. color: white;
  291. font-size: 14px;
  292. border-radius: 0 3px 3px 0;
  293. padding: 5px 10px;
  294. }
  295. }
  296. .margin {
  297. margin-top: 20px;
  298. }
  299. .next {
  300. width: 170px;
  301. height: 40px;
  302. background: #00985e;
  303. color: #fff;
  304. font-size: 18px;
  305. font-weight: bold;
  306. text-align: center;
  307. color: white;
  308. margin-top: 20px;
  309. line-height: 40px;
  310. border-radius: 3px;
  311. margin: 42px auto 0;
  312. }
  313. }
  314. }
  315. }
  316. </style>
  317. <style lang="scss">
  318. .sld_login_password_mange {
  319. .el-input {
  320. width: 280px;
  321. height: 40px;
  322. border-radius: 3px 0 0 3px;
  323. position: inherit;
  324. }
  325. .el-input__inner {
  326. width: 280px;
  327. height: 40px;
  328. border-radius: 3px 0 0 3px;
  329. }
  330. .input {
  331. width: 100%;
  332. height: 40px;
  333. margin-top: 20px;
  334. border-radius: 3px;
  335. .el-input__wrapper {
  336. width: 100%;
  337. }
  338. .el-input__inner {
  339. height: 40px;
  340. border-radius: 3px;
  341. width: 100%;
  342. }
  343. }
  344. }
  345. .el-input__inner:focus {
  346. border-color: $colorMain;
  347. outline: 0;
  348. }
  349. /**
  350. * 解决el-input设置类型为number时,中文输入法光标上移问题
  351. **/
  352. .el-input__inner {
  353. line-height: 1px !important;
  354. }
  355. </style>