index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="container">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header">
  5. <view class="header-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
  7. </view>
  8. <text class="header-title">修改密码</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <view class="header-placeholder"></view>
  12. <view class="form-card">
  13. <view class="form-item">
  14. <text class="form-label">旧密码</text>
  15. <input
  16. class="form-input"
  17. type="password"
  18. v-model="oldPassword"
  19. placeholder="请输入旧密码"
  20. placeholder-class="placeholder"
  21. />
  22. </view>
  23. <view class="form-item">
  24. <text class="form-label">新密码</text>
  25. <input
  26. class="form-input"
  27. type="password"
  28. v-model="newPassword"
  29. placeholder="请输入新密码(6-20位)"
  30. placeholder-class="placeholder"
  31. />
  32. </view>
  33. <view class="form-item no-border">
  34. <text class="form-label">确认密码</text>
  35. <input
  36. class="form-input"
  37. type="password"
  38. v-model="confirmPassword"
  39. placeholder="请再次输入新密码"
  40. placeholder-class="placeholder"
  41. />
  42. </view>
  43. </view>
  44. <view class="btn-area">
  45. <button class="submit-btn" @click="submitChange">确认修改</button>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. // 引入 API @author steelwei
  51. import { updatePassword } from '@/api/fulfiller/fulfiller'
  52. export default {
  53. data() {
  54. return {
  55. oldPassword: '',
  56. newPassword: '',
  57. confirmPassword: ''
  58. }
  59. },
  60. methods: {
  61. navBack() {
  62. uni.navigateBack({ delta: 1 });
  63. },
  64. // 提交修改 @author steelwei
  65. async submitChange() {
  66. // 验证输入
  67. if (!this.oldPassword) {
  68. uni.showToast({ title: '请输入旧密码', icon: 'none' });
  69. return;
  70. }
  71. if (!this.newPassword) {
  72. uni.showToast({ title: '请输入新密码', icon: 'none' });
  73. return;
  74. }
  75. if (this.newPassword.length < 6 || this.newPassword.length > 20) {
  76. uni.showToast({ title: '密码长度为6-20位', icon: 'none' });
  77. return;
  78. }
  79. if (this.newPassword !== this.confirmPassword) {
  80. uni.showToast({ title: '两次密码输入不一致', icon: 'none' });
  81. return;
  82. }
  83. uni.showLoading({ title: '提交中...' });
  84. try {
  85. const res = await updatePassword(this.oldPassword, this.newPassword);
  86. if (res.code === 200) {
  87. uni.showToast({
  88. title: '修改成功',
  89. icon: 'success',
  90. duration: 2000
  91. });
  92. setTimeout(() => {
  93. uni.navigateBack({ delta: 1 });
  94. }, 2000);
  95. } else {
  96. uni.showToast({
  97. title: res.msg || '修改失败',
  98. icon: 'none'
  99. });
  100. }
  101. } catch (error) {
  102. console.error('修改密码失败:', error);
  103. uni.showToast({ title: error.message || error.msg || '请求失败', icon: 'none' });
  104. } finally {
  105. uni.hideLoading();
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style>
  112. page {
  113. background-color: #F8F8F8;
  114. }
  115. .custom-header {
  116. position: fixed;
  117. top: 0;
  118. left: 0;
  119. width: 100%;
  120. height: 88rpx;
  121. padding-top: var(--status-bar-height);
  122. background-color: #fff;
  123. display: flex;
  124. align-items: center;
  125. justify-content: space-between;
  126. padding-left: 30rpx;
  127. padding-right: 30rpx;
  128. box-sizing: content-box;
  129. z-index: 100;
  130. }
  131. .header-placeholder {
  132. height: calc(88rpx + var(--status-bar-height));
  133. }
  134. .back-icon {
  135. width: 40rpx;
  136. height: 40rpx;
  137. }
  138. .header-title {
  139. font-size: 28rpx;
  140. font-weight: bold;
  141. color: #333;
  142. }
  143. .header-right {
  144. width: 40rpx;
  145. }
  146. .container {
  147. padding: 20rpx 30rpx;
  148. }
  149. .form-card {
  150. background-color: #fff;
  151. border-radius: 20rpx;
  152. padding: 0 30rpx;
  153. margin-bottom: 30rpx;
  154. }
  155. .form-item {
  156. display: flex;
  157. align-items: center;
  158. padding: 30rpx 0;
  159. border-bottom: 1px solid #F5F5F5;
  160. }
  161. .form-item.no-border {
  162. border-bottom: none;
  163. }
  164. .form-label {
  165. width: 160rpx;
  166. font-size: 28rpx;
  167. color: #333;
  168. }
  169. .form-input {
  170. flex: 1;
  171. font-size: 28rpx;
  172. color: #333;
  173. }
  174. .placeholder {
  175. color: #999;
  176. }
  177. .btn-area {
  178. padding: 40rpx 0;
  179. }
  180. .submit-btn {
  181. background-color: #FF5722;
  182. color: #fff;
  183. font-size: 32rpx;
  184. border-radius: 44rpx;
  185. height: 88rpx;
  186. line-height: 88rpx;
  187. border: none;
  188. }
  189. </style>