|
|
@@ -15,7 +15,7 @@ import Result404 from './404'; |
|
|
|
import './index.css' |
|
|
|
import TabsLayout from './tabs-layout'; |
|
|
|
import Content from './content'; |
|
|
|
import homeService from '@/request/service/home'; |
|
|
|
import userService from '@/request/service/user'; |
|
|
|
import { useRequest } from "@/hooks/use-request"; |
|
|
|
import menuData from '../../mock/menu.json' |
|
|
|
|
|
|
@@ -23,14 +23,19 @@ const BasicLayout: React.FC = () => { |
|
|
|
|
|
|
|
const [loading, setLoading] = useState(true); |
|
|
|
|
|
|
|
const { lang } = useGlobalStore(); |
|
|
|
const { currentUser } = useUserStore(); |
|
|
|
const { refreshToken, lang, token } = useGlobalStore(); |
|
|
|
const { currentUser, setCurrentUser } = useUserStore(); |
|
|
|
const { setMenus } = useMenusStore(); |
|
|
|
const navigate = useNavigate(); |
|
|
|
const location = useLocation(); |
|
|
|
// const { setLatestMessage } = useMessageStore(); |
|
|
|
|
|
|
|
const { runAsync: getAnnouncement } = useRequest(homeService.getAnnouncement, { manual: true }); |
|
|
|
const { |
|
|
|
data: currentUserProfile, |
|
|
|
run: getCurrentUserProfile, |
|
|
|
} = useRequest( |
|
|
|
userService.getProfile, |
|
|
|
{ manual: true } |
|
|
|
); |
|
|
|
|
|
|
|
const formatMenus = ( |
|
|
|
menus: Menu[], |
|
|
@@ -59,6 +64,15 @@ const BasicLayout: React.FC = () => { |
|
|
|
} |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (!refreshToken) { |
|
|
|
navigate('/login'); |
|
|
|
return; |
|
|
|
} |
|
|
|
getCurrentUserProfile(); |
|
|
|
}, [refreshToken, getCurrentUserProfile, navigate]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (!currentUserProfile) return; |
|
|
|
const menus:Array<Menu> = menuData as Array<Menu> ; |
|
|
|
console.log(menus); |
|
|
|
|
|
|
@@ -112,12 +126,12 @@ const BasicLayout: React.FC = () => { |
|
|
|
}, |
|
|
|
} |
|
|
|
]); |
|
|
|
setCurrentUser(currentUserProfile!!.data); |
|
|
|
setLoading(false); |
|
|
|
|
|
|
|
// replace一下当前路由,为了触发路由匹配 |
|
|
|
router.navigate(`${location.pathname}${location.search}`, { replace: true }); |
|
|
|
}, [ currentUser ]); |
|
|
|
|
|
|
|
}, [ currentUserProfile, setCurrentUser ]); |
|
|
|
useEffect(() => { |
|
|
|
function storageChange(e: StorageEvent) { |
|
|
|
if (e.key === useGlobalStore.persist.getOptions().name) { |
|
|
@@ -132,7 +146,7 @@ const BasicLayout: React.FC = () => { |
|
|
|
} |
|
|
|
}, []); |
|
|
|
|
|
|
|
if (loading) { |
|
|
|
if (loading || !currentUser) { |
|
|
|
return ( |
|
|
|
<GloablLoading /> |
|
|
|
) |
|
|
|