81 lines
3.1 KiB
Vue
81 lines
3.1 KiB
Vue
<template>
|
|
<el-card shadow="never">
|
|
<el-form ref="resetForm" :model="formData" label-width="100px" :rules="rules">
|
|
<el-form-item label="原密码" prop="oldPassword">
|
|
<el-input type="password" v-model="formData.oldPassword" clearable
|
|
placeholder="请输入原密码"/>
|
|
</el-form-item>
|
|
<el-form-item label="新密码" prop="newPassword">
|
|
<el-input type="password" v-model="formData.newPassword" clearable
|
|
placeholder="请输入新密码"/>
|
|
<p class="tips text-gray">6~20位的数字、字母组合</p>
|
|
</el-form-item>
|
|
<el-form-item label="确认密码" prop="passwordConfirmation">
|
|
<el-input type="password" v-model="formData.passwordConfirmation" clearable
|
|
placeholder="请再次输入新密码"/>
|
|
<p class="tips text-gray">6~20位的数字、字母组合</p>
|
|
</el-form-item>
|
|
</el-form>
|
|
<el-button type="primary" @click.native="submit">确定</el-button>
|
|
</el-card>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: "pwd",
|
|
data() {
|
|
return {
|
|
formData: {
|
|
oldPassword: null,
|
|
newPassword: null,
|
|
passwordConfirmation: null,
|
|
},
|
|
rules: {
|
|
oldPassword: [
|
|
{required: true, message: '请输入原密码', trigger: 'blur'},
|
|
],
|
|
newPassword: [
|
|
{required: true, message: '请输入新密码', trigger: 'blur'},
|
|
{min: 6, max: 16, message: '密码长度在 6 到 20 个字符', trigger: 'blur'},
|
|
],
|
|
passwordConfirmation: [
|
|
{required: true, message: '请再次输入新密码', trigger: 'blur'},
|
|
{validator: this.checkPassword, trigger: 'blur'},
|
|
],
|
|
},
|
|
}
|
|
},
|
|
methods: {
|
|
submit() {
|
|
if (!this.formData.oldPassword) return this.$message.error('请输入原密码');
|
|
if (!this.formData.newPassword) return this.$message.error('请输入原密码');
|
|
if (!this.formData.passwordConfirmation) return this.$message.error('请输入原密码');
|
|
if (this.formData.newPassword !== this.formData.passwordConfirmation) return this.$message.error('两次输入的密码不一致!');
|
|
if (this.formData.newPassword === this.formData.oldPassword) return this.$message.error('新密码不能与原密码相同!');
|
|
if (this.formData.newPassword.length < 6 || this.formData.newPassword.length > 20) return this.$message.error('密码长度在 6 到 20 个字符');
|
|
const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+$/
|
|
if (!reg.test(this.formData.newPassword)) {
|
|
return this.$message({
|
|
message: '密码必须由数字和字母组成',
|
|
type: 'error'
|
|
})
|
|
}
|
|
vk.callFunction({
|
|
url: 'user/kh/updatePwd',
|
|
data: this.formData
|
|
}).then(res => {
|
|
this.$message({
|
|
type: 'success',
|
|
message: '修改成功'
|
|
})
|
|
this.$refs.resetForm.resetFields();
|
|
})
|
|
},
|
|
checkPassword(rule, value, callback) {
|
|
if (value !== this.formData.newPassword) {
|
|
callback(new Error('两次输入的密码不一致!'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script> |