fix: 修改登陆逻辑
This commit is contained in:
parent
99b18a38d5
commit
0ae3e5bdbb
@ -114,7 +114,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
||||
*/
|
||||
export const request = {
|
||||
|
||||
baseURL:"http://172.20.10.2:8101",
|
||||
baseURL:"http://localhost:8101",
|
||||
withCredentials:true,
|
||||
...errorConfig,
|
||||
};
|
||||
|
@ -41,24 +41,23 @@ const useStyles = createStyles(({ token }) => {
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}, []);
|
||||
const { initialState, setInitialState } = useModel('@@initialState');
|
||||
// 移除 useEffect 里的 window.location.reload 相关逻辑
|
||||
// useEffect(() => {
|
||||
// console.log('initialState2',sessionStorage.getItem('avatar_refreshed'))
|
||||
// if (!sessionStorage.getItem('avatar_refreshed')) {
|
||||
// sessionStorage.setItem('avatar_refreshed', '1');
|
||||
// window.location.reload();
|
||||
// }
|
||||
// }, []);
|
||||
|
||||
/**
|
||||
* 退出登录,并且将当前的 url 保存
|
||||
*/
|
||||
const loginOut = async () => {
|
||||
await userLogoutUsingPost();
|
||||
// 退出登录时清除刷新标记
|
||||
sessionStorage.removeItem('avatar_refreshed');
|
||||
const { search, pathname } = window.location;
|
||||
const urlParams = new URL(window.location.href).searchParams;
|
||||
/** redirect */
|
||||
|
@ -93,8 +93,13 @@ useEffect(()=>{
|
||||
const defaultLoginSuccessMessage = '登录成功!';
|
||||
message.success(defaultLoginSuccessMessage);
|
||||
await fetchUserInfo();
|
||||
// 登录成功后,设置刷新标记并刷新页面
|
||||
const urlParams = new URL(window.location.href).searchParams;
|
||||
history.push(urlParams.get('redirect') || '/');
|
||||
sessionStorage.setItem('avatar_refreshed', '1');
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
return;
|
||||
} else {
|
||||
message.error(res.message);
|
||||
@ -104,6 +109,7 @@ useEffect(()=>{
|
||||
console.log(error);
|
||||
message.error(defaultLoginFailureMessage);
|
||||
}
|
||||
// 登录失败不需要刷新
|
||||
};
|
||||
|
||||
return (
|
||||
|
Loading…
x
Reference in New Issue
Block a user