feat: 新增右键菜单二次封装 系统菜单和权限使用

This commit is contained in:
2026-08-16 10:21:12 +08:00
parent e5565956ba
commit ce349a5ec7
7 changed files with 432 additions and 48 deletions
@@ -7,7 +7,7 @@ import { onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon, IconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { Button, message, Modal, Popconfirm, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@@ -15,6 +15,10 @@ import {
deleteMenuApi,
getAllMenusApi,
} from '#/api/sys/menu';
import {
useVxeRowContextMenu,
VxeRowContextMenu,
} from '#/components/vxe-row-context-menu';
import MenuFormModal from './components/MenuFormModal.vue';
@@ -141,6 +145,12 @@ const gridOptions: VxeGridProps<any> = {
rowField: 'id',
parentField: 'parentId',
},
// 启用 cell-menu 事件,但隐藏 Vxe 原生面板(由 Ant Design 二次封装接管)
menuConfig: {
enabled: true,
trigger: 'cell',
visibleMethod: () => false,
},
// 配置远程加载
proxyConfig: {
ajax: {
@@ -237,6 +247,62 @@ async function handleDelete(record: MenuVO.MenuInfo) {
}
}
function confirmDeleteMenu(record: MenuVO.MenuInfo) {
Modal.confirm({
title: '确定要删除这个菜单吗?',
content: record.title || record.name || `ID ${record.id}`,
okText: '删除',
okType: 'danger',
cancelText: '取消',
onOk: () => handleDelete(record),
});
}
const {
open: ctxMenuOpen,
x: ctxMenuX,
y: ctxMenuY,
row: ctxMenuRow,
items: ctxMenuItems,
onCellMenu,
} = useVxeRowContextMenu<MenuVO.MenuInfo>((_row) => [
{
key: 'addChild',
label: '新增',
icon: PlusCircleIcon,
},
{
key: 'edit',
label: '编辑',
icon: EditIcon,
},
{
key: 'delete',
label: '删除',
icon: TrashIcon,
danger: true,
},
]);
function handleCtxMenuSelect(key: string) {
const row = ctxMenuRow.value;
if (!row) return;
switch (key) {
case 'addChild': {
handleAddChild(row);
break;
}
case 'edit': {
handleEdit(row);
break;
}
case 'delete': {
confirmDeleteMenu(row);
break;
}
}
}
// 处理模态框成功:更新菜单只合并当前行;新建仍整表刷新
function handleModalSuccess(
payload?: { mode: 'update'; menu: MenuVO.MenuInfo } | { mode: 'create' },
@@ -341,6 +407,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
gridEvents: {
// 拖拽排序事件
rowDragend: handleDragSort,
cellMenu: onCellMenu,
} as any,
});
@@ -386,7 +453,7 @@ onMounted(() => {
全部收起
</Button>
<div class="text-sm text-gray-500">
💡 提示:可直接拖拽菜单名称列进行排序
💡 可拖拽菜单名称列排序;右键行可编辑 / 增下级 / 删除
</div>
</Space>
</template>
@@ -463,6 +530,14 @@ onMounted(() => {
<!-- 菜单表单模态框 -->
<MenuFormModal ref="menuFormModalRef" @success="handleModalSuccess" />
<VxeRowContextMenu
v-model:open="ctxMenuOpen"
:x="ctxMenuX"
:y="ctxMenuY"
:items="ctxMenuItems"
@select="handleCtxMenuSelect"
/>
</Page>
</template>