Commit 8a3da11867aa8f51a402a60dd6c4a0d3723d2a8e
1 parent
719ba897
JeecgBoot 2.1.1 代码生成器AI版本发布
Showing
1 changed file
with
20 additions
and
36 deletions
ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue
... | ... | @@ -31,10 +31,8 @@ |
31 | 31 | <div class="drawer-bootom-button"> |
32 | 32 | <a-dropdown style="float: left" :trigger="['click']" placement="topCenter"> |
33 | 33 | <a-menu slot="overlay"> |
34 | - <!-- 简化Tree逻辑,使用默认checkStrictly为false的行为,即默认父子关联 | |
35 | 34 | <a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item> |
36 | 35 | <a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item> |
37 | - --> | |
38 | 36 | <a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item> |
39 | 37 | <a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item> |
40 | 38 | <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item> |
... | ... | @@ -70,11 +68,10 @@ |
70 | 68 | treeData: [], |
71 | 69 | defaultCheckedKeys:[], |
72 | 70 | checkedKeys:[], |
73 | - halfCheckedKeys:[], | |
74 | 71 | expandedKeysss:[], |
75 | 72 | allTreeKeys:[], |
76 | 73 | autoExpandParent: true, |
77 | - checkStrictly: false, | |
74 | + checkStrictly: true, | |
78 | 75 | title:"角色权限配置", |
79 | 76 | visible: false, |
80 | 77 | loading: false, |
... | ... | @@ -88,10 +85,12 @@ |
88 | 85 | } |
89 | 86 | this.$refs.datarule.show(this.selectedKeys[0],this.roleId) |
90 | 87 | }, |
91 | - onCheck (checkedKeys, { halfCheckedKeys }) { | |
92 | - // 保存选中的和半选中的,后面保存的时候合并提交 | |
93 | - this.checkedKeys = checkedKeys | |
94 | - this.halfCheckedKeys = halfCheckedKeys | |
88 | + onCheck (o) { | |
89 | + if(this.checkStrictly){ | |
90 | + this.checkedKeys = o.checked; | |
91 | + }else{ | |
92 | + this.checkedKeys = o | |
93 | + } | |
95 | 94 | }, |
96 | 95 | show(roleId){ |
97 | 96 | this.roleId=roleId |
... | ... | @@ -122,18 +121,24 @@ |
122 | 121 | this.checkedKeys = this.allTreeKeys |
123 | 122 | }, |
124 | 123 | cancelCheckALL () { |
124 | + //this.checkedKeys = this.defaultCheckedKeys | |
125 | 125 | this.checkedKeys = [] |
126 | 126 | }, |
127 | + switchCheckStrictly (v) { | |
128 | + if(v==1){ | |
129 | + this.checkStrictly = false | |
130 | + }else if(v==2){ | |
131 | + this.checkStrictly = true | |
132 | + } | |
133 | + }, | |
127 | 134 | handleCancel () { |
128 | 135 | this.close() |
129 | 136 | }, |
130 | 137 | handleSubmit(){ |
131 | 138 | let that = this; |
132 | - let checkedKeys = [...that.checkedKeys, ...that.halfCheckedKeys] | |
133 | - const permissionIds = checkedKeys.join(",") | |
134 | 139 | let params = { |
135 | 140 | roleId:that.roleId, |
136 | - permissionIds, | |
141 | + permissionIds:that.checkedKeys.join(","), | |
137 | 142 | lastpermissionIds:that.defaultCheckedKeys.join(","), |
138 | 143 | }; |
139 | 144 | that.loading = true; |
... | ... | @@ -150,15 +155,6 @@ |
150 | 155 | } |
151 | 156 | }) |
152 | 157 | }, |
153 | - convertTreeListToKeyLeafPairs(treeList, keyLeafPair = []) { | |
154 | - for(const {key, isLeaf, children} of treeList) { | |
155 | - keyLeafPair.push({key, isLeaf}) | |
156 | - if(children && children.length > 0) { | |
157 | - this.convertTreeListToKeyLeafPairs(children, keyLeafPair) | |
158 | - } | |
159 | - } | |
160 | - return keyLeafPair; | |
161 | - }, | |
162 | 158 | }, |
163 | 159 | watch: { |
164 | 160 | visible () { |
... | ... | @@ -166,23 +162,11 @@ |
166 | 162 | queryTreeListForRole().then((res) => { |
167 | 163 | this.treeData = res.result.treeList |
168 | 164 | this.allTreeKeys = res.result.ids |
169 | - const keyLeafPairs = this.convertTreeListToKeyLeafPairs(this.treeData) | |
170 | 165 | queryRolePermission({roleId:this.roleId}).then((res)=>{ |
171 | - // 过滤出 leaf node 即可,即选中的 | |
172 | - // Tree组件中checkStrictly默认为false的时候,选中子节点,父节点会自动设置选中或半选中 | |
173 | - // 保存 checkedKeys 以及 halfCheckedKeys 以便于未做任何操作时提交表单数据 | |
174 | - const checkedKeys = [...res.result].filter(key => { | |
175 | - const keyLeafPair = keyLeafPairs.filter(item => item.key === key)[0] | |
176 | - return keyLeafPair && keyLeafPair.isLeaf | |
177 | - }) | |
178 | - const halfCheckedKeys = [...res.result].filter(key => { | |
179 | - const keyLeafPair = keyLeafPairs.filter(item => item.key === key)[0] | |
180 | - return keyLeafPair && !keyLeafPair.isLeaf | |
181 | - }) | |
182 | - this.checkedKeys = [...checkedKeys]; | |
183 | - this.halfCheckedKeys = [...halfCheckedKeys] | |
184 | - this.defaultCheckedKeys = [...halfCheckedKeys, ...checkedKeys]; | |
185 | - this.expandedKeysss = this.allTreeKeys; | |
166 | + this.checkedKeys = [...res.result]; | |
167 | + this.defaultCheckedKeys = [...res.result]; | |
168 | + this.expandedKeysss = this.allTreeKeys; | |
169 | + //console.log(this.defaultCheckedKeys) | |
186 | 170 | }) |
187 | 171 | }) |
188 | 172 | } |
... | ... |