reactor:【system 系统管理】role 进一步统一代码风格
This commit is contained in:
@@ -76,8 +76,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||
try {
|
||||
// 加载部门列表
|
||||
await loadDeptTree();
|
||||
toggleExpandAll();
|
||||
// 设置表单值, 一定要在加载树之后
|
||||
handleExpandAll();
|
||||
// 设置表单值,一定要在加载树之后
|
||||
await formApi.setValues(await getRole(data.id));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
@@ -97,7 +97,7 @@ async function loadDeptTree() {
|
||||
}
|
||||
|
||||
/** 全选/全不选 */
|
||||
function toggleSelectAll() {
|
||||
function handleSelectAll() {
|
||||
isAllSelected.value = !isAllSelected.value;
|
||||
if (isAllSelected.value) {
|
||||
const allIds = getAllNodeIds(deptTree.value);
|
||||
@@ -108,14 +108,13 @@ function toggleSelectAll() {
|
||||
}
|
||||
|
||||
/** 展开/折叠所有节点 */
|
||||
function toggleExpandAll() {
|
||||
function handleExpandAll() {
|
||||
isExpanded.value = !isExpanded.value;
|
||||
// 获取所有节点的 ID
|
||||
expandedKeys.value = isExpanded.value ? getAllNodeIds(deptTree.value) : [];
|
||||
}
|
||||
|
||||
/** 切换父子联动 */
|
||||
function toggleCheckStrictly() {
|
||||
function handleCheckStrictly() {
|
||||
isCheckStrictly.value = !isCheckStrictly.value;
|
||||
}
|
||||
|
||||
@@ -132,15 +131,14 @@ function getAllNodeIds(nodes: any[], ids: number[] = []): number[] {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="数据权限" class="w-[40%]">
|
||||
<Modal title="数据权限" class="w-2/5">
|
||||
<Form class="mx-4">
|
||||
<template #dataScopeDeptIds="slotProps">
|
||||
<!-- <Spin :spinning="deptLoading"> -->
|
||||
<!-- TODO @芋艿:可优化,使用 antd 的 tree?原因是,更原生 -->
|
||||
<VbenTree
|
||||
:tree-data="deptTree"
|
||||
multiple
|
||||
bordered
|
||||
:spinning="deptLoading"
|
||||
:expanded="expandedKeys"
|
||||
v-bind="slotProps"
|
||||
value-field="id"
|
||||
@@ -148,20 +146,19 @@ function getAllNodeIds(nodes: any[], ids: number[] = []): number[] {
|
||||
:auto-check-parent="false"
|
||||
:check-strictly="!isCheckStrictly"
|
||||
/>
|
||||
<!-- </Spin> -->
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<ElCheckbox :model-value="isAllSelected" @change="toggleSelectAll">
|
||||
<ElCheckbox :model-value="isAllSelected" @change="handleSelectAll">
|
||||
全选
|
||||
</ElCheckbox>
|
||||
<ElCheckbox :model-value="isExpanded" @change="toggleExpandAll">
|
||||
<ElCheckbox :model-value="isExpanded" @change="handleExpandAll">
|
||||
全部展开
|
||||
</ElCheckbox>
|
||||
<ElCheckbox
|
||||
:model-value="isCheckStrictly"
|
||||
@change="toggleCheckStrictly"
|
||||
@change="handleCheckStrictly"
|
||||
>
|
||||
父子联动
|
||||
</ElCheckbox>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SystemDeptApi } from '#/api/system/dept';
|
||||
import type { Recordable } from '@vben-core/typings';
|
||||
|
||||
import type { SystemMenuApi } from '#/api/system/menu';
|
||||
import type { SystemRoleApi } from '#/api/system/role';
|
||||
|
||||
import { ref } from 'vue';
|
||||
import {nextTick, ref} from 'vue';
|
||||
|
||||
import { useVbenModal, VbenTree } from '@vben/common-ui';
|
||||
import { SystemMenuTypeEnum } from '@vben/constants';
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { ElCheckbox, ElMessage } from 'element-plus';
|
||||
@@ -18,7 +21,7 @@ import { useAssignMenuFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const menuTree = ref<SystemDeptApi.Dept[]>([]); // 菜单树
|
||||
const menuTree = ref<SystemMenuApi.Menu[]>([]); // 菜单树
|
||||
const menuLoading = ref(false); // 加载菜单列表
|
||||
const isAllSelected = ref(false); // 全选状态
|
||||
const isExpanded = ref(false); // 展开状态
|
||||
@@ -77,6 +80,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
|
||||
await formApi.setValues(data);
|
||||
} finally {
|
||||
await nextTick(); // 菜单过多,渲染较慢,需要等下一次事件循环
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
@@ -87,14 +91,14 @@ async function loadMenuTree() {
|
||||
menuLoading.value = true;
|
||||
try {
|
||||
const data = await getMenuList();
|
||||
menuTree.value = handleTree(data) as SystemDeptApi.Dept[];
|
||||
menuTree.value = handleTree(data) as SystemMenuApi.Menu[];
|
||||
} finally {
|
||||
menuLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 全选/全不选 */
|
||||
function toggleSelectAll() {
|
||||
function handleSelectAll() {
|
||||
isAllSelected.value = !isAllSelected.value;
|
||||
if (isAllSelected.value) {
|
||||
const allIds = getAllNodeIds(menuTree.value);
|
||||
@@ -105,9 +109,8 @@ function toggleSelectAll() {
|
||||
}
|
||||
|
||||
/** 展开/折叠所有节点 */
|
||||
function toggleExpandAll() {
|
||||
function handleExpandAll() {
|
||||
isExpanded.value = !isExpanded.value;
|
||||
// 获取所有节点的 ID
|
||||
expandedKeys.value = isExpanded.value ? getAllNodeIds(menuTree.value) : [];
|
||||
}
|
||||
|
||||
@@ -121,32 +124,44 @@ function getAllNodeIds(nodes: any[], ids: number[] = []): number[] {
|
||||
});
|
||||
return ids;
|
||||
}
|
||||
|
||||
function getNodeClass(node: Recordable<any>) {
|
||||
const classes: string[] = [];
|
||||
if (node.value?.type === SystemMenuTypeEnum.BUTTON) {
|
||||
classes.push('inline-flex');
|
||||
if (node.index % 3 >= 1) {
|
||||
classes.push('!pl-0');
|
||||
}
|
||||
}
|
||||
|
||||
return classes.join(' ');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="数据权限" class="w-[40%]">
|
||||
<Modal title="数据权限" class="w-2/5">
|
||||
<Form class="mx-4">
|
||||
<template #menuIds="slotProps">
|
||||
<!-- <Spin :spinning="menuLoading" class="w-full"> -->
|
||||
<!-- TODO @芋艿:可优化,使用 antd 的 tree?原因是,更原生 -->
|
||||
<VbenTree
|
||||
:spinning="menuLoading"
|
||||
:tree-data="menuTree"
|
||||
multiple
|
||||
bordered
|
||||
:expanded="expandedKeys"
|
||||
:get-node-class="getNodeClass"
|
||||
v-bind="slotProps"
|
||||
value-field="id"
|
||||
label-field="name"
|
||||
icon-field="meta.icon"
|
||||
/>
|
||||
<!-- </Spin> -->
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<ElCheckbox :model-value="isAllSelected" @change="toggleSelectAll">
|
||||
<ElCheckbox :model-value="isAllSelected" @change="handleSelectAll">
|
||||
全选
|
||||
</ElCheckbox>
|
||||
<ElCheckbox :model-value="isExpanded" @change="toggleExpandAll">
|
||||
<ElCheckbox :model-value="isExpanded" @change="handleExpandAll">
|
||||
全部展开
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user