|
1 | 1 | import React from 'react'; |
2 | | -import { Avatar } from 'antd'; |
3 | | -import { UserOutlined } from '@ant-design/icons'; |
| 2 | +import { MicroApp, IRoute, request as requestClient, RequestConfig } from 'umi'; |
| 3 | +import { PageContainer } from '@ant-design/pro-layout'; |
| 4 | +import { BASE_URL } from './constants'; |
| 5 | +import proLayout from './proLayout'; |
4 | 6 |
|
5 | | -import { |
6 | | - BasicLayoutProps, |
7 | | - Settings as LayoutSettings, |
8 | | -} from '@ant-design/pro-layout'; |
| 7 | +const qiankunApps: Array<QiankunApp> = []; |
9 | 8 |
|
10 | 9 | export async function getInitialState() { |
11 | 10 | return { |
12 | 11 | currentUser: 'Suyi', |
13 | 12 | }; |
14 | 13 | } |
15 | 14 |
|
16 | | -export const layout = ({ |
17 | | - initialState, |
18 | | -}: { |
19 | | - initialState: { settings?: LayoutSettings }; |
20 | | -}): BasicLayoutProps => { |
21 | | - return { |
22 | | - // rightContentRender: () => <RightContent />, |
23 | | - // footerRender: () => <Footer />, |
24 | | - onPageChange: () => { |
25 | | - // const { currentUser } = initialState; |
26 | | - // const { location } = history; |
27 | | - // 如果没有登录,重定向到 login |
28 | | - // if (!currentUser && location.pathname !== '/user/login') { |
29 | | - // history.push('/user/login'); |
30 | | - // } |
31 | | - }, |
32 | | - // menuHeaderRender: undefined, |
33 | | - rightContentRender: () => { |
34 | | - return ( |
35 | | - <div> |
36 | | - <Avatar shape="square" size="small" icon={<UserOutlined />} /> |
37 | | - </div> |
38 | | - ); |
39 | | - }, |
40 | | - |
41 | | - layout: 'top', |
42 | | - navTheme: 'light', |
43 | | - headerHeight: 64, |
44 | | - }; |
| 15 | +export const patchRoutes = ({ routes }: { routes: Array<IRoute> }) => { |
| 16 | + const root = routes[0]; |
| 17 | + |
| 18 | + qiankunApps.forEach((item) => { |
| 19 | + const { name, path, locale, remark } = item; |
| 20 | + if (!root.routes) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + root.routes.push({ |
| 25 | + name, |
| 26 | + path, |
| 27 | + locale: locale || '', |
| 28 | + exact: true, |
| 29 | + hideInMenu: false, |
| 30 | + hideInNav: false, |
| 31 | + component: (props: any) => { |
| 32 | + return ( |
| 33 | + <PageContainer content={remark}> |
| 34 | + <MicroApp name={name} data={{ props }} /> |
| 35 | + </PageContainer> |
| 36 | + ); |
| 37 | + }, |
| 38 | + }); |
| 39 | + }); |
| 40 | +}; |
| 41 | + |
| 42 | +export const layout = proLayout; |
| 43 | + |
| 44 | +export const qiankun = async () => { |
| 45 | + try { |
| 46 | + // const params = { method: 'get', json: {} }; |
| 47 | + // const { apps } = await requestClient<{ |
| 48 | + // apps: QiankunApp[]; |
| 49 | + // }>(`${BASE_URL}/getFeConfig`, params); |
| 50 | + |
| 51 | + // console.log('===getFeConfig', apps); |
| 52 | + |
| 53 | + // apps |
| 54 | + // .filter(({ type }) => type === 'App') |
| 55 | + // .sort((appA, appB) => appA.order - appB.order) |
| 56 | + // .forEach((app) => qiankunApps.push(app)); |
| 57 | + |
| 58 | + return { |
| 59 | + apps: [], |
| 60 | + }; |
| 61 | + } catch (error) { |
| 62 | + return {}; |
| 63 | + } |
45 | 64 | }; |
| 65 | + |
| 66 | +export const request: RequestConfig = { |
| 67 | + timeout: 1000, |
| 68 | + errorConfig: {}, |
| 69 | + middlewares: [], |
| 70 | + requestInterceptors: [], |
| 71 | + responseInterceptors: [], |
| 72 | +}; |
| 73 | + |
| 74 | +interface QiankunApp { |
| 75 | + name: string; |
| 76 | + type: string; |
| 77 | + path: string; |
| 78 | + entry: string; |
| 79 | + order: number; |
| 80 | + remark?: string; |
| 81 | + locale?: string; |
| 82 | +} |
0 commit comments