fix(): 修复菜单权限问题

master
李神峰 2026-01-06 17:51:36 +08:00
parent 08f2ff9348
commit 1322a6cdfa
3 changed files with 31 additions and 5 deletions

View File

@ -12,7 +12,7 @@ function getMenuUrl(menuItem: MenuItem | undefined): string | null {
return null;
}
const url = menuItem.path || menuItem.redirect;
const url = menuItem.path;
if (url) {
return url;
}
@ -65,7 +65,6 @@ const TopMenu: React.FC<{
navigate(menuItem.path)
}
const url = getMenuUrl(menuItem);
if (url) {
navigate(url);
}

View File

@ -60,9 +60,32 @@ const MenuTitleCard = ({ key, title }) => {
</div>
)
}
function getMenuUrl(menuItem){
if (!menuItem) {
return null;
}
const url = menuItem.path;
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;
}
export default function Home() {
const menu = useSelector((state) => state.auth.menu);
const [title, setTitle] = useState([])
const [menuList, setMenuList] = useState([])
const [showTabLeft, setShowTabLeft] = useState(false)
const [showTabRight, setShowTabRight] = useState(false)
// const title = menu.map(item => ({ title: item.menuName, key: item.path || item.redirect }))
@ -229,7 +252,10 @@ export default function Home() {
const navigate = useNavigate();
const jumpMenu = (item) => {
navigate(item.key)
const url = getMenuUrl(item);
if (url) {
navigate(url);
}
}
const [videoList, setVideoList] = useState([])
const [videoArr, setvideoArr] = useState({})
@ -273,7 +299,8 @@ export default function Home() {
const getMenu = async () => {
try {
const data = await loadMenu();
setTitle(data.map(item => ({ title: item.menuName, key: item.path || item.redirect })))
setMenuList(data)
setTitle(data.map(item => ({ ...item, key: item.path || item.redirect })))
} catch (error) {
console.log(error);
}