<template>
<div class="modifyPwd">
<!--<el-button type="primary" @click="dialogModifyVisible = true">修改密码 </el-button>-->
<!--<el-dialog :visible.sync="dialogModifyVisible" class="dialog" title="修改密码" width="610px">-->
<el-row>
<el-col :span="24">
<el-steps :active="active" finish-status="success" align-center>
<el-step title="验证身份" description=""/>
<el-step title="设置新密码" description=""/>
</el-steps>
</el-col>
</el-row>
<el-row v-show="active == 0" type="flex" class="row-bg" justify="center" style="margin: 20px">
<el-col :span="16">
<el-form ref="form1" :model="form1" :rules="rules1" label-width="120px" class="demo-ruleForm">
<el-form-item label="当前手机号:">
<div class="form-control-static">{{ form1.phone }}</div>
</el-form-item>
<el-form-item label="填写验证码:" prop="verify_code">
<el-row style="display: flex">
<el-input class="inputCode" v-model="form1.verify_code" placeholder="请输入验证码" size="small">
</el-input>
<button type="button" :class="codeClass" class="saveBtn1 getCodeBtn" :disabled="codeBtnDisable" @click.stop="getCode">
{{ codeText }}
</button>
</el-row>
</el-form-item>
</el-form>
</el-col>
</el-row>
<el-row v-show="active == 1" type="flex" class="row-bg" justify="center" style="margin: 20px">
<el-col :span="16">
<el-form ref="form2" :model="form2" :rules="rules2" label-width="120px">
<el-form-item label="输入新密码:" prop="newPwd" v-if="isBi1">
<el-input type="password" placeholder="输入新密码" v-model="form2.newPwd" maxlength="16"
onkeydown="if(event.keyCode==32) return false" @keyup.native="chineseReg"></el-input>
<span class="suffixIconBi" @click="iconClick1(1)"></span>
</el-form-item>
<el-form-item label="输入新密码:" prop="newPwd" v-if="isZheng1">
<el-input type="text" placeholder="输入新密码" v-model="form2.newPwd" maxlength="16"
onkeydown="if(event.keyCode==32) return false" @keyup.native="chineseReg"></el-input>
<span class="suffixIconZheng" @click="iconClick1(-1)"></span>
</el-form-item>
<!--安全程度-->
<el-form-item>
<div class="safeContainer">
<div class="mySafe safe" v-if="passwordLevel===0">
<div></div>
<div></div>
<div></div>
<span>密码强度弱</span>
</div>
<div class="mySafe safe1" v-if="passwordLevel===1">
<div></div>
<div></div>
<div></div>
<span>密码强度弱</span>
</div>
<div class="mySafe safe2" v-if="passwordLevel===2">
<div></div>
<div></div>
<div></div>
<span>密码强度中</span>
</div>
<div class="mySafe safe3" v-if="passwordLevel===3">
<div></div>
<div></div>
<div></div>
<span>密码强度强</span>
</div>
</div>
</el-form-item>
<el-form-item label="确认新密码:" prop="confirmPwd" v-if="isBi">
<el-input type="password" placeholder="再次输入新密码" v-model="form2.confirmPwd" maxlength="16"
onkeydown="if(event.keyCode==32) return false" @keyup.native="chineseReg"></el-input>
<span class="suffixIconBi" @click="iconClick(1)"></span>
</el-form-item>
<el-form-item label="确认新密码:" prop="confirmPwd" v-if="isZheng">
<el-input type="text" placeholder="再次输入新密码" v-model="form2.confirmPwd" maxlength="16"
onkeydown="if(event.keyCode==32) return false" @keyup.native="chineseReg"></el-input>
<span class="suffixIconZheng" @click="iconClick(-1)"></span>
</el-form-item>
<el-form-item style="margin-top: -12px">
<div class="safestatic">
6-16位字符,必须为数字+字母组合(可以支持特殊符号,包括:~、!、@、#、¥、%、&、*)
</div>
</el-form-item>
</el-form>
<!--<div style="text-indent:32px;font-size: 12px;margin-top: 25px;color: #faad14"> 提示:密码必须为5-15位数字或字母组合,区分大小写</div>-->
</el-col>
</el-row>
<div class="myFooter1">
<div class="footer">
<span slot="footer" class="dialog-footer">
<el-button class="saveBtn" :disabled="xiaDisable" @click="nextStep">{{ btnText }}</el-button>
</span>
</div>
</div>
<!--</el-dialog>-->
</div>
</template>
<script>
import {sendCode, checkCode, changePasssWord} from '@/api/api'
export default {
name: 'ModifyPwd',
data() {
const validatePass1 = (rule, value, callback) => {
if (!this.checkPassword(value)) {
callback(new Error("6-16位字符,必须为数字+字母组合(可以支持特殊符号)"));
return;
}
if (this.form2.confirmPwd !== '') {
this.$refs.form2.validateField('confirmPwd');
}
callback();
};
const validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else if (value != this.form2.newPwd) {
callback(new Error('确认密码与新密码不一致,请重新输入'));
} else {
callback();
}
}
return {
xiaDisable:true,
codeBtnDisable: false,
// 密码安全程度
passwordLevel: 0,
// ---------
// ---- 睁眼闭眼-----
isZheng: false,
isBi: true,
isZheng1: false,
isBi1: true,
// ---------
dialogModifyVisible: true,
codeText: '获取验证码',
btnText: '下一步',
codeClass: 'btn-code1',
timer: '',
count: 60,
form1: {
phone: '',
verify_code: ''
},
rules1: {
verify_code: [
{required: true, message: '请输入验证码', trigger: 'blur'}
]
},
form2: {
newPwd: '',
confirmPwd: ''
},
rules2: {
newPwd: [
{required: true, validator: validatePass1, trigger: ['blur,change']}
],
confirmPwd: [
{required: true, validator: validatePass2, trigger: ['blur,change']}
]
},
active: 0
}
},
created() {
this.form1.phone = this.$route.params.phone
},
watch: {
'form2.newPwd': {
handler(newName, oldName) {
if (newName) {
this.checkPassword(newName);
this.$refs.form2.validateField('newPwd');
} else {
this.passwordLevel = 0;
}
},
deep: true
},
'form2.confirmPwd': {
handler(newName, oldName) {
if (newName) {
this.$refs.form2.validateField('confirmPwd');
}
},
deep: true
}
},
methods: {
//HTML反转义
HTMLDecode(text) {
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
},
// 禁止输入汉字
chineseReg() {
let chineseReg = new RegExp(/[\u4E00-\u9FA5]/g);
let hasChinese = chineseReg.test(this.form2.newPwd);//验证汉字
if (hasChinese) {
this.form2.newPwd = this.form2.newPwd.replace(/[\u4e00-\u9fa5]/ig, '');
}
},
// 点击图标切换睁眼闭眼
iconClick(a) {
if (a === 1) {
this.isZheng = true;
this.isBi = false;
} else {
this.isZheng = false;
this.isBi = true;
}
},
iconClick1(a) {
if (a === 1) {
this.isZheng1 = true;
this.isBi1 = false;
} else {
this.isZheng1 = false;
this.isBi1 = true;
}
},
nextStep() {
const _this = this
const ruleForm = 'form' + (this.active + 1)
this.$refs[ruleForm].validate((valid) => {
if (valid) {
if (_this.active === 0) {
// 验证身份
checkCode({mobile: _this.form1.phone, code: _this.form1.verify_code})
.then(function (res) {
if (res.data.status === 'success') {
_this.active++
} else {
// HTMLDecode();
_this.form2.verify_code = '';
_this.$alert(res.data.errorMsg, '提示', {
confirmButtonText: '确定'
})
}
})
} else if (_this.active === 1) {
// 设置新密码
changePasssWord(
{
id: _this.$route.params.id,
password: _this.form2.newPwd,
confirmPassword: _this.form2.confirmPwd
}).then(function (res) {
if (res.data.status === 'success') {
// parent.logout('密码修改成功,请重新登录');
parent.forceLogout('密码修改成功,请重新登录');
} else {
_this.$alert(res.data.errorMsg, '提示', {
confirmButtonText: '确定'
})
}
})
}
} else {
return false
}
})
},
getCode() {
this.xiaDisable=false;
if (this.form1.phone) {
const _this = this
const params = {mobile: _this.form1.phone, username: _this.$route.params.username}
sendCode(params).then(function (res) {
if (res.data.status === 'success') {
_this.setTimer();
} else {
_this.$alert(res.data.errorMsg, '提示', {
confirmButtonText: '确定'
})
}
})
} else {
parent.forceLogout();
}
},
setTimer() {
if (this.timer) return
const _this = this
this.codeClass = 'btn-code2'
_this.count--;
_this.codeBtnDisable = true;
_this.codeText = _this.count + 's后重发'
this.timer = setInterval(function () {
if (_this.count < 2) {
clearInterval(_this.timer)
_this.timer = ''
_this.count = 60
_this.codeClass = 'btn-code1'
_this.codeText = '获取验证码'
_this.codeBtnDisable = false;
} else {
_this.count--
_this.codeText = _this.count + 's后重发'
}
}, 1000)
},
checkPassword(str) {
let numReg = new RegExp(/[0-9]+/);
let hasNum = numReg.test(str);//验证数字
let letterReg = new RegExp(/[a-zA-Z]+/);
let hasLetter = letterReg.test(str);//验证字母
let specialCharacter = new RegExp(/[~!!@#¥%&*]+/);
let hasSpecialCharacter = specialCharacter.test(str);//验证特殊字符
let validateResult = /^(?=.*?[0-9])[0-9A-Za-z~!!@#¥%&*]{6,16}$/g.test(str);//不支持. /等字符
//只含数字、字母、特殊字符其中一种的弱密码
if (!(hasNum && hasLetter) && !(hasLetter && hasSpecialCharacter)
&& !(hasNum && hasSpecialCharacter)) {
this.passwordLevel = 1;
return false;
} else if (hasSpecialCharacter && hasNum && hasLetter) {
//三级安全密码
this.passwordLevel = 3;
} else {
//只包含两种,中度安全
this.passwordLevel = 2;
if ((hasNum && hasSpecialCharacter) || (hasLetter && hasSpecialCharacter)) {
return false;
}
}
return validateResult;
}
}
}
</script>
第二版:6-16位字符,必须为数字+字母组合(可以支持特殊符号,包括:~、!、@、#、¥、%、&、*)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...