Skip to content

Commit

Permalink
fix: 修复左侧菜单对图标的支持的问题
Browse files Browse the repository at this point in the history
调整prettier配置让尖括号换行
删除不合适的示例代码
  • Loading branch information
chj_damon committed Apr 14, 2021
1 parent 1c115d3 commit 1bc93f8
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
singleQuote: true,
trailingComma: 'all',
bracketSpacing: true,
jsxBracketSameLine: true,
jsxBracketSameLine: false,
arrowParens: 'avoid',
insertPragma: false,
tabWidth: 2,
Expand Down
2 changes: 1 addition & 1 deletion config/config.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineConfig({
{ rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#5bbad5' },
{
rel: 'stylesheet',
href: '//at.alicdn.com/t/font_1509107_vaarx0n4zz.css',
href: '//at.alicdn.com/t/font_1905159_jylqduh3ufd.css',
},
],
inlineLimit: 10,
Expand Down
2 changes: 1 addition & 1 deletion config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default defineConfig({
{ rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#5bbad5' },
{
rel: 'stylesheet',
href: '//at.alicdn.com/t/font_1509107_vaarx0n4zz.css',
href: '//at.alicdn.com/t/font_1905159_jylqduh3ufd.css',
},
],
chainWebpack(config) {
Expand Down
8 changes: 1 addition & 7 deletions config/routeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ export default [
routes: [
{ path: '/', redirect: '/homepage' },
{ path: '/homepage', component: './homepage', title: '首页' },
{
path: '/hotel',
component: './hotel',
routes: [
{ path: '/hotel/hotelInfo', component: './hotel/HotelInfo', title: '酒店基本信息' },
],
},
{ path: '/hotel/hotelInfo', component: './hotel/hotelInfo', title: '酒店基本信息' },
],
},
{ path: '*', component: './404' },
Expand Down
6 changes: 4 additions & 2 deletions mock/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export default {
name: 'homepage',
apiUrl: '/homepage',
description: '首页',
icon: 'iconyunyingguanli',
},
{
name: 'hotel',
apiUrl: '/hotel',
description: '酒店',
apiUrl: '/hotel/hotelInfo',
description: '酒店基本信息',
icon: 'icongongsi',
},
],
code: 20000,
Expand Down
8 changes: 4 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function getInitialState() {
type: 'asc',
});
const flatRoutes = arrayUtils.deepFlatten(routes);
flatRoutes.forEach((route) => {
flatRoutes.forEach(route => {
if (route.privilegeList) {
privileges.push(...route.privilegeList);
}
Expand All @@ -53,20 +53,20 @@ export async function getInitialState() {
* @param resources
*/
function convertResourceToMenu(list: PrivilegeResource[]): MenuDataItem[] {
return list.map((item) => {
return list.map(item => {
if (item.children && item.children.length > 0) {
return {
name: item.description,
key: `${item.apiUrl}`,
customIcon: item.icon,
icon: item.icon,
path: item.apiUrl,
children: convertResourceToMenu(item.children),
};
}
return {
name: item.description,
key: `${item.apiUrl}`,
customIcon: item.icon,
icon: item.icon,
path: item.apiUrl,
};
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/Iconfont/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import React, { CSSProperties } from 'react';

interface IconfontProps {
name: string;
className?: string;
style?: any;
style?: CSSProperties;
}
/** 自定义图标 */
const Iconfont: React.FC<IconfontProps> = (props: IconfontProps) => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default function Loading() {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
}}
>
<Spin size="large" />
</div>
);
Expand Down
33 changes: 33 additions & 0 deletions src/layouts/BasicLayout/index.module.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

.basic-layout {
width: 100%;

Expand All @@ -7,5 +8,37 @@
min-height: calc(100vh - 64px - 32px);
margin: 16px;
}
.ant-menu .ant-menu-item {
padding: 0 16px !important;
}
.ant-menu-item .iconfont {
min-width: 14px;
margin-right: 10px;
font-size: 14px;
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
}
.ant-menu-item .iconfont + span {
opacity: 1;
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;
}

.ant-menu-dark .ant-menu-item .iconfont {
color: #fff;
}
.ant-menu-inline-collapsed .ant-menu-item .iconfont {
margin: 0;
font-size: 16px;
line-height: 40px;
display: inline-block;
}

.ant-menu-dark .ant-menu-item span.ant-pro-menu-item-title {
transition: none;
}
.ant-menu-inline-collapsed .ant-menu-item .iconfont + span.ant-pro-menu-item-title {
display: inline-block;
max-width: 0;
opacity: 0;
}
}
}
46 changes: 14 additions & 32 deletions src/layouts/BasicLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import ProLayout from '@ant-design/pro-layout';
import ProLayout, { MenuDataItem } from '@ant-design/pro-layout';
import type { IRouteComponentProps } from 'umi';
import { Link, useModel } from 'umi';
import Iconfont from '@/components/Iconfont';
Expand All @@ -8,53 +8,35 @@ import Logo from './components/Logo';
import defaultSettings from './defaultSettings';
import styles from './index.module.less';

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

const { menus = [] } = initialState!;
const menuDataRender = () => menus;

const loopMenuItem = (menus: MenuDataItem[]): MenuDataItem[] =>
menus.map(({ icon, children, ...item }) => ({
...item,
icon: icon && iconMap[icon as string],
children: children && loopMenuItem(children),
}));

return (
<ProLayout
className={styles['basic-layout']}
logo={<Logo />}
collapsed={collapsed}
onCollapse={handleMenuCollapse}
menuHeaderRender={(logoDom, titleDom) => (
<Link to="/">
{logoDom}
{titleDom}
</Link>
)}
menuDataRender={() => loopMenuItem(menus)}
menuItemRender={(menuItemProps, defaultDom) => {
return (
<Link to={menuItemProps.path || '/'}>
<span>
{menuItemProps.customIcon && (
<Iconfont
name={menuItemProps.customIcon}
style={{ marginRight: 10, fontSize: 17 }}
/>
)}
</span>
<span>{defaultDom}</span>
</Link>
);
}}
subMenuItemRender={(menuItemProps: any, defaultDom: any) => {
return (
<span>
{menuItemProps.customIcon && (
<Iconfont name={menuItemProps.customIcon} style={{ marginRight: 10, fontSize: 17 }} />
)}
<span>{defaultDom}</span>
</span>
);
return <Link to={menuItemProps.path || '/'}>{defaultDom}</Link>;
}}
rightContentRender={(/** props: HeaderViewProps */) => <CustomHeaderRight />}
onMenuHeaderClick={() => props.history.push('/')}
menuDataRender={menuDataRender}
{...defaultSettings}
>
{props.children}
Expand Down
7 changes: 4 additions & 3 deletions src/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default (props: IRouteComponentProps) => {
<ConfigProvider
locale={zhCN}
renderEmpty={() => <Empty image={require('@/assets/pic_empty.png')} description="暂无数据" />}
getPopupContainer={trigger => trigger.parentElement || document.body}
form={{ validateMessages }}>
form={{ validateMessages }}
>
<SWRConfig
value={{
/** 是否开启suspense模式,默认值false */
Expand Down Expand Up @@ -61,7 +61,8 @@ export default (props: IRouteComponentProps) => {
// compare(a, b)
/** 用于检测是否暂停重新验证的函数,当返回 true 时将忽略所请求的数据和错误。默认返回 false */
// isPaused()
}}>
}}
>
<AuthContext.Provider value={authService}>{props.children}</AuthContext.Provider>
</SWRConfig>
</ConfigProvider>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default () => {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
}}
>
<div style={{ width: 600, textAlign: 'center' }}>
<img alt="" src={require('@/assets/pic_404.png')} style={{ width: '100%' }} />
<div style={{ lineHeight: 3 }}>对不起,您访问的页面不存在</div>
Expand Down
23 changes: 2 additions & 21 deletions src/pages/hotel/HotelInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import { Button } from 'antd';
import React from 'react';
import { Link } from 'umi';
import React, { useContext } from 'react';
import { HotelDispatchContext } from '../useHotelService';
import HotelOtherInfo from '../HotelOtherInfo';
import HotelMetaInfo from '../HotelMetaInfo';

export default function HotelInfo() {
const {setValue, setName} = useContext(HotelDispatchContext);

const changeValue = () => {
setValue(Math.random() * 100);
};

const changeName = () => {
setName((Math.random() * 100).toFixed(2));
};

console.log('222')
return (
<div>
<div>酒店基本信息</div>
<Button onClick={changeValue}>修改value</Button>
<Button onClick={changeName}>修改name</Button>
<Link to="/homepage">homepage</Link>
<HotelOtherInfo />
<HotelMetaInfo />
</div>
);
};
}
13 changes: 0 additions & 13 deletions src/pages/hotel/HotelMetaInfo/index.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/pages/hotel/HotelOtherInfo/index.tsx

This file was deleted.

11 changes: 11 additions & 0 deletions src/pages/hotel/hotelInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { Link } from 'umi';

export default function HotelInfo() {
return (
<div>
<div>酒店基本信息</div>
<Link to="/homepage">homepage</Link>
</div>
);
}
18 changes: 0 additions & 18 deletions src/pages/hotel/index.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions src/pages/hotel/useHotelService.test.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/pages/hotel/useHotelService.ts

This file was deleted.

0 comments on commit 1bc93f8

Please sign in to comment.