| | |
| | | const defaultAvatar = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png' |
| | | |
| | | export function render(oldRender) { |
| | | console.log("1"); |
| | | const token = getToken(); |
| | | if (!token || token?.length === 0) { |
| | | oldRender(); |
| | |
| | | } |
| | | |
| | | export async function patchClientRoutes({ routes }) { |
| | | console.log("2"); |
| | | patchRouteWithRemoteMenus(routes); |
| | | }; |
| | | |
| | |
| | | * @see https://umijs.org/zh-CN/plugins/plugin-initial-state |
| | | * */ |
| | | export async function getInitialState() { |
| | | console.log("3"); |
| | | const fetchUserInfo = async () => { |
| | | try { |
| | | // const userInfo = await getUserInfo({ |
| | | // skipErrorHandler: true, |
| | | // }); |
| | | // if (userInfo?.user.avatar === '') { |
| | | // response.user.avatar = defaultAvatar; |
| | | // } |
| | | // return { |
| | | // ...userInfo |
| | | // }; |
| | | |
| | | const userInfo = await queryCurrentUser({ |
| | | const { data: userInfo } = await getUserInfo({ |
| | | skipErrorHandler: true, |
| | | }); |
| | | return userInfo.data; |
| | | // console.log(userInfo); |
| | | if (userInfo?.avatar === '') { |
| | | userInfo.avatar = defaultAvatar; |
| | | } |
| | | userInfo.name = userInfo.nickname; |
| | | return { |
| | | ...userInfo |
| | | }; |
| | | |
| | | // const userInfo = await queryCurrentUser({ |
| | | // skipErrorHandler: true, |
| | | // }); |
| | | // console.log(userInfo); |
| | | // return userInfo.data; |
| | | } catch (error) { |
| | | console.log(error); |
| | | history.push(loginPath); |
| | |
| | | |
| | | // ProLayout 支持的api https://procomponents.ant.design/components/layout |
| | | export const layout = ({ initialState, setInitialState }) => { |
| | | console.log("4"); |
| | | return { |
| | | actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />], |
| | | avatarProps: { |
| | |
| | | locale: false, |
| | | // 每当 initialState?.currentUser?.userid 发生修改时重新执行 request |
| | | params: { |
| | | userId: initialState?.currentUser?.userId, |
| | | userId: initialState?.currentUser?.id, |
| | | }, |
| | | request: async () => { |
| | | // console.log(initialState?.currentUser?.userId); |
| | | // if (!initialState?.currentUser?.userId) { |
| | | // return []; |
| | | // } |
| | | if (!initialState?.currentUser?.id) { |
| | | return []; |
| | | } |
| | | return getRemoteMenu(); |
| | | }, |
| | | }, |
| | | waterMarkProps: { |
| | | content: initialState?.currentUser?.name, |
| | | content: initialState?.currentUser?.nickname, |
| | | }, |
| | | footerRender: () => <Footer />, |
| | | onPageChange: () => { |