Skip to content

Commit

Permalink
Feature/lyy umi UI fix 0607 (#11250)
Browse files Browse the repository at this point in the history
* feat(ui): 修复手动声明 routes 时的显示问题

* feat(ui): 修复手动声明 routes 时的显示问题

* feat(ui): routes label 增加自动换行

---------

Co-authored-by: yuyuehui.yyh <yuyuehui.yyh@digital-engine.com>
  • Loading branch information
2 people authored and xiaohuoni committed Jun 13, 2023
1 parent 526e23b commit c25f6e6
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/ant-design-pro/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@ export default defineConfig({
codeSplitting: {
jsStrategy: 'granularChunks',
},
ui: {},
});
8 changes: 5 additions & 3 deletions ui/components/routes/routeChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { modeColorMap } from '@/contants';
import { state as globalState } from '@/models/global';
import { superLongTextHandle } from '@/utils/g6LongText';
import { IIRoute } from '@/utils/realizeRoutes';
import G6 from '@antv/g6';
import { FC, useEffect } from 'react';
Expand Down Expand Up @@ -98,17 +99,18 @@ export const RouteChart: FC<IProps> = ({ routes, onNodeClick }) => {
});

graph.node((node) => {
const { id, depth } = node;
const label = id.split('/').slice(-1)[0];
const { depth, absPath } = node;
const label = ((absPath as string) || '').split('/').slice(-1)[0] || '/';
const { color, backgroud } =
colorList[(depth as number) % colorList.length];

return {
style: {
fill: backgroud,
stroke: color,
fontSize: 12,
},
label,
label: superLongTextHandle(label, 96, 12),
labelCfg: {
position: 'center',
offset: 5,
Expand Down
22 changes: 18 additions & 4 deletions ui/components/routes/routeDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,28 @@ export const RouteDrawer: React.FC<{
mask={false}
>
<Wrapper>
{info.name ? (
<div className="info-item">
<h3>Name</h3>
<div className="label">{info.absPath}</div>
</div>
) : null}
<div className="info-item">
<h3>RoutePath</h3>
<div className="label">{info.absPath}</div>
</div>
<div className="info-item">
<h3>FilePath</h3>
<div className="label">{info.__absFile || info.file}</div>
</div>
{info.__absFile || info.file ? (
<div className="info-item">
<h3>FilePath</h3>
<div className="label">{info.__absFile || info.file}</div>
</div>
) : null}
{info.redirect ? (
<div className="info-item">
<h3>Redirect</h3>
<div className="label">{info.redirect}</div>
</div>
) : null}
<div className="info-item">
<h3>CodeContent</h3>
<div className="code-label">
Expand Down
2 changes: 2 additions & 0 deletions ui/hooks/useAppData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { BuildResult } from '@umijs/bundler-utils/compiled/esbuild';
import { useQuery } from 'umi';

export interface IRoute {
name?: string;
redirect?: string;
path: string;
id: string;
parentId?: string;
Expand Down
1 change: 0 additions & 1 deletion ui/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Helmet, Outlet, styled } from 'umi';

const Wrapper = styled.div`
display: flex;
border: 1px solid var(--subtle-color);
height: 100%;
aside {
min-width: 200px;
Expand Down
31 changes: 31 additions & 0 deletions ui/utils/g6LongText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import G6 from '@antv/g6';

// G6换行符处理超长文本
export const superLongTextHandle = (
str: string,
maxWidth: number,
fontSize: number,
) => {
let currentWidth = 0;
let res = str;
// 区分汉字和字母
const pattern = new RegExp('[\u4E00-\u9FA5]+');
str.split('').forEach((letter, i) => {
if (currentWidth > maxWidth) return;
if (pattern.test(letter)) {
// 中文字符
currentWidth += fontSize;
} else {
// 根据字体大小获取单个字母的宽度
currentWidth += G6.Util.getLetterWidth(letter, fontSize);
}
if (currentWidth > maxWidth) {
res = `${str.slice(0, i)}\n${superLongTextHandle(
str.slice(i),
maxWidth,
fontSize,
)}`;
}
});
return res;
};
4 changes: 3 additions & 1 deletion ui/utils/realizeRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface IIRoute extends PartialIRoute {
children: IIRoute[];
}

export const FAKE_ID = '__FEAKE_LAYOUT__';
export const FAKE_ID = '__FAKE_LAYOUT__';

// 通过对象引用建立route间关系
export const realizeRoutes = (routes: IAppData['routes']): IIRoute[] => {
Expand Down Expand Up @@ -55,6 +55,8 @@ export const realizeRoutes = (routes: IAppData['routes']): IIRoute[] => {
return [
{
id: FAKE_ID,
path: '',
absPath: '',
isLayout: true,
children: relations,
},
Expand Down

0 comments on commit c25f6e6

Please sign in to comment.