feat: 系统权限页批量拖拽排序 + 表单加父级/排序字段

- VxeTable 树形表格加行拖拽,拖完调用 /permission/sort 接口
- 表单弹窗新增父级权限选择(TreeSelect)和排序值输入
- 编辑时禁止选择自己及子孙节点作为父级
- 后端新增 POST /permission/sort 批量排序接口
This commit is contained in:
小蟑螂
2026-04-10 23:49:27 +08:00
parent 5f34c0b849
commit 068a0b96ea
3 changed files with 147 additions and 18 deletions
@@ -11,6 +11,7 @@ import { Button, message, Popconfirm, Space, Tag, Spin } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
batchSortPermissionApi,
deletePermissionApi,
getSystemPermissionTreeApi,
} from '#/api/system/permission';
@@ -103,6 +104,12 @@ const gridOptions: VxeGridProps<any> = {
showOverflow: true,
size: 'small',
expandAll: false,
rowConfig: {
drag: true,
},
rowDragConfig: {
isPeerDrag: false,
},
toolbarConfig: {
custom: true,
refresh: true,
@@ -134,7 +141,38 @@ const gridOptions: VxeGridProps<any> = {
};
// 表格实例
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
gridEvents: {
rowDragend: handleDragSort,
} as any,
});
// 防重调用标志
let isDragging = false;
// 处理拖拽排序
async function handleDragSort() {
if (isDragging) return;
isDragging = true;
try {
const vxeGrid = (gridApi as any).grid;
if (!vxeGrid) return;
const tableData = vxeGrid.getTableData?.()?.fullData || [];
if (!tableData.length) return;
// 按 tree 的顺序构建排序数据(VxeTable tree 内部已更新顺序)
const sortItems = tableData.map((item: any, index: number) => ({
permissionId: item.id,
sortOrder: index + 1,
}));
await batchSortPermissionApi(sortItems);
} catch (error: any) {
message.error(error?.message || '排序更新失败');
gridApi.reload();
} finally {
isDragging = false;
}
}
// 刷新表格
function refreshTable() {
@@ -195,7 +233,7 @@ const getTypeColor = (type: string) => {
<Page title="系统权限" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
系统管理模块下的完整权限树结构
平台完整权限树结构,支持拖拽排序
</div>
</template>