2024-12-10 10:28:55 +08:00
|
|
|
import React,{useEffect} from 'react';
|
|
|
|
|
import { Menu } from 'antd';
|
|
|
|
|
import { createCrudService } from '../../components/crud/_';
|
|
|
|
|
import apiurl from '../../service/apiurl';
|
|
|
|
|
import {ProfileOutlined} from '@ant-design/icons';
|
|
|
|
|
import {useNavigate} from 'react-router';
|
|
|
|
|
import {MenuItem} from '../../models/_';
|
|
|
|
|
import {useDispatch,useSelector} from "react-redux";
|
|
|
|
|
|
|
|
|
|
function getMenuUrl(menuItem: MenuItem | undefined): string | null {
|
|
|
|
|
if (!menuItem) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const url = menuItem.path || menuItem.redirect;
|
|
|
|
|
if (url) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (menuItem.children && menuItem.children.length) {
|
|
|
|
|
for (const m of menuItem.children) {
|
|
|
|
|
const url = getMenuUrl(m);
|
|
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TopMenu: React.FC<{
|
|
|
|
|
menu: MenuItem[];
|
|
|
|
|
menuIndexes: string[];
|
|
|
|
|
}> = ({menu, menuIndexes}) => {
|
2024-12-27 17:49:19 +08:00
|
|
|
console.log('12333333',menu);
|
2024-12-10 10:28:55 +08:00
|
|
|
console.log(menuIndexes);
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
|
|
const getMenuIcon = (val: any) => {
|
|
|
|
|
let icon = null;
|
|
|
|
|
if (val.icon === "HomeFilled") {
|
|
|
|
|
icon = <span className="shouye topMenuIcon"></span>
|
|
|
|
|
} else if (val.icon === "FundFilled") {
|
|
|
|
|
icon = <span className="yubao topMenuIcon"></span>
|
|
|
|
|
} else if (val.icon === "AlertFilled") {
|
|
|
|
|
icon = <span className="yujing topMenuIcon"></span>
|
|
|
|
|
} else if (val.icon === "GoldenFilled") {
|
|
|
|
|
icon = <span className="yuyan topMenuIcon"></span>
|
|
|
|
|
} else if (val.icon === "AppstoreFilled") {
|
|
|
|
|
icon = <span className="yuan topMenuIcon"></span>
|
|
|
|
|
} else if (val.icon === "FileTextFilled") {
|
|
|
|
|
icon = <span className="guanli topMenuIcon"></span>
|
|
|
|
|
}
|
|
|
|
|
return icon;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const menuClicked = (id: any) => {
|
|
|
|
|
const menuItem:any = menu.find(m => m.id == id);
|
2024-12-12 17:53:28 +08:00
|
|
|
if (menuItem.title === "首页") {
|
|
|
|
|
navigate(menuItem.path)
|
2024-12-10 10:28:55 +08:00
|
|
|
}
|
|
|
|
|
const url = getMenuUrl(menuItem);
|
|
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
|
navigate(url);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-10 17:47:22 +08:00
|
|
|
|
2024-12-10 10:28:55 +08:00
|
|
|
return (
|
|
|
|
|
|
|
|
|
|
<div className='app-top-menu'>
|
|
|
|
|
{
|
|
|
|
|
menu?.map(o => {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={o.id}
|
|
|
|
|
className={`app-top-menu-item${menuIndexes[0] == o.id ? ' active' : ''}`}
|
2024-12-12 17:53:28 +08:00
|
|
|
onClick={() => {menuClicked(o.id)}}
|
2024-12-10 10:28:55 +08:00
|
|
|
style={{cursor:"pointer"}}
|
|
|
|
|
>
|
|
|
|
|
<img src={`${process.env.PUBLIC_URL}/assets/${o.icon}.png`} alt=""/>
|
|
|
|
|
<span>{o.title}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default React.memo(TopMenu);
|