restPassword.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="container">
  3. <view class="wrapper">
  4. <view class="input-content">
  5. <view class="input-item" v-if="step === 0">
  6. <view class="input-item-title">
  7. <image src="/static/login/user.png"></image>
  8. </view>
  9. <input type="text" v-model="form.account" placeholder="请输入账户名" placeholder-class="input-empty" maxlength="11"
  10. />
  11. </view>
  12. <view class="input-item" v-if="step === 0">
  13. <view class="input-item-title">
  14. <image class="img-code-icon" src="/static/login/code.png"></image>
  15. </view>
  16. <input v-model="form.img_code" placeholder="请输入图片验证码" placeholder-class="input-empty" maxlength="4"
  17. @confirm="toLogin" />
  18. <image :src="validate_url" class="img_code" mode="" @click="getValidImgUrl"></image>
  19. </view>
  20. <view class="input-item" v-if="step === 1">
  21. <view class="input-item-title">
  22. <image src="/static/login/user.png"></image>
  23. <view class="phone-number">+86</view>
  24. <image class="vertical" src="/static/vertical-line.svg"></image>
  25. </view>
  26. <input type="mobile" v-model="form.mobile" disabled="true" placeholder="请输入手机号码" placeholder-class="input-empty" maxlength="11"
  27. />
  28. </view>
  29. <view class="input-item" v-if="step === 1">
  30. <view class="input-item-title">
  31. <image class="img-code-icon" src="/static/login/code.png"></image>
  32. </view>
  33. <input v-model="form.img_code_phone" placeholder="请输入图片验证码" placeholder-class="input-empty"
  34. maxlength="4" @confirm="toLogin" />
  35. <image :src="validate_url" class="img_code" mode="" @click="getValidImgUrl"></image>
  36. </view>
  37. <view class="input-item" v-if="step === 1">
  38. <view class="input-item-title">
  39. <image src="/static/login/pwd2.png"></image>
  40. </view>
  41. <input v-model="form.sms_code" placeholder="请输入验证码" placeholder-class="input-empty" maxlength="4"
  42. @confirm="toLogin" />
  43. <view class="get-captcha" @click="handleGetCapcha">{{ sendTime === 0 ? '获取验证码' : sendTime + 's后重新获取' }}</view>
  44. </view>
  45. <view class="input-item" v-if="step === 2">
  46. <view class="input-item-title">
  47. <image src="/static/login/pwd2.png"></image>
  48. </view>
  49. <input type="password" v-model="form.password" placeholder="请输入新密码" placeholder-class="input-empty" maxlength="20"
  50. @confirm="toLogin" />
  51. </view>
  52. <view class="input-item" v-if="step === 2">
  53. <view class="input-item-title">
  54. <image src="/static/login/pwd2.png"></image>
  55. </view>
  56. <input type="password" v-model="form.rep_password" placeholder="请再次输入密码" placeholder-class="input-empty" maxlength="20"
  57. @confirm="toLogin" />
  58. </view>
  59. <button class="confirm-btn" @click="toNext">{{ step === 0 ? '验证账号' : (step==1?'下一步':'确定') }}</button>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. validAccount,
  67. sendFindPasswordSms,
  68. validFindPasswordSms,
  69. changePassword
  70. } from '@/api/passport.js';
  71. import {
  72. getValidateCodeUrl
  73. } from '@/api/common.js';
  74. import * as RegExp from '@/utils/RegExp.js';
  75. export default {
  76. data() {
  77. return {
  78. validate_url: '',
  79. sendTime: 0,
  80. form: {},
  81. step: 0,
  82. }
  83. },
  84. onLoad() {
  85. this.$nextTick(this.getValidImgUrl)
  86. },
  87. methods: {
  88. handleGetCapcha() {
  89. if (this.sendTime == 0) {
  90. sendFindPasswordSms(this.form.uuid,this.form.img_code_phone).then(res => { //发送验证码
  91. if (res.statusCode == 200) {
  92. this.sendTime = 60;
  93. let timer = setInterval(() => {
  94. this.sendTime--;
  95. if (this.sendTime === 0) {
  96. clearInterval(timer);
  97. }
  98. }, 1000);
  99. }
  100. })
  101. }
  102. },
  103. getValidImgUrl() { //获取图片验证码
  104. const uuid = this.step === 0 ? '' : this.form.uuid
  105. this.validate_url = getValidateCodeUrl('FIND_PASSWORD',uuid)
  106. },
  107. toNext() {
  108. // TODO 验证
  109. if (this.step === 0) {
  110. const { account,img_code } = this.form
  111. validAccount(img_code, account).then(res=>{
  112. if(res.statusCode==200){
  113. this.step = 1
  114. this.form.mobile = res.data.mobile
  115. this.form.uname = res.data.uname
  116. this.form.uuid = res.data.uuid
  117. this.getValidImgUrl()
  118. }
  119. });
  120. } else if (this.step == 1) {
  121. const { uuid, sms_code } = this.form
  122. validFindPasswordSms(uuid,sms_code).then((res) => {
  123. if(res.statusCode==200){
  124. this.step = 2;
  125. this.sendTime = 0;
  126. this.getValidImgUrl()
  127. }
  128. })
  129. }else{
  130. const { password,uuid,rep_password } = this.form
  131. if(!password){
  132. this.$api.msg('请输入密码')
  133. return;
  134. }
  135. if(!RegExp.password.test(password)){
  136. this.$api.msg('密码应为6-20位英文或数字!')
  137. return ;
  138. }
  139. if(password!=rep_password){
  140. this.$api.msg('两次输入密码不一致')
  141. return;
  142. }
  143. changePassword(password,uuid).then(res=>{
  144. if(res.statusCode==200){
  145. this.$api.msg('修改密码成功!')
  146. setTimeout(function() {
  147. uni.reLaunch({
  148. url:"/pages/passport/login"
  149. })
  150. }, 500);
  151. }
  152. })
  153. }
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. @import './login.scss';
  160. .container {
  161. padding-top: 0;
  162. .img_code {
  163. width: 140rpx;
  164. height: 48rpx;
  165. margin-right: 20rpx;
  166. }
  167. .img-code-icon {
  168. width: 44rpx;
  169. height: 35rpx;
  170. }
  171. .input-content {
  172. margin-top: 300rpx;
  173. }
  174. }
  175. </style>