|
|
|
@@ -20,7 +20,8 @@ import { |
|
|
|
setRemoteMenu, |
|
|
|
} from './services/session'; |
|
|
|
import './styles/menu.less'; |
|
|
|
import { needAuth } from './utils'; |
|
|
|
import { isLoginPage, needAuth } from './utils'; |
|
|
|
import { HomeUrl } from './utils/constant'; |
|
|
|
import { closeAllModals } from './utils/modal'; |
|
|
|
import { gotoLoginPage } from './utils/ui'; |
|
|
|
export { requestConfig as request } from './requestConfig'; |
|
|
|
@@ -41,7 +42,7 @@ export async function getInitialState(): Promise<GlobalInitialState> { |
|
|
|
} as API.CurrentUser; |
|
|
|
} catch (error) { |
|
|
|
console.error('getInitialState', error); |
|
|
|
gotoLoginPage(); |
|
|
|
gotoLoginPage(true); |
|
|
|
} |
|
|
|
return undefined; |
|
|
|
}; |
|
|
|
@@ -117,27 +118,29 @@ export const layout: RuntimeConfig['layout'] = ({ initialState }) => { |
|
|
|
}; |
|
|
|
|
|
|
|
export const onRouteChange: RuntimeConfig['onRouteChange'] = async (e) => { |
|
|
|
debugger; |
|
|
|
// console.log('onRouteChange'); |
|
|
|
|
|
|
|
// 路由切换时,尤其是回退时,关闭打开的弹框 |
|
|
|
closeAllModals(); |
|
|
|
|
|
|
|
const { location } = e; |
|
|
|
const pathname = location.pathname; |
|
|
|
const token = getAccessToken(); |
|
|
|
// 没有 token,跳转到登录页面 |
|
|
|
if (!token && needAuth(location.pathname)) { |
|
|
|
gotoLoginPage(); |
|
|
|
if (!token && needAuth(pathname)) { |
|
|
|
gotoLoginPage(false); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 有 token, 登录页面直接跳转到首页 |
|
|
|
if (token && !needAuth(location.pathname)) { |
|
|
|
history.push('/'); |
|
|
|
if (token && isLoginPage(pathname)) { |
|
|
|
history.push(HomeUrl); |
|
|
|
} |
|
|
|
|
|
|
|
const menus = getRemoteMenu(); |
|
|
|
// 没有菜单,刷新页面 |
|
|
|
if (menus === null && needAuth(location.pathname)) { |
|
|
|
if (menus === null && needAuth(pathname)) { |
|
|
|
history.go(0); |
|
|
|
} |
|
|
|
}; |
|
|
|
|