forget_pwd.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class="forget-pwd bg-white">
  3. <view class="input-container">
  4. <view class="input-item flex">
  5. <view class="input-label flex normal">手机号</view>
  6. <u-input v-model="mobile" class="input" placeholder="请输入手机号码" />
  7. </view>
  8. <view class="input-item flex">
  9. <view class="input-label flex normal">短信验证码</view>
  10. <u-input v-model="smsCode" style="width: 300rpx" placeholder="请输入验证码" />
  11. <button class="bd-primary xs primary br60 flex row-center" @click="sendSmsFun">
  12. <!-- 获取验证码 -->
  13. <u-verification-code unique-key="forget-pwd" ref="uCode" @change="codeChange">
  14. </u-verification-code>
  15. <view class="xs">{{codeTips}}</view>
  16. </button>
  17. </view>
  18. <view class="input-item flex">
  19. <view class="input-label flex normal">重置密码</view>
  20. <u-input type="password" v-model="resetPwd" placeholder="6-20位数字+字母或符号组合" />
  21. </view>
  22. <view class="input-item flex">
  23. <view class="input-label flex normal">确认密码</view>
  24. <u-input type="password" v-model="comfirmPwd" placeholder="请再次输入密码" />
  25. </view>
  26. </view>
  27. <view class="btn white bg-primary br60 flex row-center" @click="forgetPwdFun">
  28. 确认
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. forgetPwd,
  35. sendSms
  36. } from '@/api/app.js'
  37. import {
  38. ACCESS_TOKEN
  39. } from '@/config/app.js'
  40. import {
  41. SMSType
  42. } from '@/utils/type.js'
  43. import {
  44. mapMutations
  45. } from 'vuex'
  46. export default {
  47. name: 'forgetPwd',
  48. data() {
  49. return {
  50. mobile: '',
  51. smsCode: '',
  52. resetPwd: '',
  53. comfirmPwd: '',
  54. time: 59,
  55. codeTips: '',
  56. }
  57. },
  58. onLoad() {
  59. },
  60. methods: {
  61. ...mapMutations(['login']),
  62. codeChange(tip) {
  63. this.codeTips = tip
  64. },
  65. forgetPwdFun() {
  66. let {
  67. mobile,
  68. smsCode,
  69. resetPwd,
  70. comfirmPwd
  71. } = this;
  72. if (!mobile) {
  73. this.$toast({
  74. title: '请填写手机号'
  75. });
  76. return;
  77. }
  78. if (!smsCode) {
  79. this.$toast({
  80. title: '请填写短信验证码'
  81. });
  82. return;
  83. }
  84. if (!resetPwd) {
  85. this.$toast({
  86. title: '请填写重置密码'
  87. });
  88. return;
  89. }
  90. if (!comfirmPwd) {
  91. this.$toast({
  92. title: '请填写确认密码'
  93. });
  94. return;
  95. }
  96. if (resetPwd != comfirmPwd) {
  97. this.$toast({
  98. title: '两次密码输入不一致'
  99. });
  100. return;
  101. }
  102. let data = {
  103. mobile: mobile,
  104. code: smsCode,
  105. password: resetPwd,
  106. repassword: comfirmPwd
  107. };
  108. forgetPwd(data).then(res => {
  109. if (res.code == 1) {
  110. this.login(data);
  111. this.$toast({
  112. title: res.msg
  113. });
  114. // 跳转到登录页
  115. setTimeout(() => {
  116. uni.navigateBack()
  117. }, 1000)
  118. }
  119. })
  120. },
  121. sendSmsFun() {
  122. if(!this.$refs.uCode.canGetCode) return
  123. if (!this.mobile) {
  124. this.$toast({
  125. title: '请填写手机号信息'
  126. })
  127. return;
  128. }
  129. sendSms({
  130. mobile: this.mobile,
  131. key: SMSType.FINDPWD
  132. }).then(res => {
  133. if (res.code == 1) {
  134. this.$toast({title:res.msg});
  135. this.$refs.uCode.start();
  136. }
  137. })
  138. }
  139. },
  140. }
  141. </script>
  142. <style lang="scss">
  143. page {
  144. padding: 0;
  145. }
  146. .forget-pwd {
  147. min-height: 100vh;
  148. padding: 40px 20px 0;
  149. padding: 80rpx 40rpx 0;
  150. .input-container {
  151. .input-item {
  152. padding: 0 20rpx;
  153. height: 88rpx;
  154. margin-bottom: 30rpx;
  155. border-bottom: 1px solid #D7D7D7;
  156. .input-label {
  157. width: 180rpx;
  158. flex: none;
  159. }
  160. .bd-primary {
  161. height: 56rpx;
  162. width: 176rpx;
  163. flex: none;
  164. border: 1px solid $-color-primary;
  165. .seconds {
  166. color: $-color-primary;
  167. }
  168. }
  169. }
  170. }
  171. .btn {
  172. margin-top: 60rpx;
  173. padding: 20rpx 0;
  174. }
  175. }
  176. </style>