| | |
| | | import { history, Link } from '@umijs/max'; |
| | | import defaultSettings from '../config/defaultSettings'; |
| | | import { errorConfig } from './requestErrorConfig'; |
| | | import { currentUser as queryCurrentUser } from '@/services/ant-design-pro/api'; |
| | | import { getRemoteMenu, getRoutersInfo, getUserInfo, setRemoteMenu, patchRouteWithRemoteMenus } from './services/route'; |
| | | import { getToken } from '@/utils/token-util' |
| | | import { getToken, setToken } from '@/utils/token-util' |
| | | import { TOKEN_HEADER_NAME, TOKEN_STORE_NAME } from '@/config/setting'; |
| | | import { API_BASE_URL } from '@/config/setting' |
| | | import { message } from 'antd'; |
| | | |
| | | const isDev = process.env.NODE_ENV === 'development'; |
| | | const loginPath = '/user/login'; |
| | | const defaultAvatar = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png' |
| | | |
| | | // https://xflow.antv.vision/zh-CN/docs/tutorial/solutions/dag DAG 流程图 |
| | | // https://ant-design.antgroup.com/components/table-cn 表格 |
| | | // https://procomponents.ant.design/components/form 表单pro |
| | | export function render(oldRender) { |
| | | const token = getToken(); |
| | | if (!token || token?.length === 0) { |
| | |
| | | |
| | | export async function patchClientRoutes({ routes }) { |
| | | patchRouteWithRemoteMenus(routes); |
| | | }; |
| | | } |
| | | |
| | | export async function onRouteChange({ clientRoutes, location }) { |
| | | const menus = getRemoteMenu(); |
| | | if (menus === null && location.pathname !== loginPath) { |
| | | history.go(0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @see https://umijs.org/zh-CN/plugins/plugin-initial-state |
| | |
| | | const { data: userInfo } = await getUserInfo({ |
| | | skipErrorHandler: true, |
| | | }); |
| | | // console.log(userInfo); |
| | | if (userInfo?.avatar === '') { |
| | | userInfo.avatar = defaultAvatar; |
| | | } |
| | |
| | | return { |
| | | ...userInfo |
| | | }; |
| | | |
| | | // const userInfo = await queryCurrentUser({ |
| | | // skipErrorHandler: true, |
| | | // }); |
| | | // console.log(userInfo); |
| | | // return userInfo.data; |
| | | } catch (error) { |
| | | console.log(error); |
| | | history.push(loginPath); |
| | |
| | | }, |
| | | }, |
| | | waterMarkProps: { |
| | | content: initialState?.currentUser?.nickname, |
| | | // content: initialState?.currentUser?.nickname, |
| | | }, |
| | | footerRender: () => <Footer />, |
| | | onPageChange: () => { |
| | |
| | | * @doc https://umijs.org/docs/max/request#配置 |
| | | */ |
| | | export const request = { |
| | | // baseURL: 'http://localhost:9999', |
| | | baseURL: API_BASE_URL, |
| | | ...errorConfig, |
| | | timeout: 10000, |
| | | timeout: 60000, |
| | | // 前置守卫 |
| | | requestInterceptors: [ |
| | | (url, options) => { |
| | |
| | | // 后置守卫 |
| | | responseInterceptors: [ |
| | | (response) => { |
| | | |
| | | if (response?.data?.code === 401) { |
| | | // message.error(intl.formatMessage({ |
| | | // id: 'pages.login.failure', |
| | | // defaultMessage: '登录失败,请重试!', |
| | | // })); |
| | | history.push(loginPath) |
| | | } |
| | | const token = response.headers[TOKEN_HEADER_NAME]; |
| | | if (token) { |
| | | setToken(token); |
| | | } |
| | | console.log(response?.data); |
| | | return response; |
| | | } |
| | | ] |