pwdEdit.vue 3.4 KB

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