Skip to content

Commit e278fcf

Browse files
GongJSvanoneang
authored andcommitted
Temp (#121)
* fix: 修复修改个人信息分组内容重叠的bug * fix:checkbox 半选状态
1 parent 72ef024 commit e278fcf

4 files changed

Lines changed: 139 additions & 80 deletions

File tree

src/assets/styles/realize/elementUi.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
width: 100%;
3939
}
4040

41-
.el-radio {
42-
width: 33%;
43-
margin-left: 0px !important;
44-
margin-bottom: 20px;
45-
}
46-
4741
.el-radio__inner {
4842
border: 1px solid #c4c0d2 !important;
4943
}
@@ -57,12 +51,6 @@
5751
color: $theme;
5852
}
5953

60-
@media screen and (max-width: 980px) {
61-
.el-radio {
62-
width: 50%;
63-
}
64-
}
65-
6654
// form
6755
.el-form-item__label {
6856
color: #333333;

src/components/layout/SideBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default {
169169
170170
.mobile-logo {
171171
width: 64px;
172-
height: 66px;
172+
height: 72px;
173173
display: flex;
174174
justify-content: center;
175175
align-items: center;

src/views/admin/group/GroupAuths.vue

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
<label>{{title}}</label>
66
</div>
77
<div class="details">
8-
9-
<div class="permissions-box" v-for="(auth,index) in allAuths" :key="index">
8+
<div class="permissions-box" v-for="(auth,moduleName) in allAuths" :key="moduleName">
109
<el-checkbox-group v-model="auths">
1110
<div class="module-box">
12-
<el-checkbox @change="moduleCheck($event, auth)" class="module" :label="index">
13-
</el-checkbox>
11+
<el-checkbox
12+
@change="moduleCheck($event, auth,moduleName)"
13+
class="module"
14+
:label="moduleName"
15+
:indeterminate="halfAuths.includes(moduleName)"></el-checkbox>
1416
</div>
1517

1618
<ul class="permissions-ul">
1719
<li class="permissions-li" v-for="(item,key) in auth" :key="key">
18-
<el-checkbox :label="key | filterTitle(32)" @change="singleCheck($event, key, index)"></el-checkbox>
20+
<el-checkbox :label="key | filterTitle(32)" @change="singleCheck($event, key, moduleName)"></el-checkbox>
1921
</li>
2022
</ul>
2123
</el-checkbox-group>
@@ -35,6 +37,7 @@ export default {
3537
return {
3638
allAuths: {}, // 所有分组权限
3739
auths: [], // 拥有的分组权限
40+
halfAuths: [], // 该分类下的权限没有全选中
3841
cacheFlag: true,
3942
loading: false,
4043
}
@@ -53,65 +56,95 @@ export default {
5356
let res = await Admin.getOneGroup(this.id)
5457
// 获取分组所拥有的权限
5558
/* eslint-disable */
56-
res = JSON.parse(JSON.stringify(res)) // 去除__ob__
59+
res = JSON.parse(JSON.stringify(res)); // 去除__ob__
5760
for (let i = 0; i < res.auths.length; i++) {
5861
for (const key in res.auths[i]) {
5962
for (let j = 0; j < res.auths[i][key].length; j++) {
60-
this.auths.push(res.auths[i][key][j].auth)
63+
this.auths.push(res.auths[i][key][j].auth);
6164
}
6265
}
6366
}
64-
this.$emit('updateCacheAuths', this.auths)
67+
this.$emit("updateCacheAuths", this.auths);
6568
// 检查module状态是否需要选中
6669
for (const key in this.allAuths) {
67-
this.initModuleCheck(key)
70+
this.initModuleCheck(key);
6871
}
6972
}
70-
this.$emit('updateAuths', this.auths)
71-
this.$emit('updateAllAuths', this.allAuths)
73+
this.$emit("updateAuths", this.auths);
74+
this.$emit("updateAllAuths", this.allAuths);
7275
},
7376
// 弹窗打开时,判断某一分类权限是否全部选中
7477
initModuleCheck(moduleName) {
75-
const currentModuleChildrenArr = Object.keys(this.allAuths[moduleName])
76-
const intersect = Utils.getIntersect(currentModuleChildrenArr, this.auths)
78+
const currentModuleChildrenArr = Object.keys(this.allAuths[moduleName]);
79+
const intersect = Utils.getIntersect(
80+
currentModuleChildrenArr,
81+
this.auths
82+
);
83+
// 全选
7784
if (intersect.length === currentModuleChildrenArr.length) {
78-
this.auths.push(moduleName)
85+
this.auths.push(moduleName);
86+
}
87+
// 半选
88+
if (
89+
intersect.length > 0 &&
90+
intersect.length < currentModuleChildrenArr.length
91+
) {
92+
this.halfAuths.push(moduleName);
7993
}
8094
},
81-
moduleCheck(checked, auth) {
82-
const authArr = Object.keys(auth)
95+
moduleCheck(checked, auth, moduleName) {
96+
const authArr = Object.keys(auth);
8397
if (checked) {
84-
this.auths.push(...authArr)
98+
if (this.halfAuths.indexOf(moduleName) > -1) {
99+
this.halfAuths.splice(this.halfAuths.indexOf(moduleName), 1);
100+
}
101+
this.auths.push(...authArr);
85102
} else {
86-
this.auths = this.auths.filter(x => authArr.indexOf(x) < 0)
103+
if (this.halfAuths.indexOf(moduleName) > -1) {
104+
this.halfAuths.splice(this.halfAuths.indexOf(moduleName), 1);
105+
}
106+
this.auths = this.auths.filter(x => authArr.indexOf(x) < 0);
87107
}
88-
this.$emit('updateAuths', this.auths)
108+
this.$emit("updateAuths", this.auths);
89109
},
90110
singleCheck(checked, singleAuth, moduleName) {
91-
const currentModuleChildrenArr = Object.keys(this.allAuths[moduleName])
92-
const intersect = Utils.getIntersect(currentModuleChildrenArr, this.auths)
111+
const currentModuleChildrenArr = Object.keys(this.allAuths[moduleName]);
112+
const intersect = Utils.getIntersect(
113+
currentModuleChildrenArr,
114+
this.auths
115+
);
93116
if (intersect.length === currentModuleChildrenArr.length) {
94-
this.auths.push(moduleName)
95-
} else {
96-
const index = this.auths.indexOf(moduleName)
97-
if (index > -1) {
98-
this.auths.splice(index, 1)
117+
if (this.halfAuths.indexOf(moduleName) > -1) {
118+
this.halfAuths.splice(this.halfAuths.indexOf(moduleName), 1);
99119
}
120+
this.auths.push(moduleName);
121+
} else if (
122+
intersect.length > 0 &&
123+
intersect.length < currentModuleChildrenArr.length
124+
) {
125+
// this.auths.splice(this.auths.indexOf(moduleName),1)
126+
this.halfAuths.push(moduleName);
127+
} else {
128+
129+
this.halfAuths.splice(this.halfAuths.indexOf(moduleName), 1);
130+
this.auths.splice(this.auths.indexOf(moduleName), 1);
100131
}
101-
this.$emit('updateAuths', this.auths)
102-
},
132+
this.halfAuths = Array.from(new Set(this.halfAuths));
133+
this.auths = Array.from(new Set(this.auths));
134+
this.$emit("updateAuths", this.auths);
135+
}
103136
},
104137
async created() {
105138
try {
106-
this.loading = true
107-
await this.getGroupAuths()
108-
this.loading = false
139+
this.loading = true;
140+
await this.getGroupAuths();
141+
this.loading = false;
109142
} catch (e) {
110-
this.loading = false
111-
console.log(e)
143+
this.loading = false;
144+
console.log(e);
112145
}
113146
}
114-
}
147+
};
115148
</script>
116149

117150
<style lang="scss" scoped>
@@ -185,14 +218,15 @@ export default {
185218
margin-bottom: 20px;
186219
187220
.permissions-li {
188-
width: 290px;
221+
width: 150px;
189222
height: 20px;
190223
line-height: 20px;
191224
margin-bottom: 20px;
192225
display: flex;
193226
flex-direction: row;
194227
justify-content: flex-start;
195228
vertical-align: text-top;
229+
margin-right: 10px;
196230
197231
.check {
198232
transform: translateY(2px);

src/views/admin/user/UserInfo.vue

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<template>
22
<div class="container">
33
<el-row>
4-
<el-col
5-
:lg="16"
6-
:md="20"
7-
:sm="24"
8-
:xs="24">
4+
<el-col :lg="16" :md="20" :sm="24" :xs="24">
95
<el-form
106
:model="form"
117
status-icon
@@ -14,36 +10,28 @@
1410
ref="form"
1511
v-loading="loading"
1612
label-width="100px"
17-
@submit.native.prevent>
13+
@submit.native.prevent
14+
>
1815
<el-form-item label="用户名" prop="nickname">
1916
<el-input clearable v-model="form.nickname" :disabled="isEdited"></el-input>
2017
</el-form-item>
2118
<el-form-item label="邮箱" prop="email">
2219
<el-input clearable v-model="form.email" autocomplete="off"></el-input>
2320
</el-form-item>
2421
<el-form-item v-if="pageType === 'add'" label="密码" prop="password">
25-
<el-input
26-
clearable
27-
type="password"
28-
v-model="form.password"
29-
autocomplete="off"></el-input>
22+
<el-input clearable type="password" v-model="form.password" autocomplete="off"></el-input>
3023
</el-form-item>
3124
<el-form-item
3225
v-if="pageType === 'add'"
3326
label="确认密码"
3427
prop="confirm_password"
35-
label-position="top">
36-
<el-input
37-
clearable
38-
type="password"
39-
v-model="form.confirm_password"
40-
autocomplete="off"></el-input>
28+
label-position="top"
29+
>
30+
<el-input clearable type="password" v-model="form.confirm_password" autocomplete="off"></el-input>
4131
</el-form-item>
4232
<el-form-item v-if="pageType !== 'password'" label="选择分组">
43-
<el-radio-group v-model="form.group_id" label-position="top">
44-
<el-radio :label="item.id" v-for="(item, index) in groups" :key=index>
45-
{{item.name}}
46-
</el-radio>
33+
<el-radio-group v-model="form.group_id" label-position="top" class="user-info">
34+
<el-radio :label="item.id" v-for="(item, index) in groups" :key="index">{{item.name}}</el-radio>
4735
</el-radio-group>
4836
</el-form-item>
4937
<el-form-item v-show="submit" class="submit">
@@ -66,19 +54,23 @@ export default {
6654
type: Boolean, // 表单是否显示功能按钮
6755
default: true,
6856
},
69-
id: { // 用户id
57+
id: {
58+
// 用户id
7059
type: Number,
7160
default: undefined,
7261
},
73-
groups: { // 所有分组
62+
groups: {
63+
// 所有分组
7464
type: Array,
7565
default: () => {},
7666
},
77-
labelPosition: { // 表单label位置
67+
labelPosition: {
68+
// 表单label位置
7869
type: String,
7970
default: 'right',
8071
},
81-
info: { // 用户信息
72+
info: {
73+
// 用户信息
8274
type: Object,
8375
default: () => {},
8476
},
@@ -90,9 +82,10 @@ export default {
9082
inject: ['eventBus'],
9183
data() {
9284
// 验证回调函数
93-
const checkUserName = (rule, value, callback) => { // eslint-disable-line
85+
const checkUserName = (rule, value, callback) => {
86+
// eslint-disable-line
9487
if (!value) {
95-
return callback(new Error('用户名不能为空'))
88+
callback(new Error('用户名不能为空'))
9689
}
9790
callback()
9891
}
@@ -130,7 +123,11 @@ export default {
130123
// 验证规则
131124
rules: {
132125
nickname: [
133-
{ validator: checkUserName, trigger: ['blur', 'change'], required: true },
126+
{
127+
validator: checkUserName,
128+
trigger: ['blur', 'change'],
129+
required: true,
130+
},
134131
],
135132
password: [
136133
{ validator: validatePassword, trigger: 'blur', required: true },
@@ -139,15 +136,20 @@ export default {
139136
{ validator: validatePassword2, trigger: 'blur', required: true },
140137
],
141138
email: [
142-
{ type: 'email', message: '请输入正确的邮箱地址或者不填', trigger: ['blur', 'change'] },
139+
{
140+
type: 'email',
141+
message: '请输入正确的邮箱地址或者不填',
142+
trigger: ['blur', 'change'],
143+
},
143144
],
144145
},
145146
}
146147
},
147148
methods: {
148149
// 提交表单
149150
async submitForm(formName) {
150-
this.$refs[formName].validate(async (valid) => { // eslint-disable-line
151+
this.$refs[formName].validate(async (valid) => {
152+
// eslint-disable-line
151153
if (valid) {
152154
// 新增用户
153155
let res
@@ -170,12 +172,20 @@ export default {
170172
}
171173
} else {
172174
// 更新用户信息
173-
if (this.form.email === this.info.email && this.form.group_id === this.info.group_id) {
175+
if (
176+
this.form.email === this.info.email
177+
&& this.form.group_id === this.info.group_id
178+
) {
179+
this.$emit('handleInfoResult', false)
174180
return
175181
}
176182
try {
177183
this.loading = true
178-
res = await Admin.updateOneUser(this.form.email, this.form.group_id, this.id)
184+
res = await Admin.updateOneUser(
185+
this.form.email,
186+
this.form.group_id,
187+
this.id,
188+
)
179189
} catch (e) {
180190
this.loading = false
181191
console.log(e)
@@ -241,3 +251,30 @@ export default {
241251
}
242252
}
243253
</style>
254+
255+
<style lang="scss">
256+
.el-radio-group {
257+
&.user-info {
258+
display: flex;
259+
flex-wrap: wrap;
260+
width: 120%;
261+
> .el-radio {
262+
width: 30%;
263+
margin-left: 0px !important;
264+
margin-right: 10px;
265+
margin-bottom: 20px;
266+
white-space: normal;
267+
display: flex;
268+
}
269+
}
270+
}
271+
@media screen and (max-width: 980px) {
272+
.el-radio-group {
273+
&.user-info {
274+
> .el-radio {
275+
width: 50%;
276+
}
277+
}
278+
}
279+
}
280+
</style>

0 commit comments

Comments
 (0)