fix: 修复角色修改时VbenTree组件没有回显选中 (#6662)

* fix: 修复角色修改时VbenTree组件没有回显选中

* chore: use nextTick

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix: merge

* chore: 更新

---------

Co-authored-by: haiyinlong <haiyinlong@uhigame.com>
Co-authored-by: Jin Mao <50581550+jinmao88@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Ken Hai
2025-08-21 15:30:58 +08:00
committed by GitHub
parent 2cc78f925f
commit ffaf85c8f3

View File

@@ -5,7 +5,7 @@ import type { Recordable } from '@vben/types';
import type { SystemRoleApi } from '#/api/system/role'; import type { SystemRoleApi } from '#/api/system/role';
import { computed, ref } from 'vue'; import { computed, nextTick, ref } from 'vue';
import { useVbenDrawer, VbenTree } from '@vben/common-ui'; import { useVbenDrawer, VbenTree } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons'; import { IconifyIcon } from '@vben/icons';
@@ -47,20 +47,26 @@ const [Drawer, drawerApi] = useVbenDrawer({
drawerApi.unlock(); drawerApi.unlock();
}); });
}, },
onOpenChange(isOpen) {
async onOpenChange(isOpen) {
if (isOpen) { if (isOpen) {
const data = drawerApi.getData<SystemRoleApi.SystemRole>(); const data = drawerApi.getData<SystemRoleApi.SystemRole>();
formApi.resetForm(); formApi.resetForm();
if (data) { if (data) {
formData.value = data; formData.value = data;
id.value = data.id; id.value = data.id;
formApi.setValues(data);
} else { } else {
id.value = undefined; id.value = undefined;
} }
if (permissions.value.length === 0) { if (permissions.value.length === 0) {
loadPermissions(); await loadPermissions();
}
// Wait for Vue to flush DOM updates (form fields mounted)
await nextTick();
if (data) {
formApi.setValues(data);
} }
} }
}, },