import { useModel,history } from "@umijs/max"; import { useEffect, useState } from "react"; // @mui import { Box, ListItemIcon, Typography } from "@mui/material"; // mock import { styled } from "@mui/material/styles"; // components import navConfig from "@/layouts/dashboard/nav/config"; import { doFetch } from "@/utils/doFetch"; import { useRequest } from "ahooks"; import { Badge, Card, Divider } from "antd"; const StyledNavItemIcon = styled(ListItemIcon)({ width: 48, height: 48, color: "inherit", display: "flex", alignItems: "center", justifyContent: "center", color:"#448ee2" }); export default function Welcome() { const [navConfigs, setNavConfigs] = useState(navConfig); const { initialState: { nav, currentUser, menuNum }, setInitialState, } = useModel("@@initialState"); const { data } = useRequest(async () => { let res = await doFetch({ url: "/system/message", params: {} }); let result = {}; res?.data?.dataList?.map((it) => { result[it?.menu] = it?.count; }); return result; }); useEffect(() => { if (!data) { return; } setNavConfigs(() => { let news = navConfig?.map((it) => { return { ...it, children: it?.children?.map((item) => { const info = menuNum?.[item?.key ?? ""] === 0 ? {} : menuNum?.[item?.key ?? ""] ? { info: (
{menuNum[item?.key ?? ""]}
), } : data[item?.key ?? ""] ? { info: (
{data[item?.key]}
), } : {}; return { ...item, ...info, }; }), }; }); if (currentUser?.type == 1) { return news?.filter((it) => { return it?.title === "管理中心"; }); } else if (currentUser?.type == 2) { return news?.filter((it) => { return it?.title === "教学中心"; }); } else { return news?.filter((it) => { return it?.title === "学习中心"; }); } }); }, [data, currentUser?.type, menuNum]); console.log(navConfigs, currentUser); return ( 你好{currentUser?.name}{" "} 欢迎使用
{navConfigs?.[0]?.children?.map?.((it) => { return ( { history.push(it?.path) }}>
{it?.icon} {it?.title}
{it?.info}
); })}
); }