feat: 菜单
This commit is contained in:
parent
e6fa2be3eb
commit
caf8681e24
@ -1,8 +1,9 @@
|
||||
import { DictEnum } from '@vben/constants';
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import { type FormSchemaGetter, z } from '#/adapter';
|
||||
import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter';
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
import { renderDict, renderIcon } from '#/utils/render';
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
@ -42,6 +43,90 @@ export const yesNoOptions = [
|
||||
{ label: '否', value: '1' },
|
||||
];
|
||||
|
||||
// (M目录 C菜单 F按钮)
|
||||
const menuTypes = {
|
||||
M: { value: '目录', icon: 'fxemoji:folder' },
|
||||
C: { value: '菜单', icon: 'fluent-emoji-flat:open-book' },
|
||||
F: { value: '按钮', icon: 'fluent-emoji:ok-button' },
|
||||
};
|
||||
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
{
|
||||
title: '菜单名称',
|
||||
field: 'menuName',
|
||||
treeNode: true,
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '图标',
|
||||
field: 'icon',
|
||||
width: 80,
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
if (row?.icon === '#') {
|
||||
return '';
|
||||
}
|
||||
return renderIcon(row.icon);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
field: 'orderNum',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '组件类型',
|
||||
field: 'menuType',
|
||||
width: 150,
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
const current = menuTypes[row.menuType as 'C' | 'F' | 'M'];
|
||||
return current as any;
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '权限标识',
|
||||
field: 'perms',
|
||||
},
|
||||
{
|
||||
title: '组件路径',
|
||||
field: 'component',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
field: 'status',
|
||||
width: 100,
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
return renderDict(row.status, DictEnum.SYS_NORMAL_DISABLE);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '显示',
|
||||
field: 'visible',
|
||||
width: 100,
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
return renderDict(row.visible, DictEnum.SYS_SHOW_HIDE);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
field: 'createTime',
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
|
||||
export const drawerSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
|
@ -1,55 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { Card } from 'ant-design-vue';
|
||||
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
|
||||
import { listToTree } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter';
|
||||
import { Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import { querySchema } from './data';
|
||||
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
|
||||
import { menuList, menuRemove } from '#/api/system/menu';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
import menuDrawer from './menu-drawer.vue';
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
},
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async (_, formValues) => {
|
||||
const resp = await menuList({
|
||||
...formValues,
|
||||
});
|
||||
const treeData = listToTree(resp, {
|
||||
id: 'menuId',
|
||||
pid: 'parentId',
|
||||
children: 'children',
|
||||
});
|
||||
return { rows: treeData };
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
isHover: true,
|
||||
keyField: 'menuId',
|
||||
},
|
||||
round: true,
|
||||
align: 'center',
|
||||
showOverflow: true,
|
||||
treeConfig: {
|
||||
parentField: 'parentId',
|
||||
rowField: 'menuId',
|
||||
transform: false,
|
||||
},
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||
const [MenuDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: menuDrawer,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({ update: false });
|
||||
drawerApi.setData({});
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
const [QueryForm] = useVbenForm({
|
||||
// 默认展开
|
||||
collapsed: false,
|
||||
// 所有表单项共用,可单独在表单内覆盖
|
||||
commonConfig: {
|
||||
// 所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
// 是否可展开
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
text: '查询',
|
||||
},
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
});
|
||||
async function handleEdit(record: Recordable<any>) {
|
||||
drawerApi.setData({ id: record.menuId });
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: Recordable<any>) {
|
||||
await menuRemove(row.menuId);
|
||||
await tableApi.reload();
|
||||
}
|
||||
|
||||
function expandAll() {
|
||||
tableApi.grid?.setAllTreeExpand(true);
|
||||
}
|
||||
|
||||
function collapseAll() {
|
||||
tableApi.grid?.setAllTreeExpand(false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page content-class="flex flex-col gap-4">
|
||||
<Card>
|
||||
<QueryForm />
|
||||
</Card>
|
||||
<Card>
|
||||
<div class="flex justify-end">
|
||||
<a-button type="primary" @click="handleAdd">
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable>
|
||||
<template #toolbar-actions>
|
||||
<span class="pl-[7px] text-[16px]">菜单权限列表</span>
|
||||
</template>
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button @click="collapseAll">
|
||||
{{ $t('pages.common.collapse') }}
|
||||
</a-button>
|
||||
<a-button @click="expandAll">
|
||||
{{ $t('pages.common.expand') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['system:menu:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</div>
|
||||
</Card>
|
||||
<MenuDrawer />
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<a-button
|
||||
size="small"
|
||||
type="link"
|
||||
v-access:code="['system:menu:edit']"
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</a-button>
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<a-button
|
||||
danger
|
||||
size="small"
|
||||
type="link"
|
||||
v-access:code="['system:menu:delete']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<MenuDrawer @reload="tableApi.reload()" />
|
||||
</Page>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user