ZZJ
2022-04-02 45faaf27722588e92050e2e3eace9b3704377048
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<template>
  <div class="ResetPassword">
    <!-- 重置表格 -->
    <div class="resetForm" v-if="!isReseted">
      <div class="formHeart">
        <div class="title">重置密码</div>
        <el-form
          :model="formData"
          :rules="baseInforule"
          :validate-on-rule-change="false"
          ref="resetForm"
          class="demo-rulmargin"
        >
          <el-form-item prop="phoneNum">
            <div class="phoneNum">
              <el-input
                placeholder="请输入注册手机号"
                v-model="formData.phoneNum"
                class="input-with-select"
              >
              </el-input>
              <div class="iconfont">&#xe602;</div>
            </div>
          </el-form-item>
 
          <el-form-item prop="verifyCode">
            <el-input
              v-model="formData.verifyCode"
              readonly
              onfocus="this.removeAttribute('readonly');"
              onblur="this.setAttribute('readonly',true);"
              autocomplete="off"
              placeholder="请输入验证码"
            >
            </el-input>
            <el-button
              class="code-btn"
              :disabled="codeDisabled"
              @click="getCode"
              >{{ codeMsg }}</el-button
            >
            <div class="iconfont">&#xe604;</div>
          </el-form-item>
 
          <el-form-item prop="password">
            <el-input
              show-password
              v-model="formData.password"
              placeholder="请设置6-14位登录密码"
            >
            </el-input>
            <div class="iconfont">&#xe608;</div>
          </el-form-item>
 
          <el-form-item prop="repassword">
            <el-input
              show-password
              v-model="formData.repassword"
              placeholder="确认密码"
            >
            </el-input>
            <div class="iconfont">&#xe608;</div>
          </el-form-item>
 
          <div>
            <div
              class="button submit"
              :class="{ disabled: btnDisabled }"
              @click="submit"
            >
              提交
            </div>
          </div>
        </el-form>
      </div>
    </div>
 
    <!-- 重置成功 -->
    <div class="successBox" v-else>
      <div class="title">
        <span class="iconfont">&#xe605;</span>
        重置密码成功
      </div>
      <div class="des">请妥善保管您的账户信息</div>
      <router-link to="/login">
        <div class="button">重新登录</div>
      </router-link>
    </div>
  </div>
</template>
 
<script>
import { getVerifyCode, forgetPwd } from "@/api/login";
import { isPhone, validPassword } from "@/scripts/validate"; // 正则文件
 
export default {
  data() {
    //密码校验
    let validatePassword = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请设置密码!"));
      } else {
        let result = validPassword(value);
        if (result) {
          callback();
        } else {
          callback(
            new Error(
              "请输入6到14位字符,字母/数字以及标点符号至少包含2种组成的"
            )
          );
        }
      }
    };
    //确认密码校验
    let validateRePassword = (rule, value, callback) => {
      if (value === this.formData.password) {
        callback();
      } else {
        callback(new Error("两次输入的密码不一致,请重新输入"));
      }
    };
    return {
      isReseted: false, //是否重置成功
      formData: {
        phoneNum: "",
        verifyCode: "",
        password: "",
        repassword: "",
      }, //表格数据
      baseInforule: {
        password: [{ validator: validatePassword, trigger: "change" }],
        repassword: [{ validator: validateRePassword, trigger: "change" }],
        phoneNum: [{ validator: isPhone, trigger: "change" }],
        verifyCode: [
          { required: true, message: "请输入验证码", trigger: "change" },
        ],
      }, //正则规则
      codeDisabled: false, //验证码按钮锁定
      codeMsg: "获取验证码", //验证码按钮文字
      countdown: 60, //验证码冷却时间
    };
  },
  methods: {
    //获取按钮显示信息
    getValidStr() {
      if (this.countdown > 0 && this.countdown <= 60) {
        this.countdown--;
        if (this.countdown !== 0) {
          this.codeMsg = `${this.countdown}s`;
        } else {
          clearInterval(this.timer);
          this.codeMsg = "获取验证码";
          this.countdown = 60;
          this.timer = null;
          this.codeDisabled = false;
        }
      }
    },
    //获取验证码
    getCode() {
      this.$refs["resetForm"].validateField("phoneNum", (res) => {
        if (res) {
          document.querySelector(".phoneNum .el-input__inner").focus();
        }
        if (!res) {
          if (!this.timer) {
            this.codeDisabled = true;
            this.getValidStr();
            this.timer = setInterval(this.getValidStr, 1000);
            getVerifyCode({ phoneNum: this.formData.phoneNum, type: 1 })
              .then(() => {
                this.gotCode = true;
              })
              .catch((err) => {
                if (err.data) {
                  console.log(err);
                }
              });
          }
        }
      });
    },
    async submit() {
      const res = await forgetPwd({
        phoneNum: this.formData.phoneNum,
        newPwd: this.formData.password,
      });
      if (res && res.success) {
        this.$notify({
          type: "success",
          message: "重置成功",
        });
      }
      this.isReseted = true;
    },
  },
  computed: {
    //控制提交按钮disable
    btnDisabled() {
      let disabled = false;
      for (const key in this.formData) {
        if (!this.formData[key]) {
          disabled = true;
        }
      }
      return disabled;
    },
  },
};
</script>
 
<style scoped lang="scss" >
.resetForm {
  margin-top: 193px;
  width: 660px;
  height: 570px;
  background-color: #fff;
  text-align: center;
 
  .formHeart {
    overflow: hidden;
    margin: 0 auto;
    width: 456px;
 
    .title {
      margin-top: 30px;
      margin-bottom: 50px;
      font-size: 24px;
    }
 
    .el-form-item {
      margin-bottom: 30px;
      position: relative;
 
      ::v-deep .el-input__inner {
        height: 48px;
        padding: 10px 20px;
        padding-left: 64px;
        border-color: #c0c5cc;
 
        &::-webkit-input-placeholder {
          font-size: 14px;
          color: #999;
        }
      }
 
      &.is-error ::v-deep .el-input__inner:focus {
        border-color: #ff4b33;
      }
 
      .code-btn {
        box-sizing: border-box;
        width: 101px;
        height: 30px;
        position: absolute;
        top: 9px;
        right: 20px;
        padding: 4px 0;
        padding-left: 20px;
        border: none;
        border-left: 1px solid #c0c5cc;
        border-radius: 0;
 
        font-size: 16px;
        line-height: 22px;
 
        color: #0065ff;
 
        &:hover {
          background-color: #fff;
        }
 
        &.is-disabled {
          color: #999999;
        }
      }
 
      .iconfont {
        position: absolute;
        top: 4px;
        left: 20px;
        font-size: 24px;
        color: #c0c5cc;
      }
    }
 
    .submit {
      margin-top: 60px;
      width: 456px;
      height: 48px;
      border-radius: 4px;
      background: #0065ff;
      color: #fff;
      font-size: 16px;
      font-weight: 700;
      line-height: 48px;
      &.disabled {
        background: rgba(0, 101, 255, 0.5);
      }
    }
  }
}
 
.successBox {
  overflow: hidden;
  margin-top: 253px;
  height: 450px;
  width: 660px;
  background: #ffffff;
  text-align: center;
 
  .title {
    margin-top: 90px;
    margin-bottom: 40px;
    font-size: 28px;
    span {
      vertical-align: middle;
      color: rgb(54, 178, 74);
      margin-right: 20px;
      font-size: 48px;
    }
  }
  .des {
    margin-bottom: 102px;
    font-size: 14px;
  }
 
  .button {
    width: 200px;
    height: 48px;
    margin: 0 auto;
 
    background: #0065ff;
    color: #fff;
    border-radius: 4px;
    font-size: 16px;
    line-height: 48px;
  }
}
</style>