reactor:【system 系统管理】menu 进一步统一代码风格

pull/210/head
YunaiV 2025-09-08 22:53:18 +08:00
parent 3564c123a1
commit 2becb1b09d
6 changed files with 33 additions and 70 deletions

View File

@ -271,6 +271,7 @@ export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['colum
{
field: 'name',
title: '菜单名称',
minWidth: 250,
align: 'left',
fixed: 'left',
slots: { default: 'name' },
@ -279,6 +280,7 @@ export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['colum
{
field: 'type',
title: '菜单类型',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.SYSTEM_MENU_TYPE },
@ -287,22 +289,27 @@ export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['colum
{
field: 'sort',
title: '显示排序',
minWidth: 100,
},
{
field: 'permission',
title: '权限标识',
minWidth: 200,
},
{
field: 'path',
title: '组件路径',
minWidth: 200,
},
{
field: 'componentName',
title: '组件名称',
minWidth: 200,
},
{
field: 'status',
title: '状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },

View File

@ -23,7 +23,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@ -34,7 +34,7 @@ function handleCreate() {
/** 添加下级菜单 */
function handleAppend(row: SystemMenuApi.Menu) {
formModalApi.setData({ pid: row.id }).open();
formModalApi.setData({ parentId: row.id }).open();
}
/** 编辑菜单 */
@ -46,15 +46,12 @@ function handleEdit(row: SystemMenuApi.Menu) {
async function handleDelete(row: SystemMenuApi.Menu) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
duration: 0,
});
try {
await deleteMenu(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
@ -62,7 +59,7 @@ async function handleDelete(row: SystemMenuApi.Menu) {
/** 切换树形展开/收缩状态 */
const isExpanded = ref(false);
function toggleExpand() {
function handleExpand() {
isExpanded.value = !isExpanded.value;
gridApi.grid.setAllTreeExpand(isExpanded.value);
}
@ -84,6 +81,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@ -94,7 +92,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
transform: true,
reserve: true,
},
} as VxeTableGridOptions,
} as VxeTableGridOptions<SystemMenuApi.Menu>,
});
</script>
@ -108,8 +106,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="菜单路由" url="https://doc.iocoder.cn/vue3/route/" />
</template>
<FormModal @success="onRefresh" />
<Grid>
<FormModal @success="handleRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
@ -123,7 +121,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
{
label: isExpanded ? '收缩' : '展开',
type: 'primary',
onClick: toggleExpand,
onClick: handleExpand,
},
]"
/>

View File

@ -59,21 +59,22 @@ const [Modal, modalApi] = useVbenModal({
return;
}
//
let data = modalApi.getData<SystemMenuApi.Menu>();
if (!data) {
const data = modalApi.getData<SystemMenuApi.Menu>();
if (!data || !data.id) {
//
await formApi.setValues(data);
return;
}
if (data.id) {
modalApi.lock();
try {
data = await getMenu(data.id);
} finally {
modalApi.unlock();
modalApi.lock();
try {
formData.value = await getMenu(data.id);
// values
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
// values
formData.value = data;
await formApi.setValues(formData.value);
},
});
</script>

View File

@ -46,7 +46,6 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'Input',
rules: 'required',
},
// TODO @xingyu【重要】这个字段出不来
{
fieldName: 'deptId',
label: '归属部门',
@ -228,7 +227,6 @@ export function useImportFormSchema(): VbenFormSchema[] {
rules: 'required',
help: '仅允许导入 xls、xlsx 格式文件',
},
// TODO @xingyu【重要】看不到 switch 这个按钮
{
fieldName: 'updateSupport',
label: '是否覆盖',

View File

@ -45,7 +45,6 @@ export function useFormSchema(): VbenFormSchema[] {
} as SystemMenuApi.Menu);
return handleTree(data);
},
checkStrictly: true,
labelField: 'name',
valueField: 'id',
childrenField: 'children',
@ -271,7 +270,6 @@ export function useFormSchema(): VbenFormSchema[] {
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'name',
title: '菜单名称',

View File

@ -4,15 +4,14 @@ import type { SystemMenuApi } from '#/api/system/menu';
import { ref } from 'vue';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { SystemMenuTypeEnum } from '@vben/constants';
import { IconifyIcon } from '@vben/icons';
import { isEmpty } from '@vben/utils';
import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteMenu, deleteMenuList, getMenuList } from '#/api/system/menu';
import { deleteMenu, getMenuList } from '#/api/system/menu';
import { $t } from '#/locales';
import { useGridColumns } from './data';
@ -30,7 +29,7 @@ function handleRefresh() {
/** 创建菜单 */
function handleCreate() {
formModalApi.setData(null).open();
formModalApi.setData({}).open();
}
/** 添加下级菜单 */
@ -57,31 +56,6 @@ async function handleDelete(row: SystemMenuApi.Menu) {
}
}
/** 批量删除菜单 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deletingBatch'),
});
try {
await deleteMenuList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
loadingInstance.close();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemMenuApi.Menu[];
}) {
checkedIds.value = records.map((item) => item.id!);
}
/** 切换树形展开/收缩状态 */
const isExpanded = ref(false);
function handleExpand() {
@ -110,7 +84,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
toolbarConfig: {
refresh: true,
search: true,
},
treeConfig: {
parentField: 'parentId',
@ -119,10 +92,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
reserve: true,
},
} as VxeTableGridOptions<SystemMenuApi.Menu>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
@ -153,14 +122,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'primary',
onClick: handleExpand,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'danger',
icon: ACTION_ICON.DELETE,
auth: ['system:menu:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
/>
</template>