pwdEdit.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="container">
  3. <!-- 旧密码输入框 -->
  4. <view class="input-group-header">旧密码:</view>
  5. <view class="uni-input-wrapper">
  6. <input class="uni-input" placeholder="请输入旧密码" :password="showPassword1" v-model="oldPassword" />
  7. <text class="uni-icon" :class="[!showPassword1 ? 'uni-eye-active' : '']"
  8. @click="changePassword1">&#xe568;</text>
  9. </view>
  10. <view class="input-group-header">新密码:</view>
  11. <!-- 新密码输入框 -->
  12. <view class="uni-input-wrapper">
  13. <input class="uni-input" placeholder="请输入新密码" :password="showPassword2" v-model="newPassword" />
  14. <text class="uni-icon" :class="[!showPassword2 ? 'uni-eye-active' : '']"
  15. @click="changePassword2">&#xe568;</text>
  16. </view>
  17. <!-- 确认新密码输入框 -->
  18. <view class="uni-input-wrapper">
  19. <input class="uni-input" placeholder="请确认新密码" :password="showPassword3" v-model="confirmPassword" />
  20. <text class="uni-icon" :class="[!showPassword3 ? 'uni-eye-active' : '']"
  21. @click="changePassword3">&#xe568;</text>
  22. </view>
  23. <!-- 提交按钮 -->
  24. <button @click="submit" class="submitBtn">提交</button>
  25. </view>
  26. </template>
  27. <script setup lang="ts">
  28. import {
  29. ref
  30. } from 'vue';
  31. import $modal from '@/plugins/modal.js'
  32. import {
  33. changePWD
  34. } from '@/api/mine';
  35. import {
  36. useUserStore
  37. } from '@/store/user';
  38. import $tab from '@/plugins/tab.js'
  39. const userStore = useUserStore();
  40. const oldPassword = ref(''); // 旧密码
  41. const newPassword = ref(''); // 新密码
  42. const confirmPassword = ref(''); // 确认新密码
  43. const showPassword1 = ref(true); // 旧密码可见性
  44. const showPassword2 = ref(true); // 新密码可见性
  45. const showPassword3 = ref(true); // 确认密码可见性
  46. // 提交逻辑
  47. function submit() {
  48. // 检查新密码和确认密码是否一致
  49. if (newPassword.value !== confirmPassword.value) {
  50. $modal.showToast('新密码和确认密码不一致')
  51. return; // 终止提交
  52. }
  53. // 检查新密码强度
  54. if (!validatePassword(newPassword.value)) {
  55. $modal.showToast('新密码必须包含至少6个字符、包含字母和数字')
  56. return; // 终止提交
  57. }
  58. // 通过校验后,提示提交成功
  59. const params = {
  60. staffId: userStore.user.useId,
  61. oldpassword: oldPassword.value,
  62. newpassword: newPassword.value,
  63. }
  64. changePWD(params).then(res => {
  65. $modal.showToast(res.returnMsg);
  66. if ("1" == res.returnCode) { //修改成功
  67. userStore.LogOut().then(() => {
  68. $tab.reLaunch('/pages/login')
  69. })
  70. }
  71. })
  72. }
  73. // 校验密码强度
  74. function validatePassword(password) {
  75. // 密码至少有6个字符,包含字母和数字
  76. const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/;
  77. return passwordRegex.test(password);
  78. }
  79. // 切换旧密码可见性
  80. function changePassword1() {
  81. showPassword1.value = !showPassword1.value;
  82. }
  83. // 切换新密码可见性
  84. function changePassword2() {
  85. showPassword2.value = !showPassword2.value;
  86. }
  87. // 切换确认密码可见性
  88. function changePassword3() {
  89. showPassword3.value = !showPassword3.value;
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .container{
  94. padding-top: 1rem;
  95. .input-group-header{
  96. margin-left: 1rem;
  97. }
  98. .uni-input-wrapper {
  99. display: flex;
  100. align-items: center;
  101. margin: 1rem;
  102. background-color: #ffffff;
  103. .uni-icon {
  104. margin: 20rpx;
  105. }
  106. }
  107. .submitBtn {
  108. background-color: #007aff;
  109. color: white;
  110. width: 90%;
  111. margin-top: 2rem;
  112. }
  113. }
  114. .uni-eye-active {
  115. color: #007aff;
  116. }
  117. </style>