forgot.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="content">
  3. <view class="logo">
  4. <image style="height:104rpx;width:104rpx" src="/static/czzn-img/login/logo.jpg" mode="aspectFit" />
  5. <view class="app-name">{{$t('login.e')}}</view>
  6. </view>
  7. <!-- 账号密码登录 -->
  8. <view class="inp_box">
  9. <input type="text" v-model="forgotForm.mobile" :placeholder="this.$t('login.phonePlaceholder')" />
  10. </view>
  11. <view class="inp_box">
  12. <input type="text" v-model="forgotForm.code" :placeholder="this.$t('login.verifyCodePlaceholder')" />
  13. <button :class="time!=0?'load-reget':''" @click="getCode" :disabled='time!=0'
  14. class="get-code-btn">{{isGetCode?$t("login.reGetCode"):$t("login.getCode")}}{{time?`(${time}s)`:''}}</button>
  15. </view>
  16. <view class="inp_box">
  17. <input type="password" v-model="forgotForm.password"
  18. :placeholder="this.$t('register.passwordDigitsPlaceholder')" />
  19. </view>
  20. <view class="inp_box">
  21. <input type="password" v-model="forgotForm.confirmPassword"
  22. :placeholder="this.$t('register.passwordAgain')" />
  23. </view>
  24. <view class="btn-wrap">
  25. <button class="bind-btn" @click="resetPassword">{{$t('login.reset')}}</button>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. resetPassword,
  32. getTelCode
  33. } from '../../api/login'
  34. export default {
  35. data() {
  36. return {
  37. forgotForm: {
  38. mobile: "",
  39. code: "",
  40. password: "",
  41. confirmPassword: "",
  42. },
  43. time: 0,
  44. timer: '',
  45. isGetCode: false,
  46. }
  47. },
  48. methods: {
  49. backLogin() {
  50. uni.redirectTo({
  51. url: '/pages/login/login'
  52. })
  53. },
  54. resetPassword() {
  55. let phone = /^1[3-9]\d{9}$/
  56. if (this.forgotForm.mobile == '') {
  57. uni.showToast({
  58. title: this.$t('login.phonePlaceholder'),
  59. icon: "none",
  60. duration: 2500,
  61. })
  62. } else if (!phone.test(this.forgotForm.mobile)) {
  63. uni.showToast({
  64. title: this.$t('base.smsCode.phoneErrTip'),
  65. icon: "none",
  66. duration: 2500,
  67. })
  68. } else if (this.forgotForm.code == '') {
  69. uni.showToast({
  70. title: this.$t('login.verifyCodePlaceholder'),
  71. icon: "none",
  72. duration: 2500,
  73. })
  74. } else if (this.forgotForm.password == '' || this.forgotForm.confirmPassword == '') {
  75. uni.showToast({
  76. title: this.$t('login.verifyCodePlaceholder'),
  77. icon: "none",
  78. duration: 2500,
  79. })
  80. } else if (this.forgotForm.password !== this.forgotForm.confirmPassword) {
  81. uni.showToast({
  82. title: this.$t('login.diffrent'),
  83. icon: "none",
  84. duration: 2500,
  85. })
  86. } else {
  87. let data = {
  88. phone: this.forgotForm.mobile,
  89. newpassword1: this.forgotForm.password,
  90. verificationCode: this.forgotForm.code
  91. }
  92. resetPassword(data).then(res => {
  93. if (res.statusCode === 200) {
  94. if (res.data.msg) {
  95. uni.showToast({
  96. title: res.data.msg,
  97. icon: "none",
  98. duration: 2500,
  99. })
  100. } else {
  101. uni.showToast({
  102. title: '重置成功',
  103. icon: "none",
  104. duration: 1000,
  105. })
  106. setTimeout(() => {
  107. this.backLogin()
  108. }, 1200)
  109. }
  110. } else {
  111. uni.showToast({
  112. title: res.data.msg,
  113. icon: "none",
  114. duration: 2500,
  115. })
  116. }
  117. })
  118. }
  119. },
  120. getCode() {
  121. let phone = /^1[3-9]\d{9}$/
  122. if (this.forgotForm.mobile == '') {
  123. uni.showToast({
  124. title: this.$t('login.phonePlaceholder'),
  125. icon: "none",
  126. duration: 2500,
  127. })
  128. } else if (!phone.test(this.forgotForm.mobile)) {
  129. uni.showToast({
  130. title: this.$t('base.smsCode.phoneErrTip'),
  131. icon: "none",
  132. duration: 2500,
  133. })
  134. } else {
  135. getTelCode(this.forgotForm.mobile).then(res => {
  136. if (res.statusCode === 200) {
  137. if (res.data.code == 0) {
  138. if (res.data.msg) {
  139. uni.showToast({
  140. title: res.data.msg,
  141. icon: "none",
  142. duration: 2500,
  143. })
  144. return;
  145. }
  146. this.isGetCode = true
  147. this.time = 60
  148. this.forgotForm.code = ""
  149. this.forgotForm.password = ""
  150. this.forgotForm.confirmPassword = ""
  151. this.timer = setInterval(() => {
  152. this.time--
  153. if (this.time == 0) {
  154. clearInterval(this.timer)
  155. }
  156. }, 1000)
  157. }
  158. }
  159. })
  160. }
  161. },
  162. }
  163. }
  164. </script>
  165. <style>
  166. /* #ifndef APP-NVUE */
  167. view {
  168. display: flex;
  169. box-sizing: border-box;
  170. flex-direction: column;
  171. }
  172. page {
  173. box-sizing: border-box;
  174. padding: 0 48rpx 80rpx;
  175. height: 100%;
  176. }
  177. /* #endif*/
  178. </style>
  179. <style lang="scss" scoped>
  180. @import '../../common/css/login.scss';
  181. </style>