可正常启用
This commit is contained in:
parent
07f974491e
commit
75b1393c9b
@ -16,6 +16,7 @@ import type {MenuProps} from 'antd';
|
|||||||
import {getCurrentUserMenus} from '@/pages/System/Menu/service';
|
import {getCurrentUserMenus} from '@/pages/System/Menu/service';
|
||||||
import {getWeather} from '../services/weather';
|
import {getWeather} from '../services/weather';
|
||||||
import type {MenuResponse} from '@/pages/System/Menu/types';
|
import type {MenuResponse} from '@/pages/System/Menu/types';
|
||||||
|
import {MenuTypeEnum} from '@/pages/System/Menu/types';
|
||||||
import type {RootState} from '../store';
|
import type {RootState} from '../store';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import 'dayjs/locale/zh-cn';
|
import 'dayjs/locale/zh-cn';
|
||||||
@ -26,6 +27,29 @@ const {confirm} = Modal;
|
|||||||
// 设置中文语言
|
// 设置中文语言
|
||||||
dayjs.locale('zh-cn');
|
dayjs.locale('zh-cn');
|
||||||
|
|
||||||
|
// 添加清理空children的函数,同时过滤掉按钮类型菜单
|
||||||
|
const cleanEmptyChildren = (menus: MenuResponse[]): MenuResponse[] => {
|
||||||
|
// 先过滤掉按钮类型的菜单
|
||||||
|
return menus
|
||||||
|
.filter(menu => menu.type !== MenuTypeEnum.BUTTON)
|
||||||
|
.map(menu => {
|
||||||
|
const cleanedMenu = { ...menu };
|
||||||
|
|
||||||
|
if (cleanedMenu.children && cleanedMenu.children.length > 0) {
|
||||||
|
// 递归处理子菜单,同样需要过滤按钮
|
||||||
|
cleanedMenu.children = cleanEmptyChildren(cleanedMenu.children);
|
||||||
|
// 如果过滤后子菜单为空,则删除children属性
|
||||||
|
if (cleanedMenu.children.length === 0) {
|
||||||
|
delete cleanedMenu.children;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete cleanedMenu.children;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanedMenu;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const BasicLayout: React.FC = () => {
|
const BasicLayout: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@ -49,12 +73,16 @@ const BasicLayout: React.FC = () => {
|
|||||||
// 初始化用户数据
|
// 初始化用户数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializeUserData = async () => {
|
const initializeUserData = async () => {
|
||||||
// try {
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
try {
|
||||||
const menuData = await getCurrentUserMenus();
|
const menuData = await getCurrentUserMenus();
|
||||||
console.log(menuData)
|
dispatch(setMenus(cleanEmptyChildren(menuData)));
|
||||||
dispatch(setMenus(menuData));
|
} catch (error) {
|
||||||
|
message.error('获取菜单数据失败');
|
||||||
|
console.error('获取菜单数据失败:', error);
|
||||||
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!userInfo) {
|
if (!userInfo) {
|
||||||
@ -62,7 +90,7 @@ const BasicLayout: React.FC = () => {
|
|||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [dispatch, userInfo]);
|
||||||
|
|
||||||
// 处理时间和天气更新
|
// 处理时间和天气更新
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -129,11 +157,15 @@ const BasicLayout: React.FC = () => {
|
|||||||
|
|
||||||
// 将菜单数据转换为antd Menu需要的格式
|
// 将菜单数据转换为antd Menu需要的格式
|
||||||
const getMenuItems = (menuList: MenuResponse[]): MenuProps['items'] => {
|
const getMenuItems = (menuList: MenuResponse[]): MenuProps['items'] => {
|
||||||
return menuList?.map(menu => ({
|
return menuList
|
||||||
|
?.filter(menu => menu.type !== MenuTypeEnum.BUTTON) // 过滤掉按钮类型的菜单
|
||||||
|
?.map(menu => ({
|
||||||
key: menu.path || menu.id.toString(),
|
key: menu.path || menu.id.toString(),
|
||||||
icon: getIcon(menu.icon),
|
icon: getIcon(menu.icon),
|
||||||
label: menu.name,
|
label: menu.name,
|
||||||
children: menu.children && menu.children.length > 0 ? getMenuItems(menu.children) : undefined
|
children: menu.children && menu.children.length > 0
|
||||||
|
? getMenuItems(menu.children) // 递归处理子菜单
|
||||||
|
: undefined
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -203,7 +203,7 @@ const UserPage: React.FC = () => {
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 240,
|
width: 320,
|
||||||
fixed: 'right' as FixedType,
|
fixed: 'right' as FixedType,
|
||||||
render: (_: any, record: UserResponse) => (
|
render: (_: any, record: UserResponse) => (
|
||||||
<Space size={0}>
|
<Space size={0}>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user