fix: 修复头像
This commit is contained in:
parent
f35bf3978e
commit
99b18a38d5
22
src/app.tsx
22
src/app.tsx
@ -23,6 +23,7 @@ export async function getInitialState(): Promise<{
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 如果不是登录页面,执行
|
// 如果不是登录页面,执行
|
||||||
const { location } = history;
|
const { location } = history;
|
||||||
if (location.pathname !== loginPath) {
|
if (location.pathname !== loginPath) {
|
||||||
@ -32,31 +33,18 @@ export async function getInitialState(): Promise<{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
currentUser: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
|
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 {
|
return {
|
||||||
actionsRender: () => [<Question key="doc" />],
|
actionsRender: () => [<Question key="doc" />],
|
||||||
avatarProps: {
|
avatarProps: {
|
||||||
src: initialState?.currentUser?.userAvatar,
|
src: initialState?.currentUser?.userAvatar,
|
||||||
title: <AvatarName />,
|
title: <AvatarName />,
|
||||||
render: (_, avatarChildren) => {
|
render: (_, avatarChildren) => {
|
||||||
return <AvatarDropdown currentUser={data}>{avatarChildren}</AvatarDropdown>;
|
return <AvatarDropdown>{avatarChildren}</AvatarDropdown>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
waterMarkProps: {
|
waterMarkProps: {
|
||||||
@ -125,8 +113,8 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
|||||||
* @doc https://umijs.org/docs/max/request#配置
|
* @doc https://umijs.org/docs/max/request#配置
|
||||||
*/
|
*/
|
||||||
export const request = {
|
export const request = {
|
||||||
|
|
||||||
baseURL:"http://localhost:8101",
|
baseURL:"http://172.20.10.2:8101",
|
||||||
withCredentials:true,
|
withCredentials:true,
|
||||||
...errorConfig,
|
...errorConfig,
|
||||||
};
|
};
|
||||||
|
@ -8,6 +8,7 @@ import React, { useCallback } from 'react';
|
|||||||
import { flushSync } from 'react-dom';
|
import { flushSync } from 'react-dom';
|
||||||
import HeaderDropdown from '../HeaderDropdown';
|
import HeaderDropdown from '../HeaderDropdown';
|
||||||
import { userLogoutUsingPost } from '@/services/hebi/userController';
|
import { userLogoutUsingPost } from '@/services/hebi/userController';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
export type GlobalHeaderRightProps = {
|
export type GlobalHeaderRightProps = {
|
||||||
menu?: boolean;
|
menu?: boolean;
|
||||||
@ -39,7 +40,20 @@ const useStyles = createStyles(({ token }) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, children,currentUser }) => {
|
export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, children }) => {
|
||||||
|
const { initialState, setInitialState, refresh } = useModel('@@initialState');
|
||||||
|
console.log('initialState',initialState)
|
||||||
|
// 监听路由变化,并且将当前的 url 保存到 localstorage 中
|
||||||
|
// 监听路由变化,并且将当前的 url 保存到 localstorage 中
|
||||||
|
// 监听路由变化,并且将当前的 url 保存到 localstorage 中
|
||||||
|
// 添加 useEffect 来监听路由变化和初始化
|
||||||
|
useEffect(() => {
|
||||||
|
if (!initialState?.currentUser && window.location.pathname !== '/user/login') {
|
||||||
|
console.log('loginPath',window.location.pathname)
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录,并且将当前的 url 保存
|
* 退出登录,并且将当前的 url 保存
|
||||||
*/
|
*/
|
||||||
@ -60,7 +74,7 @@ export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, childre
|
|||||||
};
|
};
|
||||||
const { styles } = useStyles();
|
const { styles } = useStyles();
|
||||||
|
|
||||||
const { initialState, setInitialState } = useModel('@@initialState');
|
// const { initialState, setInitialState } = useModel('@@initialState');
|
||||||
|
|
||||||
const onMenuClick = useCallback(
|
const onMenuClick = useCallback(
|
||||||
(event: MenuInfo) => {
|
(event: MenuInfo) => {
|
||||||
@ -90,13 +104,7 @@ export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, childre
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!initialState) {
|
if (!initialState?.currentUser || !initialState.currentUser.userName) {
|
||||||
return loading;
|
|
||||||
}
|
|
||||||
|
|
||||||
// const { currentUser } = initialState;
|
|
||||||
|
|
||||||
if (!currentUser || !currentUser.userName) {
|
|
||||||
return loading;
|
return loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,4 +144,4 @@ export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, childre
|
|||||||
{children}
|
{children}
|
||||||
</HeaderDropdown>
|
</HeaderDropdown>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user