Skip to content

Commit 1bc93f8

Browse files
author
chj_damon
committed
fix: 修复左侧菜单对图标的支持的问题
调整prettier配置让尖括号换行 删除不合适的示例代码
1 parent 1c115d3 commit 1bc93f8

File tree

19 files changed

+82
-157
lines changed

19 files changed

+82
-157
lines changed

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
singleQuote: true,
55
trailingComma: 'all',
66
bracketSpacing: true,
7-
jsxBracketSameLine: true,
7+
jsxBracketSameLine: false,
88
arrowParens: 'avoid',
99
insertPragma: false,
1010
tabWidth: 2,

config/config.prod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default defineConfig({
4646
{ rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#5bbad5' },
4747
{
4848
rel: 'stylesheet',
49-
href: '//at.alicdn.com/t/font_1509107_vaarx0n4zz.css',
49+
href: '//at.alicdn.com/t/font_1905159_jylqduh3ufd.css',
5050
},
5151
],
5252
inlineLimit: 10,

config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default defineConfig({
3535
{ rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#5bbad5' },
3636
{
3737
rel: 'stylesheet',
38-
href: '//at.alicdn.com/t/font_1509107_vaarx0n4zz.css',
38+
href: '//at.alicdn.com/t/font_1905159_jylqduh3ufd.css',
3939
},
4040
],
4141
chainWebpack(config) {

config/routeConfig.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ export default [
2222
routes: [
2323
{ path: '/', redirect: '/homepage' },
2424
{ path: '/homepage', component: './homepage', title: '首页' },
25-
{
26-
path: '/hotel',
27-
component: './hotel',
28-
routes: [
29-
{ path: '/hotel/hotelInfo', component: './hotel/HotelInfo', title: '酒店基本信息' },
30-
],
31-
},
25+
{ path: '/hotel/hotelInfo', component: './hotel/hotelInfo', title: '酒店基本信息' },
3226
],
3327
},
3428
{ path: '*', component: './404' },

mock/route.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ export default {
66
name: 'homepage',
77
apiUrl: '/homepage',
88
description: '首页',
9+
icon: 'iconyunyingguanli',
910
},
1011
{
1112
name: 'hotel',
12-
apiUrl: '/hotel',
13-
description: '酒店',
13+
apiUrl: '/hotel/hotelInfo',
14+
description: '酒店基本信息',
15+
icon: 'icongongsi',
1416
},
1517
],
1618
code: 20000,

src/app.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function getInitialState() {
3030
type: 'asc',
3131
});
3232
const flatRoutes = arrayUtils.deepFlatten(routes);
33-
flatRoutes.forEach((route) => {
33+
flatRoutes.forEach(route => {
3434
if (route.privilegeList) {
3535
privileges.push(...route.privilegeList);
3636
}
@@ -53,20 +53,20 @@ export async function getInitialState() {
5353
* @param resources
5454
*/
5555
function convertResourceToMenu(list: PrivilegeResource[]): MenuDataItem[] {
56-
return list.map((item) => {
56+
return list.map(item => {
5757
if (item.children && item.children.length > 0) {
5858
return {
5959
name: item.description,
6060
key: `${item.apiUrl}`,
61-
customIcon: item.icon,
61+
icon: item.icon,
6262
path: item.apiUrl,
6363
children: convertResourceToMenu(item.children),
6464
};
6565
}
6666
return {
6767
name: item.description,
6868
key: `${item.apiUrl}`,
69-
customIcon: item.icon,
69+
icon: item.icon,
7070
path: item.apiUrl,
7171
};
7272
});

src/components/Iconfont/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
1+
import React, { CSSProperties } from 'react';
22

33
interface IconfontProps {
44
name: string;
55
className?: string;
6-
style?: any;
6+
style?: CSSProperties;
77
}
88
/** 自定义图标 */
99
const Iconfont: React.FC<IconfontProps> = (props: IconfontProps) => {

src/components/Loading.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default function Loading() {
1010
display: 'flex',
1111
justifyContent: 'center',
1212
alignItems: 'center',
13-
}}>
13+
}}
14+
>
1415
<Spin size="large" />
1516
</div>
1617
);

src/layouts/BasicLayout/index.module.less

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
.basic-layout {
23
width: 100%;
34

@@ -7,5 +8,37 @@
78
min-height: calc(100vh - 64px - 32px);
89
margin: 16px;
910
}
11+
.ant-menu .ant-menu-item {
12+
padding: 0 16px !important;
13+
}
14+
.ant-menu-item .iconfont {
15+
min-width: 14px;
16+
margin-right: 10px;
17+
font-size: 14px;
18+
transition: font-size 0.15s cubic-bezier(0.215, 0.61, 0.355, 1), margin 0.3s cubic-bezier(0.645, 0.045, 0.355, 1), color 0.3s
19+
}
20+
.ant-menu-item .iconfont + span {
21+
opacity: 1;
22+
transition: opacity 0.3s cubic-bezier(0.645, 0.045, 0.355, 1), width 0.3s cubic-bezier(0.645, 0.045, 0.355, 1), color 0.3s;
23+
}
24+
25+
.ant-menu-dark .ant-menu-item .iconfont {
26+
color: #fff;
27+
}
28+
.ant-menu-inline-collapsed .ant-menu-item .iconfont {
29+
margin: 0;
30+
font-size: 16px;
31+
line-height: 40px;
32+
display: inline-block;
33+
}
34+
35+
.ant-menu-dark .ant-menu-item span.ant-pro-menu-item-title {
36+
transition: none;
37+
}
38+
.ant-menu-inline-collapsed .ant-menu-item .iconfont + span.ant-pro-menu-item-title {
39+
display: inline-block;
40+
max-width: 0;
41+
opacity: 0;
42+
}
1043
}
1144
}

src/layouts/BasicLayout/index.tsx

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
import ProLayout from '@ant-design/pro-layout';
2+
import ProLayout, { MenuDataItem } from '@ant-design/pro-layout';
33
import type { IRouteComponentProps } from 'umi';
44
import { Link, useModel } from 'umi';
55
import Iconfont from '@/components/Iconfont';
@@ -8,53 +8,35 @@ import Logo from './components/Logo';
88
import defaultSettings from './defaultSettings';
99
import styles from './index.module.less';
1010

11+
const iconMap = {
12+
iconyunyingguanli: <Iconfont name="iconyunyingguanli" style={{ marginRight: 10 }} />,
13+
icongongsi: <Iconfont name="icongongsi" style={{ marginRight: 10 }} />,
14+
};
1115
export default function BasicLayout(props: IRouteComponentProps) {
1216
const [collapsed, handleMenuCollapse] = useState<boolean>(false);
1317
const { initialState } = useModel('@@initialState');
1418

1519
const { menus = [] } = initialState!;
16-
const menuDataRender = () => menus;
20+
21+
const loopMenuItem = (menus: MenuDataItem[]): MenuDataItem[] =>
22+
menus.map(({ icon, children, ...item }) => ({
23+
...item,
24+
icon: icon && iconMap[icon as string],
25+
children: children && loopMenuItem(children),
26+
}));
1727

1828
return (
1929
<ProLayout
2030
className={styles['basic-layout']}
2131
logo={<Logo />}
2232
collapsed={collapsed}
2333
onCollapse={handleMenuCollapse}
24-
menuHeaderRender={(logoDom, titleDom) => (
25-
<Link to="/">
26-
{logoDom}
27-
{titleDom}
28-
</Link>
29-
)}
34+
menuDataRender={() => loopMenuItem(menus)}
3035
menuItemRender={(menuItemProps, defaultDom) => {
31-
return (
32-
<Link to={menuItemProps.path || '/'}>
33-
<span>
34-
{menuItemProps.customIcon && (
35-
<Iconfont
36-
name={menuItemProps.customIcon}
37-
style={{ marginRight: 10, fontSize: 17 }}
38-
/>
39-
)}
40-
</span>
41-
<span>{defaultDom}</span>
42-
</Link>
43-
);
44-
}}
45-
subMenuItemRender={(menuItemProps: any, defaultDom: any) => {
46-
return (
47-
<span>
48-
{menuItemProps.customIcon && (
49-
<Iconfont name={menuItemProps.customIcon} style={{ marginRight: 10, fontSize: 17 }} />
50-
)}
51-
<span>{defaultDom}</span>
52-
</span>
53-
);
36+
return <Link to={menuItemProps.path || '/'}>{defaultDom}</Link>;
5437
}}
5538
rightContentRender={(/** props: HeaderViewProps */) => <CustomHeaderRight />}
5639
onMenuHeaderClick={() => props.history.push('/')}
57-
menuDataRender={menuDataRender}
5840
{...defaultSettings}
5941
>
6042
{props.children}

0 commit comments

Comments
 (0)