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 : 290 px ;
221+ width : 150 px ;
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 );
0 commit comments