@@ -39,6 +39,7 @@ export default {
3939 data () {
4040 return {
4141 allAuths: {}, // 所有分组权限
42+ allAuthIds: [],
4243 // auths: [], // 拥有的分组权限
4344 auth_module_name: [], // 权限组 module name
4445 auth_module_ids: [], // 权限组 集合 id
@@ -47,14 +48,19 @@ export default {
4748 loading: false ,
4849 }
4950 },
51+ async created () {
52+ try {
53+ this .loading = true
54+ await this .getGroupAuths ()
55+ this .loading = false
56+ } catch (e) {
57+ this .loading = false
58+ console .log (e)
59+ }
60+ },
5061 methods: {
51- // 获取全部权限
52- async getAllAuths () {
53- this .allAuths = await Admin .getAllAuths ()
54- },
5562 // 获取分组权限
5663 async getGroupAuths () {
57- // this.auths = [] // 父组件 重置
5864 this .allAuths = await Admin .getAllAuths ()
5965 // 通过判断有没有传入id,来判断当前页面是添加分组还是编辑分组
6066 if (this .id ) {
@@ -64,23 +70,24 @@ export default {
6470 res .permissions .forEach (v => {
6571 this .auth_module_ids .push (v .id )
6672 temp .push (v .module )
73+ // 每个module拥有权限个数
6774 if (! cache[v .module ]) {
6875 cache[v .module ] = 1
6976 } else {
7077 cache[v .module ]++
7178 }
7279 })
7380 temp = Array .from (new Set (temp))
81+ // 半选
7482 temp .forEach (item => {
75- if (this .allAuths [item].length === cache[item]) {
76- this .auth_module_ids .push (item)
77- } else {
83+ if (this .allAuths [item].length !== cache[item]) {
7884 this .halfAuths .push (item)
7985 }
8086 })
8187 this .auth_module_name = Array .from (new Set (temp))
8288 }
83- this .$emit (' updateAuths' , this .auths )
89+ this .$emit (' getCacheAuthIds' , this .auth_module_ids .slice ())
90+ this .$emit (' updateAuths' , this .auth_module_ids )
8491 this .$emit (' updateAllAuths' , this .allAuths )
8592 },
8693
@@ -95,7 +102,7 @@ export default {
95102 this .auth_module_ids = this .auth_module_ids .filter (v => ! _ids .includes (v))
96103 this .auth_module_name = this .auth_module_name .filter (v => v !== moduleName)
97104 }
98- // this.$emit('updateAuths', this.auths )
105+ this .$emit (' updateAuths' , this .auth_module_ids )
99106 },
100107
101108 // 单选
@@ -129,16 +136,6 @@ export default {
129136 this .$emit (' updateAuths' , this .auth_module_ids )
130137 },
131138 },
132- async created () {
133- try {
134- this .loading = true
135- await this .getGroupAuths ()
136- this .loading = false
137- } catch (e) {
138- this .loading = false
139- console .log (e)
140- }
141- },
142139}
143140 </script >
144141
0 commit comments