You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import { RequestConfig , history } from '@umijs/max' ;
import { requestConfig } from './request-config' ;
import { queryCurrentUserState } from './services/profile/apis' ;
const loginPath = '/login' ;
let currentUserInfo : any = { } ;
// 运行时配置
// 全局初始化数据配置,用于 Layout 用户信息和权限初始化
// 更多信息见文档: https://umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState() {
// 如果不是登录页面,执行
const { location } = history ;
const fetchUserInfo = async ( ) = > {
try {
const data = await queryCurrentUserState ( {
skipErrorHandler : true
} ) ;
return data ;
} catch ( error ) {
history . push ( loginPath ) ;
}
return undefined ;
} ;
if ( ! [ loginPath ] . includes ( location . pathname ) ) {
const userInfo = await fetchUserInfo ( ) ;
currentUserInfo = {
. . . userInfo
} ;
return {
fetchUserInfo ,
currentUser : userInfo
} ;
}
return {
fetchUserInfo
} ;
}
// export const patchClientRoutes = async (params: { routes: any[] }) => {
// const { routes } = params;
// console.log('routes============999', routes);
// const data = await queryCurrentUserState({
// skipErrorHandler: true
// });
// routes.unshift({
// path: '/',
// element: data?.is_admin ? (
// <Navigate to="/dashboard" replace />
// ) : (
// <Navigate to="/playground" replace />
// )
// });
// };
export const request : RequestConfig = {
baseURL : ' /v1' ,
. . . requestConfig
} ;