!8 fix: 修复el-tree组件setCheckedKeys设置一旦选中父级子级也被选中

Merge pull request !8 from 当时明月在/master-fix-tree
This commit is contained in:
芋道源码 2023-03-03 16:21:50 +00:00 committed by Gitee
commit e205995d11
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 13 additions and 9 deletions

View File

@ -122,7 +122,6 @@
ref="treeRef" ref="treeRef"
node-key="id" node-key="id"
show-checkbox show-checkbox
:default-checked-keys="defaultCheckedKeys"
:check-strictly="!checkStrictly" :check-strictly="!checkStrictly"
:props="defaultProps" :props="defaultProps"
:data="treeOptions" :data="treeOptions"
@ -245,7 +244,6 @@ const dialogScopeVisible = ref(false)
const dialogScopeTitle = ref('数据权限') const dialogScopeTitle = ref('数据权限')
const actionScopeType = ref('') const actionScopeType = ref('')
const dataScopeDictDatas = ref() const dataScopeDictDatas = ref()
const defaultCheckedKeys = ref()
// //
const checkStrictly = ref(true) const checkStrictly = ref(true)
const treeNodeAll = ref(false) const treeNodeAll = ref(false)
@ -258,13 +256,17 @@ const handleScope = async (type: string, row: RoleApi.RoleVO) => {
dataScopeForm.id = row.id dataScopeForm.id = row.id
dataScopeForm.name = row.name dataScopeForm.name = row.name
dataScopeForm.code = row.code dataScopeForm.code = row.code
actionScopeType.value = type
dialogScopeVisible.value = true
if (type === 'menu') { if (type === 'menu') {
const menuRes = await listSimpleMenusApi() const menuRes = await listSimpleMenusApi()
treeOptions.value = handleTree(menuRes) treeOptions.value = handleTree(menuRes)
const role = await PermissionApi.listRoleMenusApi(row.id) const role = await PermissionApi.listRoleMenusApi(row.id)
if (role) { if (role) {
// treeRef.value!.setCheckedKeys(role as unknown as Array<number>) role?.forEach((item: any) => {
defaultCheckedKeys.value = role unref(treeRef)?.setChecked(item, true,false);
})
} }
} else if (type === 'data') { } else if (type === 'data') {
const deptRes = await listSimpleDeptApi() const deptRes = await listSimpleDeptApi()
@ -272,12 +274,12 @@ const handleScope = async (type: string, row: RoleApi.RoleVO) => {
const role = await RoleApi.getRoleApi(row.id) const role = await RoleApi.getRoleApi(row.id)
dataScopeForm.dataScope = role.dataScope dataScopeForm.dataScope = role.dataScope
if (role.dataScopeDeptIds) { if (role.dataScopeDeptIds) {
// treeRef.value!.setCheckedKeys(role.dataScopeDeptIds as unknown as Array<number>, false) role.dataScopeDeptIds?.forEach((item: any) => {
defaultCheckedKeys.value = role.dataScopeDeptIds unref(treeRef)?.setChecked(item, true,false);
})
} }
} }
actionScopeType.value = type
dialogScopeVisible.value = true
} }
// //
const submitScope = async () => { const submitScope = async () => {

View File

@ -125,7 +125,9 @@ const handleUpdate = async (rowId: number) => {
const res = await TenantPackageApi.getTenantPackageApi(rowId) const res = await TenantPackageApi.getTenantPackageApi(rowId)
unref(formRef)?.setValues(res) unref(formRef)?.setValues(res)
// //
unref(treeRef)?.setCheckedKeys(res.menuIds) res.menuIds?.forEach((item: any) => {
unref(treeRef)?.setChecked(item, true,false);
})
} }
// //