index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="change-password-page">
  3. <nav-bar title="修改密码" bgColor="#fff" color="#000"></nav-bar>
  4. <view class="form-container">
  5. <view class="form-group">
  6. <view class="form-item">
  7. <label class="form-label">旧密码</label>
  8. <input class="form-input" type="text" :password="!showOldPwd" v-model="formData.oldPassword"
  9. placeholder="请输入当前密码" placeholder-class="input-placeholder" />
  10. <view class="pwd-toggle" @click="showOldPwd = !showOldPwd">
  11. <text class="toggle-icon">{{ showOldPwd ? '隐藏' : '显示' }}</text>
  12. </view>
  13. </view>
  14. <view class="line"></view>
  15. <view class="form-item">
  16. <label class="form-label">新密码</label>
  17. <input class="form-input" type="text" :password="!showNewPwd" v-model="formData.newPassword"
  18. placeholder="6-20位新密码" placeholder-class="input-placeholder" />
  19. <view class="pwd-toggle" @click="showNewPwd = !showNewPwd">
  20. <text class="toggle-icon">{{ showNewPwd ? '隐藏' : '显示' }}</text>
  21. </view>
  22. </view>
  23. <view class="line"></view>
  24. <view class="form-item">
  25. <label class="form-label">确认密码</label>
  26. <input class="form-input" type="text" :password="!showConfirmPwd" v-model="formData.confirmPassword"
  27. placeholder="请再次输入新密码" placeholder-class="input-placeholder" />
  28. <view class="pwd-toggle" @click="showConfirmPwd = !showConfirmPwd">
  29. <text class="toggle-icon">{{ showConfirmPwd ? '隐藏' : '显示' }}</text>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="btn-group">
  34. <button class="submit-btn" @click="submit">提交修改</button>
  35. </view>
  36. <view class="tip-text">
  37. <text class="tip-icon">ℹ️</text>
  38. <text>密码修改成功后,系统将自动安全退出,需重新登录。</text>
  39. </view>
  40. <!-- 错误提示 -->
  41. <view v-if="errorMsg" class="error-toast">
  42. <text>{{ errorMsg }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import { ref, reactive } from 'vue'
  49. import navBar from '@/components/nav-bar/index.vue'
  50. import { updateUserPwd } from '@/api/system/user'
  51. const formData = reactive({
  52. oldPassword: '',
  53. newPassword: '',
  54. confirmPassword: ''
  55. })
  56. const showOldPwd = ref(false)
  57. const showNewPwd = ref(false)
  58. const showConfirmPwd = ref(false)
  59. const errorMsg = ref('')
  60. const validate = () => {
  61. errorMsg.value = ''
  62. if (!formData.oldPassword) {
  63. errorMsg.value = '请输入旧密码'
  64. return false
  65. }
  66. if (!formData.newPassword) {
  67. errorMsg.value = '请输入新密码'
  68. return false
  69. }
  70. if (formData.newPassword.length < 6 || formData.newPassword.length > 20) {
  71. errorMsg.value = '密码长度在 6-20 位之间'
  72. return false
  73. }
  74. if (!formData.confirmPassword) {
  75. errorMsg.value = '请确认新密码'
  76. return false
  77. }
  78. if (formData.confirmPassword !== formData.newPassword) {
  79. errorMsg.value = '两次输入的密码不一致'
  80. return false
  81. }
  82. return true
  83. }
  84. const submit = async () => {
  85. if (!validate()) return
  86. try {
  87. uni.showLoading({ title: '修改中...' })
  88. await updateUserPwd(formData.oldPassword, formData.newPassword)
  89. uni.hideLoading()
  90. uni.showToast({ title: '密码修改成功,请重新登录', icon: 'success' })
  91. setTimeout(() => {
  92. uni.removeStorageSync('token')
  93. uni.reLaunch({ url: '/pages/login/index' })
  94. }, 1500)
  95. } catch (err) {
  96. uni.hideLoading()
  97. console.log('请求失败', err)
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .change-password-page {
  103. min-height: 100vh;
  104. background-color: #f7f8fa;
  105. padding-top: 20rpx;
  106. }
  107. .form-group {
  108. background: #fff;
  109. margin: 0 24rpx;
  110. border-radius: 20rpx;
  111. padding: 0 32rpx;
  112. }
  113. .form-item {
  114. display: flex;
  115. align-items: center;
  116. padding: 28rpx 0;
  117. }
  118. .form-label {
  119. width: 140rpx;
  120. flex-shrink: 0;
  121. font-size: 30rpx;
  122. color: #333;
  123. font-weight: 500;
  124. }
  125. .form-input {
  126. flex: 1;
  127. font-size: 28rpx;
  128. color: #333;
  129. height: 48rpx;
  130. line-height: 48rpx;
  131. }
  132. .pwd-toggle {
  133. margin-left: 16rpx;
  134. padding: 8rpx 16rpx;
  135. .toggle-icon {
  136. font-size: 24rpx;
  137. color: #999;
  138. }
  139. }
  140. .line {
  141. height: 2rpx;
  142. background: #EEEEEE;
  143. margin: 0;
  144. }
  145. .btn-group {
  146. margin: 60rpx 32rpx 32rpx;
  147. }
  148. .submit-btn {
  149. height: 88rpx;
  150. line-height: 88rpx;
  151. background: linear-gradient(90deg, #ffd53f, #ff9500);
  152. color: #fff;
  153. border: none;
  154. border-radius: 44rpx;
  155. font-size: 30rpx;
  156. font-weight: bold;
  157. &::after { border: none; }
  158. }
  159. .tip-text {
  160. padding: 0 40rpx;
  161. display: flex;
  162. align-items: center;
  163. gap: 12rpx;
  164. font-size: 24rpx;
  165. color: #999;
  166. }
  167. .tip-icon {
  168. font-size: 28rpx;
  169. }
  170. .error-toast {
  171. margin: 20rpx 32rpx 0;
  172. padding: 16rpx 24rpx;
  173. background: #fff2f0;
  174. border-radius: 10rpx;
  175. text {
  176. color: #ff4d4f;
  177. font-size: 26rpx;
  178. }
  179. }
  180. .input-placeholder {
  181. color: #c0c4cc;
  182. font-size: 28rpx;
  183. }
  184. </style>