mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
feat: 菜单权限管理
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
export * from './auth';
|
||||
export * from './menu';
|
||||
export * from './organization';
|
||||
export * from './user';
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MenuApi {
|
||||
/** 菜单信息 */
|
||||
export interface MenuInfo {
|
||||
id: number;
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
children?: MenuInfo[];
|
||||
}
|
||||
|
||||
/** 创建菜单参数 */
|
||||
export interface CreateMenuParams {
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
}
|
||||
|
||||
/** 更新菜单参数 */
|
||||
export interface UpdateMenuParams {
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单树
|
||||
*/
|
||||
export async function getMenuTreeApi() {
|
||||
return requestClient.get<MenuApi.MenuInfo[]>('/menu/tree');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单
|
||||
*/
|
||||
export async function getAllMenusApi() {
|
||||
return requestClient.get<MenuApi.MenuInfo[]>('/menu/list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单详情
|
||||
*/
|
||||
export async function getMenuDetailApi(id: number) {
|
||||
return requestClient.get<MenuApi.MenuInfo>(`/menu/detail/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*/
|
||||
export async function createMenuApi(data: MenuApi.CreateMenuParams) {
|
||||
return requestClient.post<MenuApi.MenuInfo>('/menu/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*/
|
||||
export async function updateMenuApi(id: number, data: MenuApi.UpdateMenuParams) {
|
||||
return requestClient.put<MenuApi.MenuInfo>(`/menu/update/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
export async function deleteMenuApi(id: number) {
|
||||
return requestClient.delete<void>(`/menu/delete/${id}`);
|
||||
}
|
||||
+12
-5
@@ -10,35 +10,35 @@ import type { MenuDTO, MenuVO } from './types';
|
||||
* 获取菜单树
|
||||
*/
|
||||
export async function getMenuTreeApi() {
|
||||
return requestClient.get<MenuVO.MenuInfoVO[]>('/menu/tree');
|
||||
return requestClient.get<MenuVO.MenuInfo[]>('/menu/tree');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单
|
||||
*/
|
||||
export async function getAllMenusApi() {
|
||||
return requestClient.get<MenuVO.MenuInfoVO[]>('/menu/list');
|
||||
return requestClient.get<MenuVO.MenuInfo[]>('/menu/list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单详情
|
||||
*/
|
||||
export async function getMenuDetailApi(id: number) {
|
||||
return requestClient.get<MenuVO.MenuInfoVO>(`/menu/detail/${id}`);
|
||||
return requestClient.get<MenuVO.MenuInfo>(`/menu/detail/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*/
|
||||
export async function createMenuApi(data: MenuDTO.CreateMenuDTO) {
|
||||
return requestClient.post<MenuVO.MenuInfoVO>('/menu/create', data);
|
||||
return requestClient.post<MenuVO.MenuInfo>('/menu/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*/
|
||||
export async function updateMenuApi(id: number, data: MenuDTO.UpdateMenuDTO) {
|
||||
return requestClient.put<MenuVO.MenuInfoVO>(`/menu/update/${id}`, data);
|
||||
return requestClient.put<MenuVO.MenuInfo>(`/menu/update/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,3 +47,10 @@ export async function updateMenuApi(id: number, data: MenuDTO.UpdateMenuDTO) {
|
||||
export async function deleteMenuApi(id: number) {
|
||||
return requestClient.delete<void>(`/menu/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量菜单排序
|
||||
*/
|
||||
export async function batchSortMenuApi(data: MenuDTO.BatchSortMenuDTO) {
|
||||
return requestClient.post<void>('/menu/batch-sort', data);
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
* 菜单模块API导出
|
||||
*/
|
||||
|
||||
export * from './menu';
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
|
||||
@@ -62,4 +62,18 @@ export namespace MenuDTO {
|
||||
/** 是否缓存 */
|
||||
keepAlive?: number;
|
||||
}
|
||||
|
||||
/** 批量菜单排序参数 */
|
||||
export interface BatchSortMenuDTO {
|
||||
/** 菜单排序项列表 */
|
||||
sortItems: MenuSortItem[];
|
||||
}
|
||||
|
||||
/** 菜单排序项 */
|
||||
export interface MenuSortItem {
|
||||
/** 菜单ID */
|
||||
menuId: number;
|
||||
/** 排序值 */
|
||||
order: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* 菜单模块VO类型定义
|
||||
*/
|
||||
import type { PermissionVO } from '#/api/system/permission/types';
|
||||
|
||||
export namespace MenuVO {
|
||||
/** 菜单信息 */
|
||||
export interface MenuInfoVO {
|
||||
export interface MenuInfo {
|
||||
/** 主键ID */
|
||||
id: number;
|
||||
/** 父级菜单ID */
|
||||
@@ -38,6 +39,8 @@ export namespace MenuVO {
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
/** 子菜单列表 */
|
||||
children?: MenuInfoVO[];
|
||||
children?: MenuInfo[];
|
||||
/** 权限列表 */
|
||||
permissions?: PermissionVO.PermissionInfoVO[];
|
||||
}
|
||||
}
|
||||
|
||||
+121
-12
@@ -8,8 +8,15 @@ import {
|
||||
createMenuApi,
|
||||
updateMenuApi,
|
||||
getAllMenusApi,
|
||||
type MenuApi as MenuApiType
|
||||
} from '#/api/core/menu'
|
||||
} from '#/api/system/menu'
|
||||
import type { MenuVO } from '#/api/system/menu/types'
|
||||
import {
|
||||
addMenuPermissionApi,
|
||||
removeMenuPermissionApi
|
||||
} from '#/api/system/menu-permission'
|
||||
import {
|
||||
getAllPermissionsApi
|
||||
} from '#/api/system/permission'
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
@@ -26,13 +33,14 @@ const [Modal, modalApi] = useVbenModal({
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (isOpen) {
|
||||
fetchParentMenuOptions();
|
||||
fetchPermissionOptions();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<MenuApiType.MenuInfo | null>(null);
|
||||
const currentRecord = ref<MenuVO.MenuInfo | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 内部表单数据类型
|
||||
@@ -71,6 +79,9 @@ const formData = ref<FormData>({
|
||||
|
||||
// 下拉选项数据
|
||||
const parentMenuOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const permissionOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const selectedPermissions = ref<number[]>([]);
|
||||
const originalPermissions = ref<number[]>([]);
|
||||
|
||||
// 创建图标组件
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
@@ -89,7 +100,7 @@ async function fetchParentMenuOptions() {
|
||||
const data = await getAllMenusApi();
|
||||
const options: Array<{ label: string; value: number }> = [];
|
||||
|
||||
const addMenuOptions = (menus: MenuApiType.MenuInfo[], level = 0) => {
|
||||
const addMenuOptions = (menus: MenuVO.MenuInfo[], level = 0) => {
|
||||
menus.forEach(menu => {
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
@@ -109,8 +120,22 @@ async function fetchParentMenuOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取权限选项
|
||||
async function fetchPermissionOptions() {
|
||||
try {
|
||||
const data = await getAllPermissionsApi();
|
||||
const options = data.map(permission => ({
|
||||
label: permission.name,
|
||||
value: permission.id,
|
||||
}));
|
||||
permissionOptions.value = options;
|
||||
} catch (error) {
|
||||
console.error('获取权限列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
|
||||
@@ -138,6 +163,15 @@ function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
status: record.status === 1, // 转换为boolean
|
||||
keepAlive: record.keepAlive === 1, // 转换为boolean
|
||||
};
|
||||
|
||||
// 设置权限数据
|
||||
if ((record as any).permissions && (record as any).permissions.length > 0) {
|
||||
selectedPermissions.value = (record as any).permissions.map((p: any) => p.id);
|
||||
originalPermissions.value = [...selectedPermissions.value];
|
||||
} else {
|
||||
selectedPermissions.value = [];
|
||||
originalPermissions.value = [];
|
||||
}
|
||||
} else if (!edit && record) {
|
||||
// 添加下级菜单模式,自动选中父菜单
|
||||
formData.value = {
|
||||
@@ -172,6 +206,10 @@ function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
status: true,
|
||||
keepAlive: false,
|
||||
};
|
||||
|
||||
// 重置权限数据
|
||||
selectedPermissions.value = [];
|
||||
originalPermissions.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,9 +217,54 @@ function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
function close() {
|
||||
modalApi.close();
|
||||
formRef.value?.resetFields();
|
||||
selectedPermissions.value = [];
|
||||
originalPermissions.value = [];
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 处理权限变更
|
||||
async function handlePermissionChange() {
|
||||
if (!currentRecord.value) return;
|
||||
|
||||
const menuId = currentRecord.value.id;
|
||||
const currentPermissions = selectedPermissions.value;
|
||||
const originalPermissionsList = originalPermissions.value;
|
||||
|
||||
// 找出新增的权限
|
||||
const addedPermissions = currentPermissions.filter(id => !originalPermissionsList.includes(id));
|
||||
|
||||
// 找出移除的权限
|
||||
const removedPermissions = originalPermissionsList.filter(id => !currentPermissions.includes(id));
|
||||
|
||||
try {
|
||||
// 添加新权限
|
||||
for (const permissionId of addedPermissions) {
|
||||
await addMenuPermissionApi({
|
||||
menuId,
|
||||
permissionId
|
||||
});
|
||||
}
|
||||
|
||||
// 移除权限
|
||||
for (const permissionId of removedPermissions) {
|
||||
await removeMenuPermissionApi({
|
||||
menuId,
|
||||
permissionId
|
||||
});
|
||||
}
|
||||
|
||||
// 更新原始权限列表
|
||||
originalPermissions.value = [...currentPermissions];
|
||||
|
||||
if (addedPermissions.length > 0 || removedPermissions.length > 0) {
|
||||
message.success('权限更新成功');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('权限更新失败:', error);
|
||||
message.error('权限更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
@@ -203,10 +286,24 @@ async function handleSubmit() {
|
||||
// 更新菜单
|
||||
await updateMenuApi(currentRecord.value.id, submitData);
|
||||
message.success('更新菜单成功');
|
||||
|
||||
// 处理权限变更
|
||||
await handlePermissionChange();
|
||||
} else {
|
||||
// 创建菜单
|
||||
await createMenuApi(submitData);
|
||||
const newMenu = await createMenuApi(submitData);
|
||||
message.success('创建菜单成功');
|
||||
|
||||
// 如果有选择的权限,为新菜单添加权限
|
||||
if (selectedPermissions.value.length > 0 && newMenu?.id) {
|
||||
for (const permissionId of selectedPermissions.value) {
|
||||
await addMenuPermissionApi({
|
||||
menuId: newMenu.id,
|
||||
permissionId
|
||||
});
|
||||
}
|
||||
message.success('权限分配成功');
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
@@ -256,12 +353,15 @@ defineExpose({
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="超级菜单" name="superMenu">
|
||||
<Switch
|
||||
v-model:checked="formData.superMenu"
|
||||
checked-children="是"
|
||||
un-checked-children="否"
|
||||
class="w-12"
|
||||
<Form.Item label="权限列表" name="permissions">
|
||||
<Select
|
||||
v-model:value="selectedPermissions"
|
||||
mode="multiple"
|
||||
placeholder="请选择权限"
|
||||
:options="permissionOptions"
|
||||
class="w-full"
|
||||
:max-tag-count="3"
|
||||
:max-tag-text-length="10"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
@@ -337,6 +437,15 @@ defineExpose({
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="超级菜单" name="superMenu">
|
||||
<Switch
|
||||
v-model:checked="formData.superMenu"
|
||||
checked-children="是"
|
||||
un-checked-children="否"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
@@ -10,9 +10,9 @@ import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteMenuApi,
|
||||
getAllMenusApi,
|
||||
type MenuApi as MenuApiType
|
||||
} from '#/api/core/menu';
|
||||
|
||||
batchSortMenuApi,
|
||||
} from '#/api/system/menu';
|
||||
import type { MenuVO } from '#/api/system/menu/types';
|
||||
import MenuFormModal from './components/MenuFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
@@ -45,7 +45,8 @@ const gridOptions: VxeGridProps<any> = {
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
treeNode: true, // 启用树节点显示
|
||||
slots: { default: 'menuName' },
|
||||
dragSort: true, // 启用拖拽排序
|
||||
// 移除自定义插槽,让拖拽控件正常显示
|
||||
},
|
||||
{
|
||||
field: 'title',
|
||||
@@ -65,16 +66,16 @@ const gridOptions: VxeGridProps<any> = {
|
||||
minWidth: 180,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '权限列表',
|
||||
minWidth: 200,
|
||||
slots: { default: 'permissions' },
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
minWidth: 100,
|
||||
slots: { default: 'menuType' },
|
||||
},
|
||||
{
|
||||
field: 'order',
|
||||
title: '排序',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
@@ -99,7 +100,13 @@ const gridOptions: VxeGridProps<any> = {
|
||||
size: 'small',
|
||||
resizable: true, // 启用列宽调整
|
||||
rowConfig: {
|
||||
isHover: true, // 启用行悬停高亮
|
||||
drag: true, // 启用行拖拽
|
||||
},
|
||||
rowDragConfig: {
|
||||
isPeerDrag: true, // 启用同层级拖拽限制
|
||||
},
|
||||
columnConfig: {
|
||||
// 列配置
|
||||
},
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
@@ -109,13 +116,9 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
data: [],
|
||||
treeConfig: {
|
||||
children: 'children',
|
||||
hasChild: 'hasChildren',
|
||||
expandAll: true, // 自动展开所有节点
|
||||
indent: 20, // 树节点缩进距离
|
||||
showIcon: true, // 显示展开/收起图标
|
||||
iconOpen: 'vxe-icon-arrow-down', // 展开图标
|
||||
iconClose: 'vxe-icon-arrow-right', // 收起图标
|
||||
transform: true,
|
||||
rowField: 'id',
|
||||
parentField: 'parentId',
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
@@ -124,11 +127,10 @@ const gridOptions: VxeGridProps<any> = {
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getAllMenusApi();
|
||||
// 构建树形结构数据
|
||||
const treeData = buildTreeData(data);
|
||||
// 直接返回扁平化数据,让 vxe-table 自动构建树形结构
|
||||
return {
|
||||
items: treeData,
|
||||
total: treeData.length,
|
||||
items: data,
|
||||
total: data.length,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取菜单列表失败:', error);
|
||||
@@ -159,17 +161,17 @@ function handleAdd() {
|
||||
}
|
||||
|
||||
// 处理添加下级菜单
|
||||
function handleAddChild(record: MenuApiType.MenuInfo) {
|
||||
function handleAddChild(record: MenuVO.MenuInfo) {
|
||||
menuFormModalRef.value?.open(false, record);
|
||||
}
|
||||
|
||||
// 处理编辑菜单
|
||||
function handleEdit(record: MenuApiType.MenuInfo) {
|
||||
function handleEdit(record: MenuVO.MenuInfo) {
|
||||
menuFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除菜单
|
||||
async function handleDelete(record: MenuApiType.MenuInfo) {
|
||||
async function handleDelete(record: MenuVO.MenuInfo) {
|
||||
try {
|
||||
await deleteMenuApi(record.id);
|
||||
message.success('删除成功');
|
||||
@@ -185,6 +187,47 @@ function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 防重复调用标志
|
||||
let isUpdating = false;
|
||||
|
||||
// 处理拖拽排序
|
||||
const handleDragSort = async (_params: any) => {
|
||||
// 防止重复调用
|
||||
if (isUpdating) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isUpdating = true;
|
||||
|
||||
// 获取当前表格数据
|
||||
const tableDataResult = gridApi.grid.getTableData();
|
||||
const tableData = tableDataResult?.tableData || [];
|
||||
|
||||
// 构建排序数据
|
||||
const sortItems = tableData.map((item: MenuVO.MenuInfo, index: number) => ({
|
||||
menuId: item.id,
|
||||
order: index + 1, // 排序值从1开始
|
||||
}));
|
||||
|
||||
// 调用排序接口
|
||||
await batchSortMenuApi({ sortItems });
|
||||
|
||||
// 排序成功后不需要重新加载数据,因为表格数据已经更新
|
||||
} catch (error: any) {
|
||||
console.error('拖拽排序失败:', error);
|
||||
if (error?.message) {
|
||||
message.error(error.message);
|
||||
} else {
|
||||
message.error('排序更新失败');
|
||||
}
|
||||
// 排序失败时重新加载数据,恢复原始状态
|
||||
gridApi.reload();
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 全部展开树形表格
|
||||
function expandAllTree() {
|
||||
if (gridApi) {
|
||||
@@ -229,35 +272,9 @@ function getMenuTypeColor(type: string) {
|
||||
return colorMap[type] || 'default';
|
||||
}
|
||||
|
||||
// 构建树形结构数据
|
||||
function buildTreeData(menuList: MenuApiType.MenuInfo[]): MenuApiType.MenuInfo[] {
|
||||
const menuMap = new Map<number, MenuApiType.MenuInfo>();
|
||||
const rootMenus: MenuApiType.MenuInfo[] = [];
|
||||
|
||||
// 创建菜单映射
|
||||
menuList.forEach(menu => {
|
||||
menuMap.set(menu.id, { ...menu, children: [] });
|
||||
});
|
||||
|
||||
// 构建树形结构
|
||||
menuList.forEach(menu => {
|
||||
const menuItem = menuMap.get(menu.id)!;
|
||||
if (menu.parentId && menu.parentId !== 0) {
|
||||
const parent = menuMap.get(menu.parentId);
|
||||
if (parent) {
|
||||
parent.children = parent.children || [];
|
||||
parent.children.push(menuItem);
|
||||
}
|
||||
} else {
|
||||
rootMenus.push(menuItem);
|
||||
}
|
||||
});
|
||||
|
||||
return rootMenus;
|
||||
}
|
||||
|
||||
// 获取菜单图标
|
||||
function getMenuIcon(menu: MenuApiType.MenuInfo) {
|
||||
function getMenuIcon(menu: MenuVO.MenuInfo) {
|
||||
if (menu.icon) {
|
||||
return createIconifyIcon(menu.icon);
|
||||
}
|
||||
@@ -278,6 +295,31 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
showSearchForm: false,
|
||||
tableTitle: '菜单管理',
|
||||
gridEvents: {
|
||||
// 拖拽排序事件
|
||||
rowDragend: handleDragSort,
|
||||
} as any,
|
||||
});
|
||||
|
||||
// 添加Grid组件的ref
|
||||
const gridRef = ref();
|
||||
|
||||
// 在组件挂载后绑定拖拽事件
|
||||
onMounted(() => {
|
||||
// 延迟绑定,确保Grid组件完全初始化
|
||||
setTimeout(() => {
|
||||
if (gridRef.value) {
|
||||
// 尝试直接绑定VxeTable的拖拽事件
|
||||
const vxeGrid = gridRef.value;
|
||||
if (vxeGrid && vxeGrid.$refs && vxeGrid.$refs.grid) {
|
||||
const grid = vxeGrid.$refs.grid;
|
||||
// 绑定拖拽事件
|
||||
grid.on('row-drag-end', (params: any) => {
|
||||
handleDragSort(params);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -285,6 +327,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<Page title="菜单管理" auto-content-height>
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid
|
||||
ref="gridRef"
|
||||
:loading="loading"
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
@@ -302,16 +345,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<CollapseIcon />
|
||||
全部收起
|
||||
</Button>
|
||||
<div class="text-gray-500 text-sm">
|
||||
💡 提示:可直接拖拽菜单名称列进行排序
|
||||
</div>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 菜单名称列 -->
|
||||
<template #menuName="{ row }: { row: any }">
|
||||
<div class="flex items-center space-x-2">
|
||||
<component :is="getMenuIcon(row)" class="w-4 h-4 text-gray-600" />
|
||||
<span>{{ row.name }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 菜单名称列 - 移除自定义插槽以支持拖拽控件正常显示 -->
|
||||
|
||||
<!-- 图标列 -->
|
||||
<template #icon="{ row }: { row: any }">
|
||||
@@ -335,6 +375,21 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 权限名称列 -->
|
||||
<template #permissions="{ row }: { row: any }">
|
||||
<div v-if="row.permissions && row.permissions.length > 0" class="flex flex-wrap gap-1">
|
||||
<Tag
|
||||
v-for="permission in row.permissions"
|
||||
:key="permission.id"
|
||||
:color="permission.status === 1 ? 'blue' : 'default'"
|
||||
size="small"
|
||||
>
|
||||
{{ permission.name }}
|
||||
</Tag>
|
||||
</div>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
@@ -361,3 +416,4 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user