<script>
export default {
data () {
return {
formLabelWidth:‘120px‘,
logining: false,
sendAuthCode:true, //布尔值,通过v-show控制显示‘获取按钮’还是‘倒计时’
auth_time: 0, //倒计时 计数器
verification:"", //绑定输入验证码框框
modeflyForm: {
tel: ‘‘,
user: ‘‘,
newPass: ‘‘,
verifly:‘‘
},
rules: {
tel: [
{ required: true, message: ‘请输入手机号‘, trigger: ‘blur‘ }
],
user: [
{ required: true, message: ‘请输入用户名‘, trigger: ‘blur‘ }
],
newPass: [
{ required: true, message: ‘请输入新密码‘, trigger: ‘blur‘ },
{validator:newPassBox,trigger:‘blur‘}
],
verifly: [
{ required: true, message: ‘请输入验证码‘, trigger: ‘blur‘ },
{validator:veriflyBox,trigger:‘blur‘}
]
}
}
// 设置新密码的正则
let newPassBox = (rules,value,callback)=>{
let reg=/^[\w]{6,18}$/
if(!reg.test(value)){callback(new Error(‘密码格式不正确,请输入6-18位的数字或字母‘))
}else{
callback()
}
}
// 验证码正则
let veriflyBox = (rules,value,callback)=>{
console.log("启用正则")
let reg=/[0-9]{6}/
if(!reg.test(value)){callback(new Error(‘验证码格式不正确,请输入6位的数字‘))
}else{
callback()
}
}
},
methods: {
// 检查手机号格式
checkTel(){
let TEL_REGEXP = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/
let tel = this.modeflyForm.tel
if(TEL_REGEXP.test(tel)){
this.getAuthCode()
}else{
// 格式不正确
this.$message("手机号格式不正确,请输入正确手机号")
return true
}
},
//获取验证码
getAuthCode() {
// 手机号格式正确发请求
let param = {mobile: this.modeflyForm.tel, type: ‘1‘}
this.$api.sys.getSmsCode(param).then(data=> {
console.log(data)
this.modeflyForm.verifly = data.msCode
})
//const verification =this.modeflyForm.tel;
//获取验证码请求
this.sendAuthCode = false;
//设置倒计时秒
this.auth_time = 60
var auth_timetimer = setInterval(()=>{
this.auth_time--
if(this.auth_time<=0){
this.sendAuthCode = true
clearInterval(auth_timetimer)
}
}, 1000)
},
submit(){
let isNull = this.modeflyForm.tel == ‘‘ || this.modeflyForm.user == ‘‘ || this.modeflyForm.newPass == ‘‘ || this.modeflyForm.verifly == ‘‘
if(!isNull){
//veriflyBox()
// 后台验证修改
// param: {mobile: ‘手机号码‘, type: 类型(1:找回密码), smsCode: ‘验证码‘}
let param = {mobile: this.modeflyForm.tel, type: ‘1‘, smsCode: this.modeflyForm.verifly}
this.$api.sys.checkSmsCode(param).then(data=> {
if(data.retCode == 0){
this.modoflyPass()
}
})
}else{
this.$message("手机号,用户名,密码,验证码不能为空!")
}
},
modoflyPass(){
// 修改请求
console.log(‘修改‘)
let param = {loginName:this.modeflyForm.user , password: this.modeflyForm.newPass, mobile: this.modeflyForm.tel}
this.$api.user.forgotPassword(param).then(data=> {
console.log(data)
if(data.retCode == 0){
this.$message("恭喜您。新密码设置成功!")
}else{
this.$message("修改失败,请重试!")
}
})
},
closeBox(){
}
}
}
</script>