优化
This commit is contained in:
@@ -101,6 +101,12 @@ describe('RolesView', () => {
|
|||||||
expect(rolesSource).not.toContain("disabled: 'disabled'")
|
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', () => {
|
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("{ key: 'roleCode', prop: 'code', label: '角色编码', minWidth: 180, showOverflowTooltip: true }")
|
||||||
expect(rolesSource).toContain('<el-form-item label="角色编码"')
|
expect(rolesSource).toContain('<el-form-item label="角色编码"')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
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 { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||||
import { Pencil, Plus, Power, ShieldCheck, Trash2 } from '@lucide/vue'
|
import { Pencil, Plus, Power, ShieldCheck, Trash2 } from '@lucide/vue'
|
||||||
import {
|
import {
|
||||||
@@ -136,14 +136,17 @@ function openCreate() {
|
|||||||
Object.assign(form, emptyForm())
|
Object.assign(form, emptyForm())
|
||||||
captureBaseline()
|
captureBaseline()
|
||||||
editorOpen.value = true
|
editorOpen.value = true
|
||||||
nextTick(() => { formRef.value?.clearValidate(); treeRef.value?.setCheckedKeys([]) })
|
|
||||||
}
|
}
|
||||||
function openEdit(row: Role) {
|
function openEdit(row: Role) {
|
||||||
if (!canEdit.value && !canGrant.value) return
|
if (!canEdit.value && !canGrant.value) return
|
||||||
Object.assign(form, { ...row, permissionIds: [...row.permissionIds] })
|
Object.assign(form, { ...row, permissionIds: [...row.permissionIds] })
|
||||||
captureBaseline()
|
captureBaseline()
|
||||||
editorOpen.value = true
|
editorOpen.value = true
|
||||||
nextTick(() => { formRef.value?.clearValidate(); treeRef.value?.setCheckedKeys([...row.permissionIds]) })
|
}
|
||||||
|
|
||||||
|
function initializePermissionSelection() {
|
||||||
|
formRef.value?.clearValidate()
|
||||||
|
treeRef.value?.setCheckedKeys([...form.permissionIds])
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectedPermissionIds() {
|
function selectedPermissionIds() {
|
||||||
@@ -253,7 +256,7 @@ onMounted(loadRoles)
|
|||||||
</section>
|
</section>
|
||||||
</ListPageLayout>
|
</ListPageLayout>
|
||||||
|
|
||||||
<AppDialog v-model="editorOpen" :title="form.id ? '配置角色' : '新增角色'" width="min(860px, calc(100vw - 28px))" class="role-editor-dialog" :confirm-loading="saving" confirm-text="保存角色" :show-confirm="form.id ? canEdit || canGrant : canCreate" destroy-on-close @confirm="saveRole">
|
<AppDialog v-model="editorOpen" :title="form.id ? '配置角色' : '新增角色'" width="min(860px, calc(100vw - 28px))" class="role-editor-dialog" :confirm-loading="saving" confirm-text="保存角色" :show-confirm="form.id ? canEdit || canGrant : canCreate" destroy-on-close @opened="initializePermissionSelection" @confirm="saveRole">
|
||||||
<el-form ref="formRef" :model="form" :rules="formRules" label-position="top" class="role-editor-form">
|
<el-form ref="formRef" :model="form" :rules="formRules" label-position="top" class="role-editor-form">
|
||||||
<div class="role-editor-layout">
|
<div class="role-editor-layout">
|
||||||
<FormSection title="基本信息" description="维护角色名称、编码和职责说明。" class="role-editor-basic">
|
<FormSection title="基本信息" description="维护角色名称、编码和职责说明。" class="role-editor-basic">
|
||||||
|
|||||||
Reference in New Issue
Block a user