diff --git a/src/modules/iam/pages/RolesView.test.ts b/src/modules/iam/pages/RolesView.test.ts index a6abbfc4..af2ce3ae 100644 --- a/src/modules/iam/pages/RolesView.test.ts +++ b/src/modules/iam/pages/RolesView.test.ts @@ -101,6 +101,12 @@ describe('RolesView', () => { expect(rolesSource).not.toContain("disabled: 'disabled'") }) + it('restores saved permission ids after the dialog tree has mounted', () => { + expect(rolesSource).toContain('@opened="initializePermissionSelection"') + expect(rolesSource).toContain('treeRef.value?.setCheckedKeys([...form.permissionIds])') + expect(rolesSource).not.toContain('nextTick(() =>') + }) + it('shows the role code in the default list layout', () => { expect(rolesSource).toContain("{ key: 'roleCode', prop: 'code', label: '角色编码', minWidth: 180, showOverflowTooltip: true }") expect(rolesSource).toContain(' -import { computed, nextTick, onMounted, reactive, ref } from 'vue' +import { computed, onMounted, reactive, ref } from 'vue' import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus' import { Pencil, Plus, Power, ShieldCheck, Trash2 } from '@lucide/vue' import { @@ -136,14 +136,17 @@ function openCreate() { Object.assign(form, emptyForm()) captureBaseline() editorOpen.value = true - nextTick(() => { formRef.value?.clearValidate(); treeRef.value?.setCheckedKeys([]) }) } function openEdit(row: Role) { if (!canEdit.value && !canGrant.value) return Object.assign(form, { ...row, permissionIds: [...row.permissionIds] }) captureBaseline() editorOpen.value = true - nextTick(() => { formRef.value?.clearValidate(); treeRef.value?.setCheckedKeys([...row.permissionIds]) }) +} + +function initializePermissionSelection() { + formRef.value?.clearValidate() + treeRef.value?.setCheckedKeys([...form.permissionIds]) } function selectedPermissionIds() { @@ -253,7 +256,7 @@ onMounted(loadRoles) - +