forgot.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view class="forgot-container">
  3. <view class="form-container">
  4. <text class="title">找回密码</text>
  5. <view class="input-group">
  6. <text class="label">手机号/邮箱</text>
  7. <input
  8. v-model="account"
  9. class="input"
  10. placeholder="请输入注册时的手机号或邮箱"
  11. type="text"
  12. />
  13. </view>
  14. <view class="input-group">
  15. <text class="label">验证码</text>
  16. <view class="code-input-group">
  17. <input
  18. v-model="code"
  19. class="input code-input"
  20. placeholder="请输入验证码"
  21. type="number"
  22. />
  23. <button
  24. class="code-btn"
  25. :disabled="countdown > 0"
  26. @click="getVerificationCode"
  27. >
  28. {{ countdown > 0 ? `${countdown}s后重试` : '获取验证码' }}
  29. </button>
  30. </view>
  31. </view>
  32. <view class="input-group">
  33. <text class="label">新密码</text>
  34. <input
  35. v-model="newPassword"
  36. class="input"
  37. placeholder="请输入新密码"
  38. :type="showPassword ? 'text' : 'password'"
  39. />
  40. <text
  41. class="toggle-password"
  42. @click="showPassword = !showPassword"
  43. >
  44. {{ showPassword ? '隐藏' : '显示' }}
  45. </text>
  46. </view>
  47. <button
  48. class="submit-btn"
  49. :disabled="!canSubmit"
  50. @click="handleResetPassword"
  51. >
  52. 重置密码
  53. </button>
  54. <view class="footer">
  55. <text>想起密码了?</text>
  56. <text class="link" @click="goToLogin">返回登录</text>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. return {
  65. account: '',
  66. code: '',
  67. newPassword: '',
  68. showPassword: false,
  69. countdown: 0,
  70. timer: null
  71. };
  72. },
  73. computed: {
  74. canSubmit() {
  75. return this.account && this.code && this.newPassword;
  76. }
  77. },
  78. methods: {
  79. async getVerificationCode() {
  80. if (!this.account) {
  81. uni.showToast({
  82. title: '请输入手机号或邮箱',
  83. icon: 'none'
  84. });
  85. return;
  86. }
  87. try {
  88. // TODO: 调用获取验证码接口
  89. await this.$api.auth.getResetCode({
  90. account: this.account
  91. });
  92. uni.showToast({
  93. title: '验证码已发送',
  94. icon: 'none'
  95. });
  96. this.startCountdown();
  97. } catch (error) {
  98. uni.showToast({
  99. title: error.message || '获取验证码失败',
  100. icon: 'none'
  101. });
  102. }
  103. },
  104. startCountdown() {
  105. this.countdown = 60;
  106. this.timer = setInterval(() => {
  107. if (this.countdown <= 0) {
  108. clearInterval(this.timer);
  109. return;
  110. }
  111. this.countdown--;
  112. }, 1000);
  113. },
  114. async handleResetPassword() {
  115. try {
  116. // TODO: 调用重置密码接口
  117. await this.$api.auth.resetPassword({
  118. account: this.account,
  119. code: this.code,
  120. newPassword: this.newPassword
  121. });
  122. uni.showToast({
  123. title: '密码重置成功',
  124. icon: 'success'
  125. });
  126. this.goToLogin();
  127. } catch (error) {
  128. uni.showToast({
  129. title: error.message || '重置密码失败',
  130. icon: 'none'
  131. });
  132. }
  133. },
  134. goToLogin() {
  135. uni.navigateTo({
  136. url: '/pages/auth/login'
  137. });
  138. }
  139. },
  140. beforeDestroy() {
  141. if (this.timer) {
  142. clearInterval(this.timer);
  143. }
  144. }
  145. };
  146. </script>
  147. <style scoped>
  148. .forgot-container {
  149. padding: 40rpx;
  150. }
  151. .form-container {
  152. background-color: #fff;
  153. border-radius: 16rpx;
  154. padding: 40rpx;
  155. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  156. }
  157. .title {
  158. font-size: 40rpx;
  159. font-weight: bold;
  160. margin-bottom: 60rpx;
  161. display: block;
  162. text-align: center;
  163. }
  164. .input-group {
  165. margin-bottom: 40rpx;
  166. position: relative;
  167. }
  168. .label {
  169. font-size: 28rpx;
  170. color: #666;
  171. margin-bottom: 16rpx;
  172. display: block;
  173. }
  174. .input {
  175. height: 88rpx;
  176. border: 2rpx solid #eee;
  177. border-radius: 8rpx;
  178. padding: 0 24rpx;
  179. font-size: 28rpx;
  180. width: 100%;
  181. box-sizing: border-box;
  182. }
  183. .code-input-group {
  184. display: flex;
  185. align-items: center;
  186. }
  187. .code-input {
  188. flex: 1;
  189. margin-right: 20rpx;
  190. }
  191. .code-btn {
  192. width: 200rpx;
  193. height: 88rpx;
  194. background-color: #f5f5f5;
  195. color: #007aff;
  196. border-radius: 8rpx;
  197. font-size: 24rpx;
  198. }
  199. .code-btn[disabled] {
  200. color: #999;
  201. }
  202. .toggle-password {
  203. position: absolute;
  204. right: 24rpx;
  205. top: 50rpx;
  206. color: #007aff;
  207. font-size: 24rpx;
  208. }
  209. .submit-btn {
  210. height: 88rpx;
  211. background-color: #007aff;
  212. color: #fff;
  213. border-radius: 8rpx;
  214. font-size: 32rpx;
  215. margin-bottom: 40rpx;
  216. }
  217. .submit-btn[disabled] {
  218. background-color: #ccc;
  219. }
  220. .footer {
  221. text-align: center;
  222. font-size: 24rpx;
  223. color: #666;
  224. }
  225. .link {
  226. color: #007aff;
  227. margin-left: 10rpx;
  228. }
  229. </style>