Skip to content

Commit d9e1323

Browse files
committed
fix: 攻击路径图bug 修改
1 parent 36d53d1 commit d9e1323

File tree

11 files changed

+124
-34
lines changed

11 files changed

+124
-34
lines changed

src/compoments/AntdCharts/G6Tree/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ const TreeGraphComponent: React.FC<Props> = ({ data }) => {
194194
(oldNode.children || []).forEach((child) => {
195195
if (!newMap.has(child.id)) {
196196
const node = graph.findById(child.id);
197-
if (node) graph.removeItem(node);
197+
if (node) graph.removeItem(node, true);
198198
}
199199
});
200200

@@ -213,7 +213,7 @@ const TreeGraphComponent: React.FC<Props> = ({ data }) => {
213213
tree.collapsed = false;
214214
tree.children.forEach((child) => {
215215
if (child.children && child.children.length > 0)
216-
child.collapsed = true;
216+
child.collapsed = false;
217217
});
218218
return tree;
219219
};

src/pages/Login.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ const Login = () => {
132132

133133
const loginFn = async (values: FieldType) => {
134134
try {
135-
console.log(values, 'values');
136135
await login(values)
137136
.then(() => {
138137
updatePower();

src/pages/ReportManage/compoments/ColumnsOperate.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ const ColumnsOperateRender: FC<{
5252
}
5353
};
5454

55-
const handPreviewReport = async () => {
55+
const handPreviewReport = async (report_title: string) => {
5656
if (render?.report_id) {
5757
const { data } = await getTimelinId(render!.report_id);
5858
const block = data.data.data.blocks;
59-
PreviewReportRef.current?.open(block);
59+
PreviewReportRef.current?.open(block, report_title);
6060
} else {
6161
message.error('获取失败');
6262
}
@@ -71,7 +71,7 @@ const ColumnsOperateRender: FC<{
7171
width: '32px',
7272
borderRight: '1px solid #EAECF3',
7373
}}
74-
onClick={() => handPreviewReport()}
74+
onClick={() => handPreviewReport(render?.report_title)}
7575
/>
7676
</div>
7777
</Tooltip>

src/pages/ReportManage/compoments/PreviewReportDrawer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ const PreviewReportDrawer = forwardRef<
3636
const [blocks, setBlocks] = useSafeState<TReportTemplateProps['blocks']>(
3737
[],
3838
);
39+
const reportTitleRef = useRef('');
3940

4041
useImperativeHandle(ref, () => ({
41-
open(block) {
42+
open(block, report_title) {
4243
drawer.open();
4344
setBlocks(block);
45+
reportTitleRef.current = report_title;
4446
},
4547
}));
4648

@@ -74,7 +76,7 @@ const PreviewReportDrawer = forwardRef<
7476
const downloadPdf = () => {
7577
if (!divRef || !divRef.current) return;
7678
const div = divRef.current;
77-
html2pdf().from(div).set(opt).save(); // 导出
79+
html2pdf().from(div).set(opt(reportTitleRef.current)).save(); // 导出
7880
};
7981

8082
return (

src/pages/TaskDetail/TaskRoadmap.tsx

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { useMemo, useEffect, type FC } from 'react';
1+
import { useMemo, useEffect, type FC, useRef } from 'react';
22
import TreeGraphComponent from '@/compoments/AntdCharts/G6Tree';
33
import { Empty, Radio, Steps } from 'antd';
44
import { targetRouteMap } from './compoments/utils';
5-
import { useRequest } from 'ahooks';
5+
import { useRequest, useUpdateEffect } from 'ahooks';
66
import { getAttackPath } from '@/apis/MessageCollectApi';
77
import type { TTaskDetailHeaderGroups } from './types';
8+
import type { TreeGraphData } from '@antv/g6';
89

910
interface TTaskRoadmpProps {
1011
setHeaderGroupValue: (value: TTaskDetailHeaderGroups) => void;
@@ -17,13 +18,81 @@ interface TTaskRoadmpProps {
1718
}[];
1819
}
1920

21+
export const mergeTree = (
22+
oldNode: TreeGraphData,
23+
newNode: TreeGraphData,
24+
): TreeGraphData => {
25+
const oldChildren = oldNode.children ?? [];
26+
const newChildren = newNode.children ?? [];
27+
28+
const newMap = new Map(newChildren.map((c) => [c.id, c]));
29+
30+
const mergedChildren = oldChildren.map((oldChild, index, arr) => {
31+
const newChild = newMap.get(oldChild.id);
32+
let merged: TreeGraphData = newChild
33+
? mergeTree(oldChild, newChild)
34+
: { id: oldChild.id, children: oldChild.children ?? [] };
35+
36+
// 上一节点和上上节点
37+
const prev1 = index > 0 ? arr?.[index - 1] : undefined;
38+
const prev2 = index > 1 ? arr?.[index - 2] : undefined;
39+
40+
['x', 'y', 'depth', 'size'].forEach((key) => {
41+
const k = key as keyof TreeGraphData;
42+
const val = merged[k];
43+
44+
if (val === null || val === undefined) {
45+
const p1 = prev1?.[k] ?? 40;
46+
const p2 = prev2?.[k] ?? 0;
47+
48+
if (typeof p1 === 'number' && typeof p2 === 'number') {
49+
merged[k] = p1 + (p1 - p2); // 线性推算
50+
} else if (typeof p1 === 'number') {
51+
merged[k] = p1 + 40; // 简单增量
52+
} else {
53+
merged[k] = 0; // 默认值
54+
}
55+
}
56+
});
57+
58+
if (!merged.type) merged.type = 'collapse-node';
59+
if (!merged.size) merged.size = 26;
60+
61+
// 递归处理 children
62+
if (merged.children && merged.children.length) {
63+
merged.children = merged.children.map((c) =>
64+
mergeTree(c, newMap.get(c.id) ?? c),
65+
);
66+
}
67+
68+
return merged;
69+
});
70+
71+
// 补充 newChildren 中不存在于 oldChildren 的节点
72+
const oldIds = new Set(oldChildren.map((c) => c.id));
73+
const additional = newChildren
74+
.filter((c) => !oldIds.has(c.id))
75+
.map((c) => mergeTree({ id: c.id, children: [] }, c));
76+
77+
return {
78+
id: oldNode.id,
79+
children: [...mergedChildren, ...additional],
80+
x: oldNode.x ?? 0,
81+
y: oldNode.y ?? 0,
82+
depth: oldNode.depth ?? 0,
83+
type: oldNode.type ?? 'collapse-node',
84+
size: oldNode.size ?? 26,
85+
};
86+
};
87+
2088
const TaskRoadmap: FC<TTaskRoadmpProps> = ({
2189
headerGroupValue,
2290
headerGroupValueOptions,
2391
setHeaderGroupValue,
2492
task_id,
2593
script_type,
2694
}) => {
95+
const oldAttackPathDataRef = useRef<TreeGraphData>();
2796
const stepsList = useMemo(() => {
2897
const targetList =
2998
targetRouteMap[script_type as keyof typeof targetRouteMap].list;
@@ -36,19 +105,31 @@ const TaskRoadmap: FC<TTaskRoadmpProps> = ({
36105
task_id,
37106
script_type,
38107
});
39-
40-
return data;
108+
const resultData = oldAttackPathDataRef.current
109+
? mergeTree(oldAttackPathDataRef.current, data)
110+
: data;
111+
return resultData;
41112
},
42113
{
43114
manual: true,
44-
pollingInterval: 8000,
115+
pollingInterval: 10000,
45116
},
46117
);
47118

48119
useEffect(() => {
49120
run();
50121
}, []);
51122

123+
useUpdateEffect(() => {
124+
if (
125+
typeof data === 'object' &&
126+
data !== null &&
127+
Object.keys(data)?.length !== 0
128+
) {
129+
oldAttackPathDataRef.current = data;
130+
}
131+
}, [data]);
132+
52133
const StepsCurrentMemo = useMemo(() => {
53134
const targetList =
54135
targetRouteMap[script_type as keyof typeof targetRouteMap].list;

src/pages/TaskDetail/compoments/EmialModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const EmailMoadl = forwardRef<
8484

8585
html2pdf()
8686
.from(div)
87-
.set(opt)
87+
.set(opt())
8888
.toPdf()
8989
.get('pdf')
9090
.then(async (pdf: any) => {

src/pages/TaskDetail/compoments/ScriptDetailButton.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ import html2pdf from 'html2pdf.js';
2020
import { EmailMoadl } from './EmialModal';
2121
import type { UseModalRefType } from '@/compoments/WizardModal/useModal';
2222

23-
export const opt = {
24-
margin: [10, 5, 10, 5],
25-
filename: 'report.pdf',
26-
image: { type: 'jpeg', quality: 0.95 },
27-
jsPDF: {
28-
format: 'a4',
29-
},
30-
html2canvas: {
31-
scale: 1.2,
32-
},
33-
pagebreak: {
34-
// 自动分页控制属性
35-
// mode: 'avoid-all',
36-
after: '#cover',
37-
},
23+
export const opt = (filename?: string) => {
24+
return {
25+
margin: [10, 5, 10, 5],
26+
filename: filename ?? 'report.pdf',
27+
image: { type: 'jpeg', quality: 0.95 },
28+
jsPDF: {
29+
format: 'a4',
30+
},
31+
html2canvas: {
32+
scale: 1.2,
33+
},
34+
pagebreak: {
35+
// 自动分页控制属性
36+
// mode: 'avoid-all',
37+
after: '#cover',
38+
},
39+
};
3840
};
3941

4042
const ScriptDetailButton = forwardRef<
@@ -51,10 +53,12 @@ const ScriptDetailButton = forwardRef<
5153
const [blocks, setBlocks] = useSafeState<TReportTemplateProps['blocks']>(
5254
[],
5355
);
56+
const taskIdRef = useRef('');
5457

5558
useImperativeHandle(ref, () => ({
56-
async open(items) {
59+
async open(items, task_id) {
5760
setBlocks(items?.blocks);
61+
taskIdRef.current = task_id;
5862
drawer.open();
5963
},
6064
}));
@@ -92,7 +96,7 @@ const ScriptDetailButton = forwardRef<
9296
const downloadPdf = () => {
9397
if (!divRef || !divRef.current) return;
9498
const div = divRef.current;
95-
html2pdf().from(div).set(opt).save(); // 导出
99+
html2pdf().from(div).set(opt(taskIdRef.current)).save(); // 导出
96100
};
97101

98102
return (

src/pages/TaskDetail/compoments/TaskDetailSider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ const TaskDetailSider: FC<TTaskDetailSiderProps> = ({
292292
</div>
293293
<ViewReportDrawer
294294
runtime_id={it.runtime_id}
295+
task_id={it.task_id}
295296
/>
296297
</div>
297298
))

src/pages/TaskDetail/compoments/ViewReportDrawer.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import { ScriptDetailButton } from './ScriptDetailButton';
88
import { useRequest } from 'ahooks';
99
import { getTimelinRuntimeId } from '@/apis/taskDetail';
1010

11-
const ViewReportDrawer: FC<{ runtime_id: string }> = ({ runtime_id }) => {
11+
const ViewReportDrawer: FC<{ runtime_id: string; task_id: string }> = ({
12+
runtime_id,
13+
task_id,
14+
}) => {
1215
const scriptDetailDrawerRef = useRef<UseDrawerRefType>(null);
1316

1417
const { run, loading } = useRequest(getTimelinRuntimeId, {
1518
manual: true,
1619
onSuccess: async (value) => {
1720
const blocks = value?.data?.data?.data ?? [];
18-
scriptDetailDrawerRef.current?.open(blocks);
21+
scriptDetailDrawerRef.current?.open(blocks, task_id);
1922
},
2023
onError: async (err) => {
2124
message.destroy();

src/pages/TaskScript/compoment/StartUpScriptModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ const StartUpScriptModal = forwardRef<
161161
.then(() => {
162162
const targetSetFormData = {
163163
task_id: `[${items?.script_name}]-[${dayjs().format('M月DD日')}]-[${randomString(6)}]-`,
164-
165164
...items,
166165
execution_date:
167166
items?.sched_type === 2 && items?.start_timestamp

0 commit comments

Comments
 (0)