Skip to content

Commit 9c210be

Browse files
committed
improve: 巡检联调更新
1 parent 9938784 commit 9c210be

File tree

3 files changed

+84
-134
lines changed

3 files changed

+84
-134
lines changed

ui/src/pages/Inspection/HistoryList.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default function HistoryList() {
109109
<div style={{ color: token.colorError }}>{`失败:${
110110
failedCount || 0
111111
}`}</div>
112-
<div style={{ color: 'purple' }}>{`高风险:${
112+
<div style={{ color: 'rgba(166,29,36,1)' }}>{`高风险:${
113113
criticalCount || 0
114114
}`}</div>
115115
<div style={{ color: 'orange' }}>{`中风险:${
@@ -123,13 +123,9 @@ export default function HistoryList() {
123123
title: '操作',
124124
dataIndex: 'opeation',
125125
width: 100,
126-
render: (text, record) => {
126+
render: (_, record) => {
127127
const id = `${record?.namespace}/${record?.name}`;
128-
return (
129-
<Link to={`/inspection/report/${id}`} target="_blank">
130-
查看报告
131-
</Link>
132-
);
128+
return <Link to={`/inspection/report/${id}`}>查看报告</Link>;
133129
},
134130
},
135131
];

ui/src/pages/Inspection/InspectionList.tsx

Lines changed: 78 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -35,92 +35,43 @@ export default function InspectionList() {
3535
const searchInput = useRef<InputRef>(null);
3636
const [open, setOpen] = useState(false);
3737
const [inspectionPolicies, setInspectionPolicies] = useState({});
38+
const [form] = Form.useForm();
39+
const [activeTab, setActiveTab] = useState('basic');
3840

39-
const { data: listInspectionPolicies, loading } = useRequest(
40-
inspection.listInspectionPolicies,
41-
{
42-
defaultParams: [{}],
43-
},
44-
);
41+
const {
42+
data: listInspectionPolicies,
43+
loading,
44+
refresh,
45+
} = useRequest(inspection.listInspectionPolicies, {
46+
defaultParams: [{}],
47+
});
4548

4649
const { run: triggerInspection } = useRequest(inspection.triggerInspection, {
4750
manual: true,
4851
});
49-
50-
// 手写巡检调度配置请求
5152
const { run: createOrUpdateInspectionPolicy, loading: saveLoading } =
52-
useRequest(
53-
async (body) => {
54-
const response = await fetch('/api/v1/inspection/policies', {
55-
method: 'POST',
56-
headers: {
57-
'Content-Type': 'application/json',
58-
},
59-
body: JSON.stringify(body),
60-
});
61-
62-
if (!response.ok) {
63-
const errorData = await response.json().catch(() => ({}));
64-
throw new Error(
65-
errorData.message ||
66-
`HTTP ${response.status}: ${response.statusText}`,
67-
);
68-
}
69-
70-
return response.json();
71-
},
72-
{
73-
manual: true,
74-
onSuccess: (data) => {
75-
console.log('保存成功:', data);
76-
message.success('调度配置保存成功');
77-
setOpen(false);
78-
form.resetFields();
79-
setActiveTab('basic');
80-
setInspectionPolicies({});
81-
},
82-
onError: (error) => {
83-
console.error('保存失败:', error);
84-
message.error(error.message);
85-
},
53+
useRequest(inspection.createOrUpdateInspectionPolicy, {
54+
manual: true,
55+
onSuccess: () => {
56+
message.success('保存巡检配置成功');
57+
setOpen(false);
58+
form.resetFields();
59+
setActiveTab('basic');
60+
setInspectionPolicies({});
61+
refresh();
8662
},
87-
);
88-
89-
// 手写删除巡检请求
63+
});
9064
const { run: deleteInspectionPolicy } = useRequest(
91-
async (params) => {
92-
const { namespace, name, scenario } = params;
93-
const response = await fetch(
94-
`/api/v1/inspection/policies?namespace=${namespace}&name=${name}&scenario=${scenario}`,
95-
{
96-
method: 'DELETE',
97-
headers: {
98-
'Content-Type': 'application/json',
99-
},
100-
},
101-
);
102-
103-
if (!response.ok) {
104-
const errorData = await response.json().catch(() => ({}));
105-
throw new Error(
106-
errorData.message ||
107-
`HTTP ${response.status}: ${response.statusText}`,
108-
);
109-
}
110-
111-
return response.json();
112-
},
65+
inspection.deleteInspectionPolicy,
11366
{
11467
manual: true,
115-
onSuccess: (data) => {
116-
console.log('删除成功:', data);
117-
message.success('巡检配置删除成功');
118-
// 刷新列表
119-
listInspectionPolicies?.refresh?.();
120-
},
121-
onError: (error) => {
122-
console.error('删除失败:', error);
123-
message.error(error.message);
68+
onSuccess: () => {
69+
message.success('删除巡检配置成功');
70+
setOpen(false);
71+
form.resetFields();
72+
setActiveTab('basic');
73+
setInspectionPolicies({});
74+
refresh();
12475
},
12576
},
12677
);
@@ -135,7 +86,7 @@ export default function InspectionList() {
13586
namespace: `${item?.obCluster?.namespace}/${item?.obCluster?.name}`,
13687
};
13788
});
138-
console.log('real', realData);
89+
13990
const columns = [
14091
{
14192
title: '资源名',
@@ -147,8 +98,6 @@ export default function InspectionList() {
14798
setSearchedColumn: setSearchedColumn,
14899
searchText: searchText,
149100
searchedColumn: searchedColumn,
150-
arraySearch: true,
151-
symbol: '/',
152101
}),
153102

154103
render: (text, record) => {
@@ -164,7 +113,7 @@ export default function InspectionList() {
164113
dataIndex: 'clusterName',
165114
width: 80,
166115
...getColumnSearchProps({
167-
dataIndex: 'name',
116+
dataIndex: 'clusterName',
168117
searchInput: searchInput,
169118
setSearchText: setSearchText,
170119
setSearchedColumn: setSearchedColumn,
@@ -199,7 +148,7 @@ export default function InspectionList() {
199148
<span style={{ color: token.colorWarning }}>{`中${
200149
moderateCount || 0
201150
}`}</span>
202-
<span style={{ color: token.colorError }}>{`${
151+
<span style={{ color: token.colorError }}>{`失败${
203152
failedCount || 0
204153
}`}</span>
205154
<a
@@ -244,7 +193,7 @@ export default function InspectionList() {
244193
const repo = text?.find((item) => item?.scenario === 'performance');
245194
const { failedCount, criticalCount, moderateCount } =
246195
repo?.resultStatistics || {};
247-
console.log('repo', repo);
196+
248197
const id = `${repo?.namespace}/${repo?.name}`;
249198
return (
250199
<div>
@@ -259,7 +208,7 @@ export default function InspectionList() {
259208
<span style={{ color: 'orange' }}>{`中${
260209
moderateCount || 0
261210
}`}</span>
262-
<span style={{ color: token.colorError }}>{`${
211+
<span style={{ color: token.colorError }}>{`失败${
263212
failedCount || 0
264213
}`}</span>
265214
<a
@@ -276,11 +225,11 @@ export default function InspectionList() {
276225
Modal.confirm({
277226
title: '确定要发起性能巡检吗?',
278227
onOk: () => {
279-
triggerInspection({
280-
namespace: repo?.obCluster?.namespace,
281-
name: repo?.obCluster?.name,
282-
scenario: repo?.scenario,
283-
});
228+
triggerInspection(
229+
repo?.obCluster?.namespace,
230+
repo?.obCluster?.name,
231+
repo?.scenario,
232+
);
284233
},
285234
});
286235
}}
@@ -314,7 +263,12 @@ export default function InspectionList() {
314263
<a
315264
onClick={() => {
316265
setOpen(true);
317-
setInspectionPolicies(record);
266+
setInspectionPolicies({
267+
status: record?.status,
268+
latestReports: record?.latestReports || [],
269+
scheduleConfig: record?.scheduleConfig || [],
270+
obCluster: record?.obCluster,
271+
});
318272
}}
319273
>
320274
调度配置
@@ -324,9 +278,6 @@ export default function InspectionList() {
324278
},
325279
];
326280

327-
const [form] = Form.useForm();
328-
const [activeTab, setActiveTab] = useState('basic');
329-
330281
// 获取指定tab的初始值
331282
const getInitialValues = (tabKey) => {
332283
const repo = inspectionPolicies?.scheduleConfig?.find(
@@ -417,11 +368,22 @@ export default function InspectionList() {
417368
Modal.confirm({
418369
title: `确定要删除${getInspectionTypeName()}巡检吗?`,
419370
onOk: () => {
420-
deleteInspectionPolicy({
421-
namespace: repo?.obCluster?.namespace,
422-
name: repo?.obCluster?.name,
423-
scenario: repo?.scenario,
371+
// 从 inspectionPolicies 中获取正确的 namespace 和 name
372+
const namespace = inspectionPolicies?.obCluster?.namespace;
373+
const name = inspectionPolicies?.obCluster?.name;
374+
375+
if (!namespace || !name) {
376+
message.error('无法获取资源信息,请重试');
377+
return;
378+
}
379+
380+
console.log('删除巡检参数:', {
381+
namespace,
382+
name,
383+
scenario: repo?.scenario || tabKey,
424384
});
385+
386+
deleteInspectionPolicy(namespace, name, repo?.scenario);
425387
},
426388
});
427389
};
@@ -530,19 +492,32 @@ export default function InspectionList() {
530492
// 构建调度配置
531493
const scheduleConfig = {
532494
scenario: activeTab,
533-
crontab: cronExpression,
495+
schedule: cronExpression,
534496
};
535497

536-
// 构建请求体
498+
// 构建请求体 - 按照 InspectionPolicy 接口要求
537499
const body = {
538-
...inspectionPolicies,
500+
obCluster: inspectionPolicies?.obCluster,
501+
status: inspectionPolicies?.status || 'enabled',
539502
scheduleConfig: [scheduleConfig],
540503
};
504+
// console.log('inspectionPolicies?.latestReports', inspectionPolicies?.latestReports)
505+
// console.log('cron表达式:', cronExpression);
506+
// console.log('请求体:', body);
507+
// console.log('inspectionPolicies:', inspectionPolicies);
508+
// console.log('namespace:', inspectionPolicies?.obCluster?.namespace);
509+
// console.log('name:', inspectionPolicies?.obCluster?.name);
510+
511+
// 验证必要字段
512+
if (
513+
!inspectionPolicies?.obCluster?.namespace ||
514+
!inspectionPolicies?.obCluster?.name
515+
) {
516+
message.error('缺少必要的资源信息,请重试');
517+
return;
518+
}
541519

542-
console.log('cron表达式:', cronExpression);
543-
console.log('请求体:', body);
544-
console.log('inspectionPolicies:', inspectionPolicies);
545-
520+
console.log('body', body);
546521
// 调用API
547522
createOrUpdateInspectionPolicy(body);
548523
});

ui/src/pages/Inspection/Result.tsx

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inspection } from '@/api';
12
import {
23
Card,
34
Col,
@@ -31,30 +32,8 @@ const Report: React.FC<Props> = () => {
3132
const params = useParams();
3233
const { namespace, name } = params;
3334

34-
// 获取巡检报告数据, 手动写请求函数,自带的请求函数不支持
3535
const { data: inspectionReportData, run: fetchReport } = useRequest(
36-
async (params) => {
37-
const { namespace: namespace1, name: name1 } = params;
38-
const response = await fetch(
39-
`/api/v1/inspection/reports/${namespace1}/${name1}`,
40-
{
41-
method: 'GET',
42-
headers: {
43-
'Content-Type': 'application/json',
44-
},
45-
},
46-
);
47-
48-
if (!response.ok) {
49-
const errorData = await response.json().catch(() => ({}));
50-
throw new Error(
51-
errorData.message ||
52-
`HTTP ${response.status}: ${response.statusText}`,
53-
);
54-
}
55-
56-
return response.json();
57-
},
36+
inspection.getInspectionReport,
5837
{
5938
manual: true,
6039
},
@@ -64,7 +43,7 @@ const Report: React.FC<Props> = () => {
6443

6544
useEffect(() => {
6645
if (namespace && name) {
67-
fetchReport({ namespace, name });
46+
fetchReport(namespace, name);
6847
}
6948
}, [namespace, name]);
7049

0 commit comments

Comments
 (0)