2024-08-07 08:57:56 +08:00
|
|
|
<script setup lang="ts">
|
2024-10-05 15:35:58 +08:00
|
|
|
import type { Recordable } from '@vben/types';
|
2024-09-22 21:37:32 +08:00
|
|
|
|
2024-10-05 15:35:58 +08:00
|
|
|
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
|
|
|
|
import { listToTree } from '@vben/utils';
|
2024-09-24 11:23:02 +08:00
|
|
|
|
2024-10-05 15:35:58 +08:00
|
|
|
import { Popconfirm, Space } from 'ant-design-vue';
|
2024-09-24 11:23:02 +08:00
|
|
|
|
2024-10-05 15:35:58 +08:00
|
|
|
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
|
|
|
|
import { menuList, menuRemove } from '#/api/system/menu';
|
|
|
|
|
|
|
|
import { columns, querySchema } from './data';
|
2024-09-22 21:37:32 +08:00
|
|
|
import menuDrawer from './menu-drawer.vue';
|
|
|
|
|
2024-10-05 15:35:58 +08:00
|
|
|
const formOptions: VbenFormProps = {
|
2024-10-05 21:04:44 +08:00
|
|
|
commonConfig: {
|
|
|
|
labelWidth: 80,
|
|
|
|
},
|
2024-10-05 15:35:58 +08:00
|
|
|
schema: querySchema(),
|
|
|
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
|
|
|
};
|
|
|
|
|
|
|
|
const gridOptions: VxeGridProps = {
|
|
|
|
columns,
|
|
|
|
height: 'auto',
|
|
|
|
keepSource: true,
|
|
|
|
pagerConfig: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
proxyConfig: {
|
|
|
|
ajax: {
|
2024-10-06 09:53:00 +08:00
|
|
|
query: async (_, formValues = {}) => {
|
2024-10-05 15:35:58 +08:00
|
|
|
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 });
|
2024-09-22 21:37:32 +08:00
|
|
|
const [MenuDrawer, drawerApi] = useVbenDrawer({
|
|
|
|
connectedComponent: menuDrawer,
|
|
|
|
});
|
|
|
|
|
|
|
|
function handleAdd() {
|
2024-10-05 15:35:58 +08:00
|
|
|
drawerApi.setData({});
|
2024-09-22 21:37:32 +08:00
|
|
|
drawerApi.open();
|
|
|
|
}
|
2024-09-24 11:23:02 +08:00
|
|
|
|
2024-10-05 15:35:58 +08:00
|
|
|
async function handleEdit(record: Recordable<any>) {
|
|
|
|
drawerApi.setData({ id: record.menuId });
|
|
|
|
drawerApi.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleDelete(row: Recordable<any>) {
|
|
|
|
await menuRemove(row.menuId);
|
2024-10-05 21:04:44 +08:00
|
|
|
await tableApi.query();
|
2024-10-05 15:35:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function expandAll() {
|
|
|
|
tableApi.grid?.setAllTreeExpand(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function collapseAll() {
|
|
|
|
tableApi.grid?.setAllTreeExpand(false);
|
|
|
|
}
|
2024-08-07 08:57:56 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-10-05 15:35:58 +08:00
|
|
|
<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>
|
|
|
|
</Space>
|
|
|
|
</template>
|
|
|
|
<template #action="{ row }">
|
2024-10-06 09:53:00 +08:00
|
|
|
<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)"
|
|
|
|
>
|
2024-10-05 15:35:58 +08:00
|
|
|
<a-button
|
2024-10-06 09:53:00 +08:00
|
|
|
danger
|
2024-10-05 15:35:58 +08:00
|
|
|
size="small"
|
|
|
|
type="link"
|
2024-10-06 09:53:00 +08:00
|
|
|
v-access:code="['system:menu:remove']"
|
|
|
|
@click.stop=""
|
2024-10-05 15:35:58 +08:00
|
|
|
>
|
2024-10-06 09:53:00 +08:00
|
|
|
{{ $t('pages.common.delete') }}
|
2024-10-05 15:35:58 +08:00
|
|
|
</a-button>
|
2024-10-06 09:53:00 +08:00
|
|
|
</Popconfirm>
|
2024-10-05 15:35:58 +08:00
|
|
|
</template>
|
|
|
|
</BasicTable>
|
2024-10-05 21:04:44 +08:00
|
|
|
<MenuDrawer @reload="tableApi.query()" />
|
2024-09-22 21:37:32 +08:00
|
|
|
</Page>
|
2024-08-07 08:57:56 +08:00
|
|
|
</template>
|