|
|
@@ -10,7 +10,7 @@ import {
|
|
|
Grid3x3, List, Link2, Key, Wrench, Monitor, Server
|
|
|
} from 'lucide-react';
|
|
|
import { Modal, Button, Input, Space, Table as AntdTable, Switch as AntdSwitch } from 'antd';
|
|
|
-import type { ColumnsType, DataNode } from 'antd/es/table';
|
|
|
+import type { ColumnsType } from 'antd/es/table';
|
|
|
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
|
import { menuApi, MenuVO, MenuQueryParams, MenuType } from '../api/Menu';
|
|
|
import { handleTree, TreeNode } from '../utils/tree';
|
|
|
@@ -20,7 +20,7 @@ import { Button as UIButton } from './ui/button';
|
|
|
import MenuForm, { MenuFormRef } from './MenuForm';
|
|
|
import PermissionWrapper from './PermissionWrapper';
|
|
|
|
|
|
-interface MenuNode extends MenuVO, TreeNode {
|
|
|
+interface MenuNode extends MenuVO {
|
|
|
children?: MenuNode[];
|
|
|
key?: number;
|
|
|
}
|
|
|
@@ -43,9 +43,12 @@ export default function MenuManagement() {
|
|
|
const currentParams = params || queryParams;
|
|
|
setLoading(true);
|
|
|
try {
|
|
|
- const data = await menuApi.getMenuList(currentParams);
|
|
|
- setList(data || []);
|
|
|
- const treeData = handleTree<MenuNode>(data || []);
|
|
|
+ const response = await menuApi.getMenuList(currentParams);
|
|
|
+ const data = Array.isArray(response) ? response : (response?.data || response || []);
|
|
|
+ setList(data);
|
|
|
+ // 过滤掉没有 id 的数据,然后转换为树形结构
|
|
|
+ const validData = data.filter(item => item.id !== undefined && item.id !== null);
|
|
|
+ const treeData = handleTree(validData as any) as MenuNode[];
|
|
|
// 为每个节点添加 key 属性(Ant Design Table 需要)
|
|
|
const addKeys = (nodes: MenuNode[]): MenuNode[] => {
|
|
|
return nodes.map(node => ({
|
|
|
@@ -57,12 +60,9 @@ export default function MenuManagement() {
|
|
|
const treeDataWithKeys = addKeys(treeData);
|
|
|
setTreeList(treeDataWithKeys);
|
|
|
|
|
|
- // 首次加载时默认展开所有
|
|
|
- if (expandedRowKeys.length === 0 && treeDataWithKeys.length > 0) {
|
|
|
- const allIds = getAllMenuIds(treeDataWithKeys);
|
|
|
- setExpandedRowKeys(allIds);
|
|
|
- setIsExpandAll(true);
|
|
|
- }
|
|
|
+ // 默认折叠,不展开任何节点
|
|
|
+ setExpandedRowKeys([]);
|
|
|
+ setIsExpandAll(false);
|
|
|
} catch (error: any) {
|
|
|
toast.error(error.message || '获取菜单列表失败');
|
|
|
} finally {
|
|
|
@@ -169,8 +169,8 @@ export default function MenuManagement() {
|
|
|
parentId: menu.parentId ?? 0,
|
|
|
path: menu.path ?? '',
|
|
|
icon: menu.icon ?? '',
|
|
|
- component: menu.component ?? null,
|
|
|
- componentName: menu.componentName ?? null,
|
|
|
+ component: menu.component ?? undefined,
|
|
|
+ componentName: menu.componentName ?? undefined,
|
|
|
status: val,
|
|
|
visible: menu.visible ?? true,
|
|
|
keepAlive: menu.keepAlive ?? true,
|
|
|
@@ -354,7 +354,10 @@ export default function MenuManagement() {
|
|
|
key: 'permission',
|
|
|
width: 300,
|
|
|
ellipsis: true,
|
|
|
- render: (text: string) => text || '-',
|
|
|
+ render: (text: string, record: MenuNode) => {
|
|
|
+ const permission = record.permission;
|
|
|
+ return permission ? String(permission) : '-';
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
title: '组件路径',
|
|
|
@@ -362,7 +365,10 @@ export default function MenuManagement() {
|
|
|
key: 'component',
|
|
|
width: 500,
|
|
|
ellipsis: true,
|
|
|
- render: (text: string) => text || '-',
|
|
|
+ render: (text: string, record: MenuNode) => {
|
|
|
+ const component = record.component;
|
|
|
+ return component ? String(component) : '-';
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
title: '组件名称',
|
|
|
@@ -530,8 +536,9 @@ export default function MenuManagement() {
|
|
|
pagination={false}
|
|
|
expandable={{
|
|
|
expandedRowKeys,
|
|
|
- onExpandedRowsChange: setExpandedRowKeys,
|
|
|
+ onExpandedRowsChange: (keys) => setExpandedRowKeys(keys as React.Key[]),
|
|
|
indentSize: 24,
|
|
|
+ defaultExpandAllRows: false,
|
|
|
}}
|
|
|
scroll={{ x: 'max-content' }}
|
|
|
size="middle"
|