Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/lyy umi UI fix 0607 #11250

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading