Skip to content

Commit 0b9022c

Browse files
committed
fix: 修复el-tree组件setCheckedKeys设置一旦选中父级子级也被选中
1 parent 3e2b5e1 commit 0b9022c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/views/system/role/index.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
ref="treeRef"
123123
node-key="id"
124124
show-checkbox
125-
:default-checked-keys="defaultCheckedKeys"
126125
:check-strictly="!checkStrictly"
127126
:props="defaultProps"
128127
:data="treeOptions"
@@ -245,7 +244,6 @@ const dialogScopeVisible = ref(false)
245244
const dialogScopeTitle = ref('数据权限')
246245
const actionScopeType = ref('')
247246
const dataScopeDictDatas = ref()
248-
const defaultCheckedKeys = ref()
249247
// 选项
250248
const checkStrictly = ref(true)
251249
const treeNodeAll = ref(false)
@@ -258,26 +256,30 @@ const handleScope = async (type: string, row: RoleApi.RoleVO) => {
258256
dataScopeForm.id = row.id
259257
dataScopeForm.name = row.name
260258
dataScopeForm.code = row.code
259+
260+
actionScopeType.value = type
261+
dialogScopeVisible.value = true
261262
if (type === 'menu') {
262263
const menuRes = await listSimpleMenusApi()
263264
treeOptions.value = handleTree(menuRes)
264265
const role = await PermissionApi.listRoleMenusApi(row.id)
265266
if (role) {
266-
// treeRef.value!.setCheckedKeys(role as unknown as Array<number>)
267-
defaultCheckedKeys.value = role
267+
role?.forEach((item: any) => {
268+
unref(treeRef)?.setChecked(item, true,false);
269+
})
268270
}
269271
} else if (type === 'data') {
270272
const deptRes = await listSimpleDeptApi()
271273
treeOptions.value = handleTree(deptRes)
272274
const role = await RoleApi.getRoleApi(row.id)
273275
dataScopeForm.dataScope = role.dataScope
274276
if (role.dataScopeDeptIds) {
275-
// treeRef.value!.setCheckedKeys(role.dataScopeDeptIds as unknown as Array<number>, false)
276-
defaultCheckedKeys.value = role.dataScopeDeptIds
277+
role.dataScopeDeptIds?.forEach((item: any) => {
278+
unref(treeRef)?.setChecked(item, true,false);
279+
})
277280
}
278281
}
279-
actionScopeType.value = type
280-
dialogScopeVisible.value = true
282+
281283
}
282284
// 保存权限
283285
const submitScope = async () => {

0 commit comments

Comments
 (0)