xcx hace 4 años
padre
commit
a0d0672a1d
Se han modificado 4 ficheros con 177 adiciones y 2 borrados
  1. 110
    1
      src/pages/ResetPassword/index.vue
  2. 57
    0
      src/pages/ResetPassword/page.scss
  3. 5
    0
      src/store/user/index.js
  4. 5
    1
      src/util/Api.js

+ 110
- 1
src/pages/ResetPassword/index.vue Ver fichero

@@ -13,7 +13,36 @@
13 13
     <!-- 内容 -->
14 14
     <div class="MainBody flex-item">
15 15
       <div>
16
-
16
+        <div class="Form">
17
+          <div class="flex-h">
18
+            <span>手机号</span>
19
+            <div class="flex-item">
20
+              <input type="text" v-model="Phone" placeholder="请输入绑定手机号">
21
+            </div>
22
+          </div>
23
+          <div class="flex-h">
24
+            <span>验证码</span>
25
+            <div class="flex-item">
26
+              <input type="number" v-model="Code" placeholder="请输入手机验证码">
27
+            </div>
28
+            <a :class="{'active': Sec === 60}" @click="ToGetCode">{{Sec === 60 ? '获取验证码' : `${Sec > 9 ? Sec : `0${Sec}`}s后再次获取`}}</a>
29
+          </div>
30
+          <div class="flex-h">
31
+            <span>新密码</span>
32
+            <div class="flex-item">
33
+              <input type="password" v-model="Password" placeholder="请输入新密码">
34
+            </div>
35
+          </div>
36
+          <div class="flex-h">
37
+            <span>确认新密码</span>
38
+            <div class="flex-item">
39
+              <input type="password" v-model="PasswordAgain" placeholder="请再次输入新密码">
40
+            </div>
41
+          </div>
42
+          <div class="Btn">
43
+            <a @click="ToResetPassword">确认</a>
44
+          </div>
45
+        </div>
17 46
       </div>
18 47
     </div>
19 48
 
@@ -27,6 +56,13 @@ export default {
27 56
   name: '',
28 57
   data () {
29 58
     return {
59
+      Phone: '',
60
+      Code: '',
61
+      Password: '',
62
+      PasswordAgain: '',
63
+      DataLock: false,
64
+      Timer: null,
65
+      Sec: 60
30 66
     }
31 67
   },
32 68
   computed: {
@@ -41,8 +77,81 @@ export default {
41 77
   },
42 78
   methods: {
43 79
     ...mapUserActions([
80
+      'GetRegPhoneCode',
81
+      'CheckRegPhoneCode',
82
+      'ResetPassword'
44 83
     ]),
45 84
     Init () {
85
+    },
86
+    ToResetPassword () {
87
+      if (!this.IsPhone(this.Phone)) {
88
+        this.Toast('手机号格式错误')
89
+        return false
90
+      }
91
+      if (!this.IsPhone(this.Code === '')) {
92
+        this.Toast('请输入验证码')
93
+        return false
94
+      }
95
+      if (!this.IsPhone(this.Password === '')) {
96
+        this.Toast('请输入新密码')
97
+        return false
98
+      }
99
+      if (!this.IsPhone(this.PasswordAgain === '')) {
100
+        this.Toast('请确认新密码')
101
+        return false
102
+      }
103
+      if (!this.IsPhone(this.Password !== this.PasswordAgain)) {
104
+        this.Toast('两次密码输入不一致')
105
+        return false
106
+      }
107
+      if (this.DataLock) return
108
+      this.DataLock = true
109
+      this.ResetPassword({
110
+        data: {
111
+          captcha: this.Code,
112
+          password: this.Password,
113
+          phone: this.Phone
114
+        }
115
+      }).then(() => {
116
+        this.Toast('密码重置成功')
117
+        this.DataLock = false
118
+        window.setTimeout(() => {
119
+          this.$router.go(-1)
120
+        }, 1000)
121
+      }).catch((res) => {
122
+        this.Toast(res.data.message)
123
+        this.DataLock = false
124
+      })
125
+    },
126
+    IsPhone (str) { // 校验手机号
127
+      let myreg = /^[1][3,4,5,7,8][0-9]{9}$/
128
+      return !!myreg.test(str)
129
+    },
130
+    ToGetCode () {
131
+      if (!this.IsPhone(this.Phone)) {
132
+        this.Toast('手机号格式错误')
133
+        return false
134
+      }
135
+      if (this.Sec === 60 && !this.DataLock) {
136
+        this.DataLock = true
137
+        this.GetRegPhoneCode({ urlData: { phone: this.Phone } }).then(() => {
138
+          this.Toast('验证码已发送')
139
+          this.DataLock = false
140
+          window.clearInterval(this.Timer)
141
+          this.Sec -= 1
142
+          this.Timer = window.setInterval(() => {
143
+            if (this.Sec) {
144
+              this.Sec -= 1
145
+            } else {
146
+              this.Sec = 60
147
+              window.clearInterval(this.Timer)
148
+            }
149
+          }, 1000)
150
+        }).catch((res) => {
151
+          this.Toast(res.data.message)
152
+          this.DataLock = false
153
+        })
154
+      }
46 155
     }
47 156
   }
48 157
 }

+ 57
- 0
src/pages/ResetPassword/page.scss Ver fichero

@@ -52,6 +52,63 @@
52 52
       left: 0;
53 53
       top: 0;
54 54
       bottom: 0;
55
+      > .Form {
56
+        width: 100%;
57
+        height: 100%;
58
+        position: relative;
59
+        overflow-y: scroll;
60
+        -webkit-overflow-scrolling: touch;
61
+        > .flex-h {
62
+          align-items: center;
63
+          background: #fff;
64
+          padding: 0 0.15rem;
65
+          border-bottom: 0.01rem solid #f8f8f8;
66
+          > span {
67
+            min-width: 0.8rem;
68
+            font-size: 0.14rem;
69
+            color: #333;
70
+            line-height: 0.44rem;
71
+          }
72
+          > div {
73
+            position: relative;
74
+            overflow: hidden;
75
+            > input {
76
+              width: 100%;
77
+              display: block;
78
+              font-size: 0.14rem;
79
+              line-height: 0.4rem;
80
+              border: none;
81
+              color: #333;
82
+            }
83
+          }
84
+          > a {
85
+            font-size: 0.14rem;
86
+            color: #fff;
87
+            background: #ccc;
88
+            line-height: 0.3rem;
89
+            padding: 0 0.15rem;
90
+            border-radius: 0.04rem;
91
+            &.active {
92
+              background: #ff5100;
93
+            }
94
+          }
95
+        }
96
+        > .Btn {
97
+          padding: 0 0.15rem;
98
+          position: relative;
99
+          overflow: hidden;
100
+          margin-top: 0.15rem;
101
+          > a {
102
+            display: block;
103
+            font-size: 0.16rem;
104
+            color: #fff;
105
+            background: #ff5100;
106
+            text-align: center;
107
+            line-height: 0.4rem;
108
+            border-radius: 0.06rem;
109
+          }
110
+        }
111
+      }
55 112
     }
56 113
   }
57 114
 }

+ 5
- 0
src/store/user/index.js Ver fichero

@@ -121,6 +121,11 @@ export default {
121 121
     }
122 122
   },
123 123
   actions: {
124
+    ResetPassword (context, payload) { // 重置密码
125
+      return new Promise((resolve, reject) => {
126
+        ToolClass.Axios(resolve, reject, Api.ResetPassword, context, payload, 1000)
127
+      })
128
+    },
124 129
     EditPassword (context, payload) { // 修改密码
125 130
       return new Promise((resolve, reject) => {
126 131
         ToolClass.Axios(resolve, reject, Api.EditPassword, context, payload, 1000)

+ 5
- 1
src/util/Api.js Ver fichero

@@ -2,9 +2,13 @@
2 2
 const prefix = '/api'
3 3
 
4 4
 const $api = {
5
+  ResetPassword: { // 重置密码
6
+    method: 'put',
7
+    url: `${prefix}/app/reset-password`
8
+  },
5 9
   EditPassword: { // 修改密码
6 10
     method: 'put',
7
-    url: `${prefix}/app/resetpassword`
11
+    url: `${prefix}/app/change-password`
8 12
   },
9 13
   GetCurrentUserInfo: { // 获取当前用户信息
10 14
     method: 'get',