diff --git a/src/app.tsx b/src/app.tsx index a61c427..b378380 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { AvatarDropdown, AvatarName, Footer, Question } from '@/components'; import { SettingDrawer } from '@ant-design/pro-components'; import type { RunTimeLayoutConfig } from '@umijs/max'; @@ -36,13 +37,26 @@ export async function getInitialState(): Promise<{ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => { + + const [data,setData]=React.useState("") + + const fetchData=(async ()=>{ + const res = await getLoginUserUsingGet(); + console.log('data',res) + setData(res) + }) + + React.useEffect(()=>{ + fetchData() + },[]) + return { actionsRender: () => [], avatarProps: { src: initialState?.currentUser?.userAvatar, title: , render: (_, avatarChildren) => { - return {avatarChildren}; + return {avatarChildren}; }, }, waterMarkProps: { diff --git a/src/components/RightContent/AvatarDropdown.tsx b/src/components/RightContent/AvatarDropdown.tsx index b0e9bc8..cf3e930 100644 --- a/src/components/RightContent/AvatarDropdown.tsx +++ b/src/components/RightContent/AvatarDropdown.tsx @@ -16,6 +16,7 @@ export type GlobalHeaderRightProps = { export const AvatarName = () => { const { initialState } = useModel('@@initialState'); + console.log('initialState',initialState) const { currentUser } = initialState || {}; return {currentUser?.userName}; }; @@ -38,7 +39,7 @@ const useStyles = createStyles(({ token }) => { }; }); -export const AvatarDropdown: React.FC = ({ menu, children }) => { +export const AvatarDropdown: React.FC = ({ menu, children,currentUser }) => { /** * 退出登录,并且将当前的 url 保存 */ @@ -93,7 +94,7 @@ export const AvatarDropdown: React.FC = ({ menu, childre return loading; } - const { currentUser } = initialState; + // const { currentUser } = initialState; if (!currentUser || !currentUser.userName) { return loading;