forget-password.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view :class="{dark: pattern=='dark'}">
  3. <view class="width100 flex-column-plus pad-32">
  4. <view class="flex-items mar-l-40 mar-t-20">
  5. <!-- <image class="logo" src="../../static/images/image5@3x.png" mode=""></image> -->
  6. </view>
  7. <view class="mar-t-50 pad-32 radius-16">
  8. <view class="input-container flex-items">
  9. <!-- <image class="login_icon mar-l-20 mar-r-20" src="../../static/images/login_email_icon@2x.png"> -->
  10. <!-- </image> -->
  11. <input class="mar-l-10 uni-input" v-model="user.mail" :placeholder="$t('login').r_email" />
  12. <view class="clear-btn" @click="clearInput('mail')" v-if="user.mail">x</view>
  13. </view>
  14. <view class="input-container mar-t-16 flex-row flex-items flex-sp-between">
  15. <input class="mar-l-10 uni-input" v-model="user.code" :placeholder="$t('login').code" />
  16. <view class="clear-btn" @click="clearInput('code')" v-if="user.code">x</view>
  17. <button type="primary" size="mini" :plain="true" @click="getCode">{{ text }}</button>
  18. </view>
  19. <view class="input-container mar-t-16 flex-items">
  20. <!-- <image class="login_icon mar-l-20 mar-r-20" src="../../static/images/Frame@2x.png"></image> -->
  21. <input class="mar-l-10 uni-input" type="password" v-model="user.password"
  22. :placeholder="$t('login').r_password" />
  23. <view class="clear-btn" @click="clearInput('password')" v-if="user.password">x</view>
  24. </view>
  25. <view class="input-container mar-t-16 flex-items">
  26. <!-- <image class="login_icon mar-l-20 mar-r-20" src="../../static/images/Frame@2x.png"></image> -->
  27. <input class="mar-l-10 uni-input" type="password" v-model="user.repassword"
  28. :placeholder="$t('login').r_repassword" />
  29. <view class="clear-btn" @click="clearInput('repassword')" v-if="user.repassword">x</view>
  30. </view>
  31. <button class="mar-t-32 font32" style="background-color: #3C86F7;" type="primary" :loading="loading"
  32. @click="resetPWD">{{$t('login').reset_pwd}}</button>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. getCode,
  40. forgetPassword
  41. } from '@/config/api.js';
  42. const seconds = 60 // 60秒倒计时
  43. export default {
  44. data() {
  45. return {
  46. user: {
  47. mail: '',
  48. code: '',
  49. password: '',
  50. repassword: ''
  51. },
  52. code: '',
  53. loading: false,
  54. timer: null,
  55. seconds: seconds,
  56. status: false,
  57. text: ''
  58. }
  59. },
  60. onLoad() {
  61. uni.setNavigationBarTitle({
  62. title: this.$t('login').reset_pwd
  63. })
  64. this.text = this.$t('login').getcode
  65. },
  66. onShow() {},
  67. onUnload() {
  68. this.timer && this.clearTimer();
  69. },
  70. methods: {
  71. async getCode() {
  72. if (this.status) return
  73. let reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
  74. if (!reg.test(this.user.mail)) return uni.$u.toast(this.$t('login').test_email)
  75. // 请求获取验证码
  76. const res = await getCode({
  77. mail: this.user.mail
  78. })
  79. if (res.code !== 200) return uni.$u.toast(res.msg)
  80. this.status = true
  81. this.countdown()
  82. this.timer = setInterval(() => {
  83. if (this.seconds === 0) {
  84. this.timer && this.clearTimer()
  85. this.status = false
  86. this.text = this.$t('login').getcode
  87. this.seconds = seconds
  88. } else {
  89. this.countdown()
  90. }
  91. }, 1000)
  92. uni.$u.toast(this.$t('login').send_code)
  93. },
  94. countdown() {
  95. this.seconds--
  96. this.text = this.seconds + 's'
  97. },
  98. clearTimer() {
  99. console.log('注销定时器')
  100. clearInterval(this.timer)
  101. this.timer = null
  102. },
  103. async resetPWD() {
  104. // 邮箱
  105. if (this.user.mail == '') {
  106. uni.$u.toast(this.$t('login').email)
  107. return
  108. }
  109. if (this.user.password == '') {
  110. uni.$u.toast(this.$t('login').password)
  111. return
  112. }
  113. if (this.user.password != this.user.repassword) {
  114. uni.$u.toast(this.$t('login').r_password_msg)
  115. return
  116. }
  117. const data = await forgetPassword(this.user)
  118. if (data.code == 200) {
  119. uni.showToast({
  120. title: this.$t('global').reset_psd_success_msg,
  121. duration: 2000,
  122. mask: true,
  123. complete: res => {
  124. this.$Router.replace({
  125. path: '/pages/user/login'
  126. })
  127. }
  128. });
  129. }
  130. },
  131. clearInput(field) {
  132. this.user[field] = '';
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss">
  138. page {
  139. background-color: white;
  140. }
  141. .logo {
  142. width: 170rpx;
  143. height: 47rpx;
  144. }
  145. .uni-input {
  146. height: 80rpx;
  147. line-height: 80rpx;
  148. border: none;
  149. outline: none;
  150. flex: 1;
  151. padding: 0;
  152. }
  153. .input-container {
  154. display: flex;
  155. align-items: center;
  156. border-bottom: 1px solid #ccc;
  157. padding-bottom: 5rpx;
  158. margin-bottom: 16rpx;
  159. }
  160. .login_icon {
  161. width: 45rpx;
  162. height: 45rpx;
  163. }
  164. button {
  165. white-space: nowrap;
  166. margin-right: 10rpx;
  167. }
  168. .clear-btn {
  169. cursor: pointer;
  170. padding: 0 10rpx;
  171. color: #999;
  172. font-size: 30rpx;
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. }
  177. .clear-btn:hover {
  178. color: #333;
  179. }
  180. </style>