updpwd.vue
5.77 KB
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
<template>
<div>
<!-- 修改密码diglog -->
<el-dialog
:title="$t('dialog.changePW')"
class="manage-dialog"
:visible.sync="passwordDialogVisible"
:close-on-click-modal="false"
@close="cancledialog()">
<el-form :model="passwordForm" status-icon ref="passwordForm" :rules="rules">
<el-form-item :label="$t('dialog.oldPW')" prop="password">
<el-input type="password" v-model="passwordForm.password"></el-input>
</el-form-item>
<el-form-item :label="$t('dialog.newPW')" prop="newpass">
<el-input type="password" v-model="passwordForm.newpass"></el-input>
</el-form-item>
<el-form-item :label="$t('dialog.confirmPW')" prop="checkPass">
<el-input type="password" v-model="passwordForm.checkPass"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="passwordDialogVisible = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
<el-button type="primary" :disabled="
passwordForm.password === '' || passwordForm.newpass === '' || passwordForm.checkPass === ''
|| passwordStatus === 'error' || newpassStatus === 'error' || checkPassStatus === 'error'
"
@click="changeSubmit('passwordForm')" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
var validatePass = (rule, value, callback) => {
//var exp = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{6,16}$/; //密码强度正则,最少6位最多16位,包括1个大写字母,1个小写字母,1个数字,1个特殊字符以上两种
var exp = /^(?=.*[0-9])((?=.*[A-Z])|(?=.*[a-z]))(?=.*[^a-zA-Z0-9]).{8,30}$/;
if (value === '') {
callback(new Error('请输入旧密码'));
this.passwordStatus = 'error'
}else{
callback()
this.passwordStatus = 'success'
}
}
var validatePass1 = (rule, value, callback) => {
//var exp = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{6,16}$/;
var exp = /^(?=.*[0-9])((?=.*[A-Z])|(?=.*[a-z]))(?=.*[^a-zA-Z0-9]).{8,30}$/;
if (!exp.test(value)) {
this.newpassStatus = 'error'
return callback(new Error(this.$t("rules.wordRules")));
}
if (value === '') {
callback(new Error(this.$t("rules.password")));
this.newpassStatus = 'error'
}else if(value == this.passwordForm.password){
callback(new Error(this.$t("rules.newOldSame")))
this.newpassStatus = 'error'
} else {
if (this.passwordForm.checkPass !== '') {
this.$refs.passwordForm.validateField('checkPass');
}
callback();
this.newpassStatus = 'success'
}
};
var validatePass2 = (rule, value, callback) => {
//var exp = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{6,16}$/;
var exp = /^(?=.*[0-9])((?=.*[A-Z])|(?=.*[a-z]))(?=.*[^a-zA-Z0-9]).{8,30}$/;
if (!exp.test(value)) {
return callback(new Error(this.$t("rules.wordRules")));
this.checkPassStatus = 'error'
}
if (value === '') {
callback(new Error(this.$t("rules.checkWord")));
this.checkPassStatus = 'error'
} else if (value !== this.passwordForm.newpass) {
callback(new Error(this.$t("rules.checkDifferent")));
this.checkPassStatus = 'error'
} else {
callback();
this.checkPassStatus = 'success'
}
};
return {
passwordDialogVisible: false,
passwordForm:{
password:'',
newpass:'',
checkPass:''
},
rules: {
password:[
{ validator:validatePass, trigger: 'change' },
{ min: 6, max: 30, message: '密码长度不小于6位', trigger: 'blur' }
],
newpass: [
{ validator: validatePass1, trigger: 'change' },
],
checkPass: [
{ validator: validatePass2, trigger: 'change' },
]
},
passwordStatus: 'error',
newpassStatus: 'error',
checkPassStatus: 'error',
}
},
methods: {
dialogInit(login_name) {
this.passwordForm.loginName = login_name
this.passwordDialogVisible = true;
},
cancledialog() {
this.$refs.passwordForm.resetFields();
},
changeSubmit(formName) {
if(!this.passwordForm.newpass || !this.passwordForm.checkPass || !this.passwordForm.password){
this.$message({
showClose: true,
message: '密码不能为空!',
type: 'warning'
});
}else if(this.passwordForm.newpass == this.passwordForm.checkPass){
if(this.passwordForm.password == this.passwordForm.newpass){
this.$message({
showClose: true,
message: '新旧密码不能相同!',
type: 'warning'
});
}else{
this.$api.management.editUser({
loginName:this.passwordForm.loginName,
oldPassWord:this.passwordForm.password,
password:this.passwordForm.newpass
})
.then((res) => {
this.passwordDialogVisible = false
if(res.data.code == 200) {
this.$message({
showClose: true,
message: this.$t('message.changePWSuccess'),
type: 'success'
})
this.logout()
}else{
this.$message({
showClose: true,
message: this.$t('message.changePWFailed'),
type: 'error'
})
}
})
.catch((err) => {
})
}
}else {
this.$message({
showClose: true,
message: '两次输入密码不一致!',
type: 'warning'
});
}
},
logout() {
for(let i in window.localStorage) {
if(i == 'lang' || i == 'oldAlarm'){
}else{
window.localStorage.removeItem(i);
}
}
for(let i in window.sessionStorage) {
window.sessionStorage.removeItem(i);
}
let cookieInfo = this.$cookie.get();
for(let k in cookieInfo) {
this.$cookie.remove(k);
}
this.$router.push('/');
},
}
}
</script>
<style scoped>
</style>