forgetPassword.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view class="setting-page">
  3. <view class="content">
  4. <view class="info-item">
  5. <text class="title">手机号码</text>
  6. <input class="input-field code-input" type="text" :password="!phone" v-model="phone"
  7. placeholder="请输入手机号码" />
  8. </view>
  9. <view class="info-item">
  10. <text class="title">验证码</text>
  11. <input class="input-field code-input" type="number" v-model="verifyCode"
  12. placeholder="请输入验证码" maxlength="6" />
  13. <view class="get-code-btn" @click="getVerifyCode">
  14. {{ codeText }}
  15. </view>
  16. </view>
  17. <view class="info-item">
  18. <text class="title">新密码</text>
  19. <input class="input-field code-input" type="text" :password="!showNewPassword" v-model="newPassword"
  20. placeholder="请输入8-20位字母、数字" />
  21. <view class="img-box" @click="toggleNewPassword">
  22. <image class="icon"
  23. :src="showNewPassword?'/static/image/icon_visible.png':'/static/image/icon_invisible.png'"
  24. mode="aspectFill"></image>
  25. </view>
  26. </view>
  27. <view class="info-item">
  28. <text class="title">确认密码</text>
  29. <input class="input-field code-input" type="text" :password="!showConfirmPassword"
  30. v-model="confirmPassword" placeholder="请再次输入新密码" />
  31. <view class="img-box" @click="toggleConfirmPassword">
  32. <image class="icon"
  33. :src="showConfirmPassword?'/static/image/icon_visible.png':'/static/image/icon_invisible.png'"
  34. mode="aspectFill"></image>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="btn-box">
  39. <view class="confirm" @click="confirm">确认</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. phone:17873014571,
  48. codeText: '获取验证码', // 验证码按钮文字
  49. newPassword: '',
  50. confirmPassword: '',
  51. // 为每个密码框单独设置显示状态
  52. showOldPassword: false,
  53. showNewPassword: false,
  54. showConfirmPassword: false
  55. }
  56. },
  57. onLoad() {},
  58. methods: {
  59. // 获取验证码
  60. getVerifyCode() {
  61. if (this.countdown > 0) {
  62. return;
  63. }
  64. if (!this.phone) {
  65. uni.showToast({
  66. icon: 'none',
  67. title: "请输入手机号",
  68. });
  69. return;
  70. }
  71. if (!/^1[3-9]\d{9}$/.test(this.phone)) {
  72. uni.showToast({
  73. icon: 'none',
  74. title: "请输入正确的手机号",
  75. });
  76. return;
  77. }
  78. // TODO: 调用发送验证码API
  79. // 这里需要对接真实的发送验证码接口
  80. uni.showLoading({
  81. title: "发送中..."
  82. });
  83. // 模拟发送验证码
  84. setTimeout(() => {
  85. uni.hideLoading();
  86. uni.showToast({
  87. icon: 'success',
  88. title: "验证码已发送",
  89. });
  90. // 开始倒计时
  91. this.countdown = 60;
  92. this.countdownTimer = setInterval(() => {
  93. this.countdown--;
  94. this.codeText = this.countdown + '秒重新获取';
  95. if (this.countdown <= 0) {
  96. clearInterval(this.countdownTimer);
  97. this.countdownTimer = null;
  98. this.codeText = '获取验证码';
  99. }
  100. }, 1000);
  101. }, 1000);
  102. },
  103. // 分别控制每个密码框的显示/隐藏
  104. toggleOldPassword() {
  105. this.showOldPassword = !this.showOldPassword;
  106. },
  107. toggleNewPassword() {
  108. this.showNewPassword = !this.showNewPassword;
  109. },
  110. toggleConfirmPassword() {
  111. this.showConfirmPassword = !this.showConfirmPassword;
  112. },
  113. confirm() {
  114. // 验证逻辑
  115. if (!this.oldPassword) {
  116. uni.showToast({
  117. title: '请输入原密码',
  118. icon: 'none'
  119. });
  120. return;
  121. }
  122. if (!this.newPassword) {
  123. uni.showToast({
  124. title: '请输入新密码',
  125. icon: 'none'
  126. });
  127. return;
  128. }
  129. // 密码格式验证
  130. const passwordRegex = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,20}$/;
  131. if (!passwordRegex.test(this.newPassword)) {
  132. uni.showToast({
  133. title: '密码需8-20位字母和数字组合',
  134. icon: 'none'
  135. });
  136. return;
  137. }
  138. if (this.newPassword !== this.confirmPassword) {
  139. uni.showToast({
  140. title: '两次输入的新密码不一致',
  141. icon: 'none'
  142. });
  143. return;
  144. }
  145. // 调用修改密码的API
  146. this.changePassword();
  147. },
  148. // 修改密码的API调用
  149. async changePassword() {
  150. try {
  151. uni.showLoading({
  152. title: '修改中...'
  153. });
  154. // 这里添加实际的API调用
  155. // const res = await uni.request({
  156. // url: '/api/change-password',
  157. // method: 'POST',
  158. // data: {
  159. // oldPassword: this.oldPassword,
  160. // newPassword: this.newPassword
  161. // }
  162. // });
  163. // 模拟成功
  164. setTimeout(() => {
  165. uni.hideLoading();
  166. uni.showToast({
  167. title: '密码修改成功',
  168. icon: 'success'
  169. });
  170. // 清空表单
  171. this.oldPassword = '';
  172. this.newPassword = '';
  173. this.confirmPassword = '';
  174. // 跳转到其他页面或返回
  175. setTimeout(() => {
  176. uni.navigateBack();
  177. }, 1500);
  178. }, 1000);
  179. } catch (error) {
  180. uni.hideLoading();
  181. uni.showToast({
  182. title: error.message || '修改失败',
  183. icon: 'none'
  184. });
  185. }
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .setting-page {
  192. background: #ffffff;
  193. min-height: 100vh;
  194. .content {
  195. background: #ffffff;
  196. }
  197. .info-item {
  198. height: 104upx;
  199. display: flex;
  200. align-items: center;
  201. justify-content: space-between;
  202. border-bottom: 1px solid #F5F6FA;
  203. .title {
  204. width: 160rpx;
  205. font-size: 28rpx;
  206. color: #666666;
  207. margin-left: 32rpx;
  208. }
  209. .input-field {
  210. width: 100%;
  211. font-size: 30rpx;
  212. font-family: PingFang SC;
  213. color: #333333;
  214. }
  215. .code-input {
  216. flex: 1;
  217. }
  218. .img-box {
  219. padding: 32rpx;
  220. .icon {
  221. width: 32rpx;
  222. height: 32rpx;
  223. }
  224. }
  225. .get-code-btn {
  226. margin-right: 32rpx;
  227. font-size: 28rpx;
  228. font-weight: 500;
  229. color: #157CF8;
  230. padding-left: 20rpx;
  231. white-space: nowrap;
  232. }
  233. }
  234. .btn-box {
  235. padding: 64upx 32upx;
  236. .confirm {
  237. width: 100%;
  238. height: 88upx;
  239. line-height: 88upx;
  240. text-align: center;
  241. font-family: PingFang SC;
  242. font-size: 32upx;
  243. color: #FFFFFF;
  244. background: #388BFF;
  245. border-radius: 44upx;
  246. }
  247. }
  248. }
  249. </style>