Skip to content

Commit cb25137

Browse files
committed
feat: add basic config & layout
1 parent 509ba36 commit cb25137

File tree

20 files changed

+511
-123
lines changed

20 files changed

+511
-123
lines changed

.umirc.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

config/basic.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
title: 'CNode.js',
3+
description: 'Node.js专业中文社区',
4+
};

config/config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import config from './basic';
2+
import routes from './routes';
3+
4+
import { defineConfig } from 'umi';
5+
6+
export default defineConfig({
7+
singular: true,
8+
fastRefresh: {},
9+
mfsu: {},
10+
11+
nodeModulesTransform: {
12+
type: 'none',
13+
},
14+
15+
antd: {},
16+
17+
dva: {
18+
immer: true,
19+
},
20+
21+
layout: {
22+
name: config.title,
23+
},
24+
25+
qiankun: {
26+
master: {
27+
apps: [],
28+
},
29+
},
30+
31+
routes,
32+
});

config/routes.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { IRoute } from 'umi';
2+
3+
const routes: IRoute[] = [
4+
{
5+
path: '/',
6+
exact: true,
7+
icon: 'home',
8+
name: 'Home',
9+
title: '主页',
10+
component: '@/page/home',
11+
// access: 'canReadCommon',
12+
hideInNav: false,
13+
hideInMenu: false,
14+
},
15+
];
16+
17+
export default routes;

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,27 @@
2020
]
2121
},
2222
"dependencies": {
23-
"@ant-design/pro-card": "^1.18.20",
24-
"@ant-design/pro-layout": "^6.32.1",
23+
"dotenv": "^10.0.0",
2524
"react": "17.x",
26-
"react-dom": "17.x",
27-
"umi": "^3.5.20"
25+
"react-dom": "17.x"
2826
},
2927
"devDependencies": {
28+
"@ant-design/icons": "^4.7.0",
29+
"@ant-design/pro-card": "^1.18.20",
30+
"@ant-design/pro-layout": "^6.32.1",
31+
"@ant-design/pro-table": "^2.61.9",
32+
"@types/dotenv": "^8.2.0",
3033
"@types/react": "^17.0.0",
3134
"@types/react-dom": "^17.0.0",
35+
"@umijs/plugin-esbuild": "^1.4.1",
36+
"@umijs/plugin-qiankun": "^2.35.4",
3237
"@umijs/preset-react": "1.x",
3338
"@umijs/test": "^3.5.20",
39+
"ahooks": "^3.1.3",
3440
"lint-staged": "^10.0.7",
3541
"prettier": "^2.2.0",
3642
"typescript": "^4.1.2",
43+
"umi": "^3.5.20",
3744
"yorkie": "^2.0.0"
3845
}
3946
}

src/app.tsx

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,82 @@
11
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';
46

5-
import {
6-
BasicLayoutProps,
7-
Settings as LayoutSettings,
8-
} from '@ant-design/pro-layout';
7+
const qiankunApps: Array<QiankunApp> = [];
98

109
export async function getInitialState() {
1110
return {
1211
currentUser: 'Suyi',
1312
};
1413
}
1514

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+
}
4564
};
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.container {
2+
display: flex;
3+
align-items: baseline;
4+
}
5+
6+
.title {
7+
color: #829a82;
8+
margin: 0;
9+
padding: 0;
10+
}
11+
12+
.description {
13+
color: #8264ff;
14+
opacity: 0.55;
15+
margin: 0 0 0 0.4em;
16+
}

src/component/Brand/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import * as styles from './index.module.less';
3+
4+
const Brand: React.FC<Props> = ({ title, description }) => (
5+
<div className={styles.container}>
6+
<h1 className={styles.title}>{title}</h1>
7+
<p className={styles.description}>{description}</p>
8+
</div>
9+
);
10+
11+
export default Brand;
12+
13+
interface Props {
14+
title: string;
15+
description: string;
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.logo {
2+
height: 240px;
3+
width: 240px;
4+
color: #fff;
5+
display: flex;
6+
justify-content: center;
7+
flex-direction: column;
8+
9+
> .title {
10+
font-size: 58px;
11+
letter-spacing: 8px;
12+
width: 240px;
13+
font-family: Verdana, Geneva, Tahoma, sans-serif;
14+
}
15+
16+
> .content {
17+
font-size: 12px;
18+
border-top: 1px solid #fff;
19+
padding-top: 0.2em;
20+
}
21+
}

src/component/Logo/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import * as styles from './index.module.less';
3+
4+
const Logo: React.FC<Props> = ({ title, description }) => (
5+
<div className={styles.logo}>
6+
<div className={styles.title}>{title}</div>
7+
<div className={styles.content}>{description}</div>
8+
</div>
9+
);
10+
11+
export default Logo;
12+
13+
interface Props {
14+
title: string;
15+
description: string;
16+
}

0 commit comments

Comments
 (0)