feat: 菜单
This commit is contained in:
parent
e6fa2be3eb
commit
caf8681e24
@ -1,8 +1,9 @@
|
|||||||
import { DictEnum } from '@vben/constants';
|
import { DictEnum } from '@vben/constants';
|
||||||
import { getPopupContainer } from '@vben/utils';
|
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 { getDictOptions } from '#/utils/dict';
|
||||||
|
import { renderDict, renderIcon } from '#/utils/render';
|
||||||
|
|
||||||
export const querySchema: FormSchemaGetter = () => [
|
export const querySchema: FormSchemaGetter = () => [
|
||||||
{
|
{
|
||||||
@ -42,6 +43,90 @@ export const yesNoOptions = [
|
|||||||
{ label: '否', value: '1' },
|
{ 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 = () => [
|
export const drawerSchema: FormSchemaGetter = () => [
|
||||||
{
|
{
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
@ -1,55 +1,146 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
import type { Recordable } from '@vben/types';
|
||||||
import { $t } from '@vben/locales';
|
|
||||||
|
|
||||||
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';
|
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({
|
const [MenuDrawer, drawerApi] = useVbenDrawer({
|
||||||
connectedComponent: menuDrawer,
|
connectedComponent: menuDrawer,
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
drawerApi.setData({ update: false });
|
drawerApi.setData({});
|
||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
const [QueryForm] = useVbenForm({
|
async function handleEdit(record: Recordable<any>) {
|
||||||
// 默认展开
|
drawerApi.setData({ id: record.menuId });
|
||||||
collapsed: false,
|
drawerApi.open();
|
||||||
// 所有表单项共用,可单独在表单内覆盖
|
}
|
||||||
commonConfig: {
|
|
||||||
// 所有表单项
|
async function handleDelete(row: Recordable<any>) {
|
||||||
componentProps: {
|
await menuRemove(row.menuId);
|
||||||
class: 'w-full',
|
await tableApi.reload();
|
||||||
},
|
}
|
||||||
},
|
|
||||||
schema: querySchema(),
|
function expandAll() {
|
||||||
// 是否可展开
|
tableApi.grid?.setAllTreeExpand(true);
|
||||||
showCollapseButton: true,
|
}
|
||||||
submitButtonOptions: {
|
|
||||||
text: '查询',
|
function collapseAll() {
|
||||||
},
|
tableApi.grid?.setAllTreeExpand(false);
|
||||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
}
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page content-class="flex flex-col gap-4">
|
<Page :auto-content-height="true">
|
||||||
<Card>
|
<BasicTable>
|
||||||
<QueryForm />
|
<template #toolbar-actions>
|
||||||
</Card>
|
<span class="pl-[7px] text-[16px]">菜单权限列表</span>
|
||||||
<Card>
|
</template>
|
||||||
<div class="flex justify-end">
|
<template #toolbar-tools>
|
||||||
<a-button type="primary" @click="handleAdd">
|
<Space>
|
||||||
{{ $t('pages.common.add') }}
|
<a-button @click="collapseAll">
|
||||||
</a-button>
|
{{ $t('pages.common.collapse') }}
|
||||||
</div>
|
</a-button>
|
||||||
</Card>
|
<a-button @click="expandAll">
|
||||||
<MenuDrawer />
|
{{ $t('pages.common.expand') }}
|
||||||
|
</a-button>
|
||||||
|
<a-button
|
||||||
|
type="primary"
|
||||||
|
v-access:code="['system:menu:add']"
|
||||||
|
@click="handleAdd"
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.add') }}
|
||||||
|
</a-button>
|
||||||
|
</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>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user