Skip to content

Commit 2319271

Browse files
committed
improve: 联调更新
1 parent 9c210be commit 2319271

File tree

5 files changed

+244
-181
lines changed

5 files changed

+244
-181
lines changed

ui/src/pages/Inspection/HistoryList.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export default function HistoryList() {
1717
},
1818
);
1919

20-
console.log('listInspectionReports', listInspectionReports);
21-
22-
const dataSource = listInspectionReports?.data || [];
20+
const dataSource = (listInspectionReports?.data || []).sort((a, b) => {
21+
// 按照 startTime 时间由近到远排列(最新的在前)
22+
return (b.startTime || 0) - (a.startTime || 0);
23+
});
2324

2425
const statusList = [
2526
{
@@ -125,7 +126,14 @@ export default function HistoryList() {
125126
width: 100,
126127
render: (_, record) => {
127128
const id = `${record?.namespace}/${record?.name}`;
128-
return <Link to={`/inspection/report/${id}`}>查看报告</Link>;
129+
return (
130+
<Link
131+
disabled={record?.status === 'running'}
132+
to={`/inspection/report/${id}`}
133+
>
134+
查看报告
135+
</Link>
136+
);
129137
},
130138
},
131139
];

ui/src/pages/Inspection/InspectionList.tsx

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default function InspectionList() {
4848

4949
const { run: triggerInspection } = useRequest(inspection.triggerInspection, {
5050
manual: true,
51+
onSuccess: () => {
52+
message.success('发起巡检成功');
53+
refresh();
54+
},
5155
});
5256
const { run: createOrUpdateInspectionPolicy, loading: saveLoading } =
5357
useRequest(inspection.createOrUpdateInspectionPolicy, {
@@ -128,16 +132,19 @@ export default function InspectionList() {
128132
title: '基础巡检',
129133
dataIndex: 'latestReports',
130134
sorter: true,
131-
render: (text) => {
135+
render: (text, record) => {
132136
const repo = text?.find((item) => item?.scenario === 'basic');
133137
const { failedCount, criticalCount, moderateCount } =
134138
repo?.resultStatistics || {};
135139

136140
const id = `${repo?.namespace}/${repo?.name}`;
137141

142+
const showContent = record?.scheduleConfig?.find(
143+
(item) => item?.scenario === 'basic',
144+
);
138145
return (
139146
<div>
140-
{repo ? (
147+
{showContent ? (
141148
<>
142149
<div>{`巡检时间:${formatTime(repo?.finishTime)}`}</div>
143150
<Space size={6}>
@@ -160,15 +167,14 @@ export default function InspectionList() {
160167
查看报告
161168
</a>
162169
<a
163-
disabled={!repo}
164170
onClick={() =>
165171
Modal.confirm({
166172
title: '确定要发起基础巡检吗?',
167173
onOk: () => {
168174
triggerInspection(
169-
repo?.obCluster?.namespace,
170-
repo?.obCluster?.name,
171-
repo?.scenario,
175+
record.obCluster.namespace,
176+
record.obCluster.name,
177+
'basic',
172178
);
173179
},
174180
})
@@ -189,15 +195,18 @@ export default function InspectionList() {
189195
title: '性能巡检',
190196
dataIndex: 'latestReports',
191197
sorter: true,
192-
render: (text) => {
198+
render: (text, record) => {
199+
const showContent = record?.scheduleConfig?.find(
200+
(item) => item?.scenario === 'performance',
201+
);
193202
const repo = text?.find((item) => item?.scenario === 'performance');
194203
const { failedCount, criticalCount, moderateCount } =
195204
repo?.resultStatistics || {};
196205

197206
const id = `${repo?.namespace}/${repo?.name}`;
198207
return (
199208
<div>
200-
{repo ? (
209+
{showContent ? (
201210
<>
202211
<div>{`巡检时间:${formatTime(repo?.finishTime)}`}</div>
203212
<Space size={6}>
@@ -220,15 +229,14 @@ export default function InspectionList() {
220229
查看报告
221230
</a>
222231
<a
223-
disabled={!repo}
224232
onClick={() => {
225233
Modal.confirm({
226234
title: '确定要发起性能巡检吗?',
227235
onOk: () => {
228236
triggerInspection(
229-
repo?.obCluster?.namespace,
230-
repo?.obCluster?.name,
231-
repo?.scenario,
237+
record.obCluster.namespace,
238+
record.obCluster.name,
239+
'performance',
232240
);
233241
},
234242
});
@@ -263,12 +271,15 @@ export default function InspectionList() {
263271
<a
264272
onClick={() => {
265273
setOpen(true);
266-
setInspectionPolicies({
267-
status: record?.status,
268-
latestReports: record?.latestReports || [],
269-
scheduleConfig: record?.scheduleConfig || [],
270-
obCluster: record?.obCluster,
271-
});
274+
setInspectionPolicies(record);
275+
// 重置表单状态,确保每次打开都是干净的状态
276+
form.resetFields();
277+
setActiveTab('basic');
278+
// 延迟设置初始值,确保 inspectionPolicies 已经更新
279+
setTimeout(() => {
280+
const initialValues = getInitialValues('basic');
281+
form.setFieldsValue(initialValues);
282+
}, 0);
272283
}}
273284
>
274285
调度配置
@@ -284,27 +295,60 @@ export default function InspectionList() {
284295
(item) => item?.scenario === tabKey,
285296
);
286297

287-
const schedule = parseCronExpression(repo?.schedule).data;
298+
// 尝试从不同的字段名获取cron表达式
299+
const cronExpression = repo?.crontab || repo?.schedule || '';
300+
301+
const parseResult = parseCronExpression(cronExpression);
302+
303+
// 如果解析失败,使用默认值
304+
const schedule = parseResult.success ? parseResult.data : null;
288305

289306
const getScheduleMode = () => {
290-
if (schedule?.dayOfMonth) return 'Monthly';
291-
if (schedule?.dayOfWeek) return 'Weekly';
292-
return 'Daily';
307+
if (schedule?.dayOfMonth && schedule.dayOfMonth !== '*') return 'Monthly';
308+
if (schedule?.dayOfWeek && schedule.dayOfWeek !== '*') return 'Weekly';
309+
return 'Dayly';
293310
};
294311

295312
const getScheduleDays = () => {
296-
if (schedule?.dayOfMonth) return [toNumber(schedule.dayOfMonth)];
297-
if (schedule?.dayOfWeek) return [schedule.dayOfWeek];
313+
if (schedule?.dayOfMonth && schedule.dayOfMonth !== '*') {
314+
// 处理多个日期的情况,如 "1,15" 或 "1-5"
315+
if (schedule.dayOfMonth.includes(',')) {
316+
return schedule.dayOfMonth.split(',').map((day) => toNumber(day));
317+
}
318+
if (schedule.dayOfMonth.includes('-')) {
319+
const [start] = schedule.dayOfMonth
320+
.split('-')
321+
.map((day) => toNumber(day));
322+
return [start]; // 只取第一个值作为示例
323+
}
324+
return [toNumber(schedule.dayOfMonth)];
325+
}
326+
if (schedule?.dayOfWeek && schedule.dayOfWeek !== '*') {
327+
// 处理多个星期的情况,如 "1,3,5" 或 "1-5"
328+
if (schedule.dayOfWeek.includes(',')) {
329+
return schedule.dayOfWeek.split(',').map((day) => toNumber(day));
330+
}
331+
if (schedule.dayOfWeek.includes('-')) {
332+
const [start] = schedule.dayOfWeek
333+
.split('-')
334+
.map((day) => toNumber(day));
335+
return [start]; // 只取第一个值作为示例
336+
}
337+
return [toNumber(schedule.dayOfWeek)];
338+
}
298339
return [];
299340
};
300341

301342
const getScheduleTime = () => {
302-
if (schedule?.hour) {
303-
return dayjs(
304-
`${schedule.hour}:${schedule.minute}`,
305-
TIME_FORMAT_WITHOUT_SECOND,
306-
);
343+
if (schedule?.hour !== undefined && schedule?.minute !== undefined) {
344+
// 确保时间格式正确,补零
345+
const hour = String(schedule.hour).padStart(2, '0');
346+
const minute = String(schedule.minute).padStart(2, '0');
347+
const timeString = `${hour}:${minute}`;
348+
return dayjs(timeString, TIME_FORMAT_WITHOUT_SECOND);
307349
}
350+
351+
// 如果没有现有配置,返回 null,让表单显示为空
308352
return null;
309353
};
310354

@@ -319,6 +363,9 @@ export default function InspectionList() {
319363

320364
const onChange = (activeKey) => {
321365
setActiveTab(activeKey);
366+
// 先重置表单,清除所有字段值
367+
form.resetFields();
368+
// 然后设置新tab的初始值
322369
const initialValues = getInitialValues(activeKey);
323370
form.setFieldsValue(initialValues);
324371
};
@@ -337,7 +384,7 @@ export default function InspectionList() {
337384
const month = '*';
338385

339386
switch (scheduleDates.mode) {
340-
case 'Daily':
387+
case 'Dayly':
341388
// 每天执行: 0 2 * * *
342389
break;
343390
case 'Weekly':
@@ -376,13 +423,6 @@ export default function InspectionList() {
376423
message.error('无法获取资源信息,请重试');
377424
return;
378425
}
379-
380-
console.log('删除巡检参数:', {
381-
namespace,
382-
name,
383-
scenario: repo?.scenario || tabKey,
384-
});
385-
386426
deleteInspectionPolicy(namespace, name, repo?.scenario);
387427
},
388428
});
@@ -396,7 +436,11 @@ export default function InspectionList() {
396436
);
397437

398438
return (
399-
<Form form={form} initialValues={getInitialValues(tabKey)}>
439+
<Form
440+
form={form}
441+
initialValues={getInitialValues(tabKey)}
442+
key={`form-${tabKey}`} // 添加key确保每个tab的表单是独立的
443+
>
400444
<SchduleSelectFormItem
401445
form={form}
402446
scheduleValue={scheduleValue}
@@ -457,6 +501,7 @@ export default function InspectionList() {
457501
setOpen(false);
458502
form.resetFields();
459503
setActiveTab('basic');
504+
// 不清空 inspectionPolicies,保持数据用于下次打开
460505
}}
461506
open={open}
462507
footer={
@@ -501,12 +546,6 @@ export default function InspectionList() {
501546
status: inspectionPolicies?.status || 'enabled',
502547
scheduleConfig: [scheduleConfig],
503548
};
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);
510549

511550
// 验证必要字段
512551
if (
@@ -517,7 +556,6 @@ export default function InspectionList() {
517556
return;
518557
}
519558

520-
console.log('body', body);
521559
// 调用API
522560
createOrUpdateInspectionPolicy(body);
523561
});

0 commit comments

Comments
 (0)