ZZJ
2022-06-01 f3bf27d9bc7c8c6484be4f37edcc57df5490ecbe
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
<template>
  <div class="bg-gray">
    <header class="header-transparent">
      <div class="logo">
        <img src="../assets/img/top-logo.png" alt />
      </div>
      <div class="text-right">
        <el-link class="toIndex cursor-pointer" href="http://smartai.com/" target="_blank">
          <span>返回首页</span>
        </el-link>
        <el-link class="cursor-pointer" href="http://smartai.com/" target="_blank">
          <!-- <router-link to="/Register">
            <span style="color:white;height:20px;">注册</span>
          </router-link>-->
        </el-link>
        <span class="devide">|</span>
        <el-link class="qrcode cursor-pointer" href="http://smartai.com/" target="_blank">
          <img src="../assets/img/u132.png" />
        </el-link>
      </div>
    </header>
    <content>
      <div class="forgetPassword">
        <h1 class="welcome">找回密码</h1>
        <el-steps class="arrowToLine" :active="active" finish-status="success" align-center simple>
          <el-step title="手机验证" class="step-num-one"></el-step>
          <el-step title="重置密码" class="step-num-two"></el-step>
          <el-step title="重置成功" class="step-num-three"></el-step>
        </el-steps>
        <div class="box1" v-show="step1">
          <el-form :model="phone" ref="phone" :rules="phoneCodeRule">
            <el-form-item prop="phoneNum">
              <el-input v-model="phone.phoneNum" placeholder="请输入手机号">
                <i slot="prefix" class="el-icon-mobile-phone" style="margin-top:15px"></i>
              </el-input>
            </el-form-item>
            <el-form-item prop="verifyCode">
              <el-input v-model="phone.verifyCode" placeholder="请输入验证码" style="width: 254px;">
                <i slot="prefix" class="el-icon-message" style="margin-top:15px"></i>
              </el-input>
              <el-button class="code-btn" :disabled="codeDisabled" @click="getCode('phone')">{{ codeMsg }}</el-button>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" style="width:380px;margin-top:10px;" @click="verifiPhone('phone')"
                >下一步</el-button
              >
            </el-form-item>
          </el-form>
        </div>
 
        <div class="box1" v-show="step2">
          <div class="el-form-item">
            <el-input v-model="newPassword" placeholder="输入新密码"></el-input>
          </div>
          <div class="el-form-item">
            <el-input v-model="passwordAgain" placeholder="再次输入密码"></el-input>
          </div>
          <el-button type="primary" style="width:380px;margin-top:10px;" @click="resetPassword()">下一步</el-button>
        </div>
 
        <div class="box1" v-show="step3">
          <p class="success-tip">密码设置成功</p>
          <el-button type="primary" style="width:334px;" @click="resetSuccess()">立即登录</el-button>
          <div class="link-tip">
            <span style="color:#EA1E24">{{ time }}s</span>后自动跳转登录页
          </div>
        </div>
      </div>
    </content>
  </div>
</template>
 
<script>
import { getVerifyCode, verifyPh, forgetPwd } from "@/api/login"
import { isPhone } from "@/scripts/validate"
export default {
  data() {
    return {
      active: -1,
 
      step1: true,
      step2: false,
      step3: false,
      phone: {
        phoneNum: "",
        verifyCode: ""
      },
      //gotCode: false,
      codeMsg: "获取验证码",
      countdown: 60,
      codeDisabled: false,
      phoneCodeRule: {
        phoneNum: [{ validator: isPhone, trigger: "change" }],
        verifyCode: [{ required: true, message: "请输入验证码", trigger: "change" }]
      },
      time: 5,
      newPassword: "",
      passwordAgain: ""
    }
  },
  mounted() {
    this.next()
  },
  watch: {
    time: function(newValue, oldValue) {
      console("当前倒计时", this.time)
      if (newValue == 0) {
        this.$router.push("/")
      }
    }
  },
  methods: {
    getValidStr() {
      if (this.countdown > 0 && this.countdown <= 60) {
        this.countdown--
        if (this.countdown !== 0) {
          this.codeMsg = "重新发送(" + this.countdown + ")"
        } else {
          clearInterval(this.timer)
          this.codeMsg = "获取验证码"
          this.countdown = 60
          this.timer = null
          this.codeDisabled = false
        }
      }
    },
    // 获取验证码
    getCode(formName) {
      // 验证码60秒倒计时
      var pattern = /^1[345789]\d{9}$/
      if (this.phone.phoneNum == "") {
        this.$refs[formName].fields[0].validateMessage = "请输入手机号"
        this.$refs[formName].fields[0].validateState = "error"
        return
      }
      if (!pattern.test(this.phone.phoneNum)) {
        this.$refs[formName].fields[0].validateMessage = "手机号码格式有误"
        this.$refs[formName].fields[0].validateState = "error"
        return
      }
      if (!this.timer) {
        this.codeDisabled = true
        this.getValidStr()
        this.timer = setInterval(this.getValidStr, 1000)
        getVerifyCode({ phoneNum: this.phone.phoneNum })
          .then((res) => {
            //this.gotCode = true;
          })
          .catch((err) => {
            this.$refs[formName].fields[0].validateMessage = err.data.msg
            this.$refs[formName].fields[0].validateState = "error"
          })
      }
    },
    verifiPhone(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)"
          })
          verifyPh({
            phoneNum: this.phone.phoneNum,
            verifyCode: this.phone.verifyCode
          })
            .then((res) => {
              this.loading.close()
              this.next()
            })
            .catch((err) => {
              this.loading.close()
              if (err && err.status == 401) {
                return
              }
              this.$notify({
                type: "error",
                message: err.msg || err.data.msg,
                duration: 2500,
                offset: 57
              })
            })
        } else {
          return
        }
      })
    },
    resetPassword() {
      // 校验两次密码输入是否一致
      if (this.newPassword == this.passwordAgain) {
        this.loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)"
        })
        forgetPwd({ phoneNum: this.phone.phoneNum, newPwd: this.newPassword })
          .then((res) => {
            this.$notify({
              type: "success",
              message: "重置新密码成功",
              duration: 2500,
              offset: 57
            })
            this.loading.close()
            setInterval(() => {
              this.time--
              if (this.time == 0) {
                //this.forgetPassword = false;
                this.$router.push("/")
              }
            }, 1000)
            this.next()
          })
          .catch((err) => {
            if (err && err.status == 401) {
              return
            }
            this.$notify({
              type: "error",
              message: "重置新密码失败,请重试",
              duration: 2500,
              offset: 57
            })
            this.loading.close()
          })
      } else {
        this.$notify({
          type: "error",
          message: "两次密码输入请保持一致",
          duration: 2500,
          offset: 57
        })
      }
    },
    next() {
      this.active++
      console.log("当前active:", this.active)
      switch (this.active) {
        case 0:
          this.step1 = true
          this.step2 = false
          this.step3 = false
          break
        case 1:
          this.step1 = false
          this.step2 = true
          this.step3 = false
          break
        case 2:
          this.step1 = false
          this.step2 = false
          this.step3 = true
          break
      }
    }
  }
}
</script>
 
<style lang="scss">
content {
  .el-input__inner:focus {
    border-color: #888 !important;
  }
  .welcome {
    padding-top: 40px;
    height: 25px;
    margin-bottom: 50px;
    font-size: 25px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: bold;
    color: #222222;
    line-height: 25px;
  }
  .forgetPassword {
    width: 900px;
    height: 567px;
    margin: 138px auto 0;
    background: #ffffff;
    .arrowToLine {
      margin: 0 0 50px 138px;
      padding: 0;
    }
    .arrowToLine .el-step.is-simple .el-step__head .el-step__icon {
      width: 26px;
      height: 26px;
    }
    .arrowToLine .el-step.is-simple .el-step__title {
      font-size: 16px;
      width: 64px;
    }
    .arrowToLine .el-step.is-simple .el-step__head .el-step__icon:after {
      font-size: 16px;
    }
    .arrowToLine .el-step.is-simple .el-step__arrow::after {
      width: 140px;
      background: #ddd;
    }
    .code-btn {
      margin-left: 10px;
      width: 116px;
      height: 40px;
      border: none;
      color: #ea1e24;
      background: rgba(234, 30, 36, 0.04);
      &.is-disabled {
        background: #eee;
        border-color: #eee;
        color: #888;
      }
    }
    .success-tip {
      margin: 50px auto;
      height: 22px;
      font-size: 22px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #111111;
      line-height: 22px;
    }
    .link-tip {
      height: 14px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #555;
      line-height: 14px;
      margin-top: 20px;
    }
    .box1 {
      width: 380px;
      margin: auto;
    }
  }
}
</style>