lxf
2025-04-28 a3ae2f2efa0f1f90908fb29fe6362429ac34509d
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
<template>
  <div class="wrapper">
    <div class="header">
      <mt-header title="忘记密码">
        <router-link to="/login" slot="left">
          <mt-button icon="back"></mt-button>
        </router-link>
      </mt-header>
    </div>
    <div class="form-group">
      <div class="title">
        输入您的手机号
      </div>
      <div class="page-part">
        <mt-field label="+86" type="tel" placeholder="请输入手机号" v-model="phone"></mt-field>
        <mt-field label="获取验证码" type="number" placeholder="输入验证码" v-model="code">
          <span v-if="codeshow" class="getcode" @click="checkCodeBox">获取验证码</span>
          <span v-if="!codeshow" class="getcode">{{count}}s</span>
        </mt-field>
        <mt-field label="输入密码" placeholder="请输入密码" type="password" v-model="password"></mt-field>
        <mt-field label="输入密码" placeholder="确认您输入的密码" type="password" v-model="password2"></mt-field>
      </div>
    </div>
    <div class="btnbox">
      <span class="text-center btnok" @click="gook">确定</span>
    </div>
    <mt-popup v-model="dialogShow" :closeOnClickModal="false" class="mint-popup-box mint-popup-white">
      <div class="clearfix">
        <a @click="dialogShow = false" class="pull-right"><i class="iconfont icon-weitongguo"></i></a>
      </div>
      <div class="">
        <div class="check-box row">
          <div class="title">
            输入图片上的验证码
          </div>
          <mt-field label="验证码" placeholder="请输入验证码" v-model="code2">
            <img @click="refreshImg" :src="adminUrl+'/code/getCode.do?time=' + imgCodeTime" height="45px" width="100px">
          </mt-field>
          <p class="red" v-if="!checkCodeState">您输入的验证码有误,请重新输入</p>
          <div class="text-center" style="width: 100%; padding: 0.2rem;">
            <mt-button type="primary" @click="checkImg">确定</mt-button>
            <!-- <mt-button style="margin-left: 10%;width:22%" type="default" @click="dialogShow = false">返回</mt-button> -->
          </div>
        </div>
      </div>
    </mt-popup>
  </div>
</template>
 
<script>
import { Toast } from 'mint-ui'
import { isNull, isPhone } from '@/utils/utils'
import * as api from '@/axios/api'
 
export default {
  components: {},
  props: {},
  data () {
    return {
      phone: '',
      password: '',
      password2: '',
      code: '',
      code2: '',
      codeshow: true,
      count: '', // 倒计时
      clickFalg: 0, //  点击次数
      imgCode: '',
      adminUrl: '',
      dialogShow: false, // 显示弹窗
      ischeckImg: false,
      checkCodeState: true, // 验证码的状态
      dialogImgShow: false, // 图片显示
      imgCodeTime: 0
    }
  },
  watch: {
    code2 (newval) {
      if (newval) {
        this.checkCodeState = true
      }
    }
  },
  computed: {},
  methods: {
    checkCodeBox () {
      if (isNull(this.phone) || !isPhone(this.phone)) {
        Toast('请输入正确的手机号')
      } else {
        this.checkPhone()
      }
    },
    async checkCode () {
      let data = await api.checkCode({ code: this.code2 })
      this.ischeckImg = data
    },
    async checkImg () {
      if (!this.code2) {
        this.checkCodeState = false
        Toast('您输入的验证码有误,请重新输入')
        return
      }
      // await this.checkCode()
      let data = await api.checkCode({ code: this.code2 })
      if (data === 'true' || data === true) {
        this.getcode()
        this.dialogShow = false
        this.checkCodeState = true
      } else {
        this.checkCodeState = false
        Toast('您输入的验证码有误,请重新输入')
        this.adminUrl = process.env.API_HOST + '1'
        this.adminUrl = process.env.API_HOST
        if (this.adminUrl === undefined) {
          this.adminUrl = ''
        }
      }
    },
    async getcode () {
      if (this.clickFalg !== 0) {
        this.clickFalg = 0
        return
      }
      this.clickFalg++
      // var reg = 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/
      let reg = /^[0-9]{11}$/ // 手机号码验证
      if (isNull(this.phone)) {
        Toast('手机号不可为空')
      } else {
        if (!reg.test(this.phone)) {
          Toast('请输入正确的手机号码')
        } else {
          let result = await api.sendForgetSms({ phoneNum: this.phone })
          if (result.status === 0) {
            const TIME_COUNT = 60
            if (!this.timer) {
              this.count = TIME_COUNT
              this.codeshow = false
              this.clickFalg = 0
              this.timer = setInterval(() => {
                if (this.count > 0 && this.count <= TIME_COUNT) {
                  this.count--
                } else {
                  this.codeshow = true
                  clearInterval(this.timer)
                  this.timer = null
                }
              }, 1000)
            } else {
              Toast(result.msg)
            }
          }
        }
      }
    },
    async checkPhone () {
      // 先验证是否已经注册
      let data = await api.checkPhone({ phoneNum: this.phone })
      if (data.status === 0) {
        // 如果用户已存在返回 0
        this.dialogShow = true
        this.adminUrl = process.env.API_HOST
        if (this.adminUrl === undefined) {
          this.adminUrl = ''
        }
        // this.gook()
      } else {
        Toast('用户还未注册,请注册')
        this.$router.push('/register')
      }
    },
    async gook () {
      if (isNull(this.phone) || !isPhone(this.phone)) {
        Toast('请输入正确的手机号码')
      } else if (isNull(this.password)) {
        Toast('请输入密码')
      } else if (isNull(this.password2)) {
        Toast('请确认密码')
      } else if (isNull(this.code)) {
        Toast('请输入验证码')
      } else if (this.password !== this.password2) {
        Toast('两次输入的密码不一致')
        this.password = 0
        this.password2 = 0
      } else {
        let opts = {
          phoneNum: this.phone,
          code: this.code,
          newPwd: this.password
        }
        let data = await api.forgetPas(opts)
        if (data.status === 0) {
          Toast('修改成功,请登录!')
          this.$router.push('/login')
        } else {
          Toast(data.msg ? data.msg : '修改失败,请重新修改')
        }
      }
    },
    refreshImg () {
      this.adminUrl = ''
      this.imgCodeTime = Date.now()
      this.dialogImgShow = false
      let this_ = this
      setTimeout(function () {
        this_.adminUrl = process.env.API_HOST
        if (this_.adminUrl === undefined) {
          this_.adminUrl = ''
        }
        this_.dialogImgShow = true
      }, 500)
    }
  },
  created () {},
  mounted () {}
}
</script>
<style lang="less" scoped>
  body {
    background-color: #fff;
  }
 
  body /deep/ .mint-toast {
    z-index: 1000000;
  }
 
  .form-group {
    padding: 0rem 0.97rem;
    font-size: 0.29rem;
 
    .title {
      font-size: 0.43rem;
      margin-bottom: 0.34rem;
      margin-top: 1.40rem;
    }
 
    .mint-cell {
      padding: 0;
    }
 
    /deep/ .mint-cell-title {
      text-align: left;
    }
 
    /deep/ .mint-cell-wrapper {
      height: 1.19rem;
      line-height: 1.19rem;
    }
  }
 
  .btnbox {
    width: 35%;
    padding-top: 0.28rem;
  }
 
  .mint-popup-box {
    // width: 100%;
    // height: 100%;
    // background:#fff;
    .title {
      font-size: 0.43rem;
      margin-bottom: 0.34rem;
      // margin-top: 1.40rem;
      padding: 0.1rem 0.4rem;
      color: #333;
    }
 
    .mint-cell {
      background: none;
      color: #000;
      width: 100%;
    }
 
    /deep/ .mint-cell-text {
      color: #000;
    }
 
    .mint-cell-wrapper {
      border: 0.02rem solid #ddd;
    }
 
    .mint-button {
      margin-top: 0.2rem;
      width: 60%;
    }
 
    .check-box {
      p {
        padding: 0.2rem 0.4rem;
      }
 
      padding-bottom: 0.3rem;
    }
  }
</style>