forgetPassword.vue 5.6 KB

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