reactor:【system 系统管理】menu 进一步统一代码风格
parent
3564c123a1
commit
2becb1b09d
|
@ -271,6 +271,7 @@ export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['colum
|
||||||
{
|
{
|
||||||
field: 'name',
|
field: 'name',
|
||||||
title: '菜单名称',
|
title: '菜单名称',
|
||||||
|
minWidth: 250,
|
||||||
align: 'left',
|
align: 'left',
|
||||||
fixed: 'left',
|
fixed: 'left',
|
||||||
slots: { default: 'name' },
|
slots: { default: 'name' },
|
||||||
|
@ -279,6 +280,7 @@ export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['colum
|
||||||
{
|
{
|
||||||
field: 'type',
|
field: 'type',
|
||||||
title: '菜单类型',
|
title: '菜单类型',
|
||||||
|
minWidth: 100,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellDict',
|
name: 'CellDict',
|
||||||
props: { type: DICT_TYPE.SYSTEM_MENU_TYPE },
|
props: { type: DICT_TYPE.SYSTEM_MENU_TYPE },
|
||||||
|
@ -287,22 +289,27 @@ export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['colum
|
||||||
{
|
{
|
||||||
field: 'sort',
|
field: 'sort',
|
||||||
title: '显示排序',
|
title: '显示排序',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'permission',
|
field: 'permission',
|
||||||
title: '权限标识',
|
title: '权限标识',
|
||||||
|
minWidth: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'path',
|
field: 'path',
|
||||||
title: '组件路径',
|
title: '组件路径',
|
||||||
|
minWidth: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'componentName',
|
field: 'componentName',
|
||||||
title: '组件名称',
|
title: '组件名称',
|
||||||
|
minWidth: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'status',
|
field: 'status',
|
||||||
title: '状态',
|
title: '状态',
|
||||||
|
minWidth: 100,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellDict',
|
name: 'CellDict',
|
||||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||||
|
|
|
@ -23,7 +23,7 @@ const [FormModal, formModalApi] = useVbenModal({
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 刷新表格 */
|
/** 刷新表格 */
|
||||||
function onRefresh() {
|
function handleRefresh() {
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ function handleCreate() {
|
||||||
|
|
||||||
/** 添加下级菜单 */
|
/** 添加下级菜单 */
|
||||||
function handleAppend(row: SystemMenuApi.Menu) {
|
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) {
|
async function handleDelete(row: SystemMenuApi.Menu) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||||
key: 'action_key_msg',
|
duration: 0,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteMenu(row.id as number);
|
await deleteMenu(row.id as number);
|
||||||
message.success({
|
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||||
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
handleRefresh();
|
||||||
key: 'action_key_msg',
|
|
||||||
});
|
|
||||||
onRefresh();
|
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
|
@ -62,7 +59,7 @@ async function handleDelete(row: SystemMenuApi.Menu) {
|
||||||
|
|
||||||
/** 切换树形展开/收缩状态 */
|
/** 切换树形展开/收缩状态 */
|
||||||
const isExpanded = ref(false);
|
const isExpanded = ref(false);
|
||||||
function toggleExpand() {
|
function handleExpand() {
|
||||||
isExpanded.value = !isExpanded.value;
|
isExpanded.value = !isExpanded.value;
|
||||||
gridApi.grid.setAllTreeExpand(isExpanded.value);
|
gridApi.grid.setAllTreeExpand(isExpanded.value);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +81,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
},
|
},
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
keyField: 'id',
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: true,
|
refresh: true,
|
||||||
|
@ -94,7 +92,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
transform: true,
|
transform: true,
|
||||||
reserve: true,
|
reserve: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions,
|
} as VxeTableGridOptions<SystemMenuApi.Menu>,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -108,8 +106,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<DocAlert title="菜单路由" url="https://doc.iocoder.cn/vue3/route/" />
|
<DocAlert title="菜单路由" url="https://doc.iocoder.cn/vue3/route/" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="handleRefresh" />
|
||||||
<Grid>
|
<Grid table-title="菜单列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<TableAction
|
<TableAction
|
||||||
:actions="[
|
:actions="[
|
||||||
|
@ -123,7 +121,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
{
|
{
|
||||||
label: isExpanded ? '收缩' : '展开',
|
label: isExpanded ? '收缩' : '展开',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
onClick: toggleExpand,
|
onClick: handleExpand,
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -59,21 +59,22 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载数据
|
// 加载数据
|
||||||
let data = modalApi.getData<SystemMenuApi.Menu>();
|
const data = modalApi.getData<SystemMenuApi.Menu>();
|
||||||
if (!data) {
|
if (!data || !data.id) {
|
||||||
|
// 设置上级
|
||||||
|
await formApi.setValues(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.id) {
|
modalApi.lock();
|
||||||
modalApi.lock();
|
try {
|
||||||
try {
|
formData.value = await getMenu(data.id);
|
||||||
data = await getMenu(data.id);
|
// 设置到 values
|
||||||
} finally {
|
if (formData.value) {
|
||||||
modalApi.unlock();
|
await formApi.setValues(formData.value);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
// 设置到 values
|
|
||||||
formData.value = data;
|
|
||||||
await formApi.setValues(formData.value);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -46,7 +46,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
// TODO @xingyu:【重要】这个字段出不来
|
|
||||||
{
|
{
|
||||||
fieldName: 'deptId',
|
fieldName: 'deptId',
|
||||||
label: '归属部门',
|
label: '归属部门',
|
||||||
|
@ -228,7 +227,6 @@ export function useImportFormSchema(): VbenFormSchema[] {
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
help: '仅允许导入 xls、xlsx 格式文件',
|
help: '仅允许导入 xls、xlsx 格式文件',
|
||||||
},
|
},
|
||||||
// TODO @xingyu:【重要】看不到 switch 这个按钮
|
|
||||||
{
|
{
|
||||||
fieldName: 'updateSupport',
|
fieldName: 'updateSupport',
|
||||||
label: '是否覆盖',
|
label: '是否覆盖',
|
||||||
|
|
|
@ -45,7 +45,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
} as SystemMenuApi.Menu);
|
} as SystemMenuApi.Menu);
|
||||||
return handleTree(data);
|
return handleTree(data);
|
||||||
},
|
},
|
||||||
checkStrictly: true,
|
|
||||||
labelField: 'name',
|
labelField: 'name',
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
childrenField: 'children',
|
childrenField: 'children',
|
||||||
|
@ -271,7 +270,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
/** 列表的字段 */
|
/** 列表的字段 */
|
||||||
export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['columns'] {
|
export function useGridColumns(): VxeTableGridOptions<SystemMenuApi.Menu>['columns'] {
|
||||||
return [
|
return [
|
||||||
{ type: 'checkbox', width: 40 },
|
|
||||||
{
|
{
|
||||||
field: 'name',
|
field: 'name',
|
||||||
title: '菜单名称',
|
title: '菜单名称',
|
||||||
|
|
|
@ -4,15 +4,14 @@ import type { SystemMenuApi } from '#/api/system/menu';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
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 { SystemMenuTypeEnum } from '@vben/constants';
|
||||||
import { IconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
import { isEmpty } from '@vben/utils';
|
|
||||||
|
|
||||||
import { ElLoading, ElMessage } from 'element-plus';
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
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 { $t } from '#/locales';
|
||||||
|
|
||||||
import { useGridColumns } from './data';
|
import { useGridColumns } from './data';
|
||||||
|
@ -30,7 +29,7 @@ function handleRefresh() {
|
||||||
|
|
||||||
/** 创建菜单 */
|
/** 创建菜单 */
|
||||||
function handleCreate() {
|
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);
|
const isExpanded = ref(false);
|
||||||
function handleExpand() {
|
function handleExpand() {
|
||||||
|
@ -110,7 +84,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: true,
|
refresh: true,
|
||||||
search: true,
|
|
||||||
},
|
},
|
||||||
treeConfig: {
|
treeConfig: {
|
||||||
parentField: 'parentId',
|
parentField: 'parentId',
|
||||||
|
@ -119,10 +92,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
reserve: true,
|
reserve: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<SystemMenuApi.Menu>,
|
} as VxeTableGridOptions<SystemMenuApi.Menu>,
|
||||||
gridEvents: {
|
|
||||||
checkboxAll: handleRowCheckboxChange,
|
|
||||||
checkboxChange: handleRowCheckboxChange,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -153,14 +122,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
onClick: handleExpand,
|
onClick: handleExpand,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: $t('ui.actionTitle.deleteBatch'),
|
|
||||||
type: 'danger',
|
|
||||||
icon: ACTION_ICON.DELETE,
|
|
||||||
auth: ['system:menu:delete'],
|
|
||||||
disabled: isEmpty(checkedIds),
|
|
||||||
onClick: handleDeleteBatch,
|
|
||||||
},
|
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue