HeadNav.js
6.21 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
import {
user as UserApi,
system as SystemApi
} from '../../../config/request.js';
module.exports = {
name: 'head-nav',
data() {
return {
dialog: {
show_set: false,
show_pass: false,
title: '修改密码',
user_info: this.$store.state.user.userinfo,
set_info: {
login_style: '',
disabled_update_pass: [],
select_users: []
},
user_info_rules: {
old_password: [{
required: true,
message: '旧密码不能为空!',
trigger: 'blur'
}],
password: [{
required: true,
message: '新密码不能为空!',
trigger: 'blur'
}, {
trigger: 'blur',
validator: (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else {
if ('' !== this.dialog.user_info.password) {
this.$refs.user_info.validateField('password_confirm');
}
callback();
}
}
}],
password_confirm: [{
required: true,
message: '确认密码不能为空!',
trigger: 'blur'
}, {
trigger: 'blur',
validator: (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else if (value !== this.dialog.user_info.password) {
callback(new Error('两次输入密码不一致!'));
} else {
callback();
}
}
}],
}
}
}
},
mounted() {
// this.onGetSetting();
},
methods: {
/**
* 退出登录
*/
logout() {
this.$confirm('你确定退出登录么?', '确认退出', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$store.dispatch('remove_userinfo').then(() => {
this.$router.push('/login');
});
});
},
/**
* 弹出框-修改密码或者系统设置
* @param {string} cmditem 弹框类型
*/
setDialogInfo(cmditem) {
if (!cmditem) {
this.$message.error('菜单选项缺少command属性');
return;
}
switch (cmditem) {
case 'info':
this.$router.push({
path: '/demo/user/edit',
query: {
id: this.$store.state.user.userinfo.id
}
});
break;
case 'pass':
this.dialog.show_pass = true;
this.dialog.title = '修改密码';
break;
case 'set':
this.onGetSetting();
this.dialog.show_set = true;
this.dialog.title = '系统设置';
break;
}
},
/**
* 修改密码
* @param {object} userinfo 当前修改密码的表单信息
*/
updUserPass(userinfo) {
this.$refs[userinfo].validate((valid) => {
if (valid) {
UserApi.updPass.call(this, {
old_password: this.dialog[userinfo].old_password,
password: this.dialog[userinfo].password,
password_confirm: this.dialog[userinfo].password_confirm
}, (data) => {
this.dialog.show_pass = false;
// this.$nextTick(() => {
this.$message.success('修改成功!');
// });
});
}
});
},
/**
* 获取系统设置信息
*/
onGetSetting() {
//获取系统设置信息
if (this.$store.state.user.userinfo.pid == 0) {
SystemApi.getSetting.call(this, (data) => {
// console.log(data);
if (data.setting_info.disabled_update_pass) {
data.setting_info.disabled_update_pass = data.setting_info.disabled_update_pass.split(',');
} else {
data.setting_info.disabled_update_pass = [];
}
data.setting_info.login_style = data.setting_info.login_style + '';
this.dialog.set_info = data.setting_info;
});
} else {
this.$message.error('只有管理员才能操作!');
}
},
/**
* 修改系统设置信息
*/
onUpdateSetting() {
// console.log(this.dialog.set_info.login_style);
// console.log(this.dialog.set_info.disabled_update_pass);
// console.log(this.dialog.set_info.id);
SystemApi.updateSetting.call(this, {
id: this.dialog.set_info.id,
login_style: this.dialog.set_info.login_style,
disabled_update_pass: this.dialog.set_info.disabled_update_pass && this.dialog.set_info.disabled_update_pass.length ? this.dialog.set_info.disabled_update_pass.join(',') : ''
}, (data) => {
// console.log(data);
this.dialog.show_set = false;
});
}
}
}