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,10 +31,8 @@ | ||
31 | <div class="drawer-bootom-button"> | 31 | <div class="drawer-bootom-button"> |
32 | <a-dropdown style="float: left" :trigger="['click']" placement="topCenter"> | 32 | <a-dropdown style="float: left" :trigger="['click']" placement="topCenter"> |
33 | <a-menu slot="overlay"> | 33 | <a-menu slot="overlay"> |
34 | - <!-- 简化Tree逻辑,使用默认checkStrictly为false的行为,即默认父子关联 | ||
35 | <a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item> | 34 | <a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item> |
36 | <a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item> | 35 | <a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item> |
37 | - --> | ||
38 | <a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item> | 36 | <a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item> |
39 | <a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item> | 37 | <a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item> |
40 | <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item> | 38 | <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item> |
@@ -70,11 +68,10 @@ | @@ -70,11 +68,10 @@ | ||
70 | treeData: [], | 68 | treeData: [], |
71 | defaultCheckedKeys:[], | 69 | defaultCheckedKeys:[], |
72 | checkedKeys:[], | 70 | checkedKeys:[], |
73 | - halfCheckedKeys:[], | ||
74 | expandedKeysss:[], | 71 | expandedKeysss:[], |
75 | allTreeKeys:[], | 72 | allTreeKeys:[], |
76 | autoExpandParent: true, | 73 | autoExpandParent: true, |
77 | - checkStrictly: false, | 74 | + checkStrictly: true, |
78 | title:"角色权限配置", | 75 | title:"角色权限配置", |
79 | visible: false, | 76 | visible: false, |
80 | loading: false, | 77 | loading: false, |
@@ -88,10 +85,12 @@ | @@ -88,10 +85,12 @@ | ||
88 | } | 85 | } |
89 | this.$refs.datarule.show(this.selectedKeys[0],this.roleId) | 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 | show(roleId){ | 95 | show(roleId){ |
97 | this.roleId=roleId | 96 | this.roleId=roleId |
@@ -122,18 +121,24 @@ | @@ -122,18 +121,24 @@ | ||
122 | this.checkedKeys = this.allTreeKeys | 121 | this.checkedKeys = this.allTreeKeys |
123 | }, | 122 | }, |
124 | cancelCheckALL () { | 123 | cancelCheckALL () { |
124 | + //this.checkedKeys = this.defaultCheckedKeys | ||
125 | this.checkedKeys = [] | 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 | handleCancel () { | 134 | handleCancel () { |
128 | this.close() | 135 | this.close() |
129 | }, | 136 | }, |
130 | handleSubmit(){ | 137 | handleSubmit(){ |
131 | let that = this; | 138 | let that = this; |
132 | - let checkedKeys = [...that.checkedKeys, ...that.halfCheckedKeys] | ||
133 | - const permissionIds = checkedKeys.join(",") | ||
134 | let params = { | 139 | let params = { |
135 | roleId:that.roleId, | 140 | roleId:that.roleId, |
136 | - permissionIds, | 141 | + permissionIds:that.checkedKeys.join(","), |
137 | lastpermissionIds:that.defaultCheckedKeys.join(","), | 142 | lastpermissionIds:that.defaultCheckedKeys.join(","), |
138 | }; | 143 | }; |
139 | that.loading = true; | 144 | that.loading = true; |
@@ -150,15 +155,6 @@ | @@ -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 | watch: { | 159 | watch: { |
164 | visible () { | 160 | visible () { |
@@ -166,23 +162,11 @@ | @@ -166,23 +162,11 @@ | ||
166 | queryTreeListForRole().then((res) => { | 162 | queryTreeListForRole().then((res) => { |
167 | this.treeData = res.result.treeList | 163 | this.treeData = res.result.treeList |
168 | this.allTreeKeys = res.result.ids | 164 | this.allTreeKeys = res.result.ids |
169 | - const keyLeafPairs = this.convertTreeListToKeyLeafPairs(this.treeData) | ||
170 | queryRolePermission({roleId:this.roleId}).then((res)=>{ | 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 | } |