feat(q1): 前端类型安全治理完成 — any 83→40, P0 全部 done
- types/monitor.ts: 新增 6 个运行时记录类型(AlertEventRecord/AlertRuleRecord/ AgentHostRecord/CronJobRecord/CertExpiryRecord/ApprovalWorkflowStepRecord) - types/common.ts: 新增 OptionItem 通用下拉类型 - 组件级 any 清理 43 处: - AlertEventsTab/AlertRulesTab/AlertChannelDialog/alertShared (19处) - AuditOperationsTab normalizeLog + 筛选器 (8处) - CronJobManager 任务列表/编辑/操作 (6处) - AgentMonitor 主机列表/命令执行 (5处) - DashboardRecent 5 张卡片组件 (5处) - AlertManager 状态类型对齐 (联动修复) - Dashboard.tsx 调用端类型对齐 (联动修复) - AlertChannel 接口新增 test_status 字段 - ESLint any: 83→40 (<50 目标达成) - tsc -b / tsc --noEmit: 零错误 - npm run build: ✓ built in 17.11s - 9/9 核心 API 回归通过
This commit is contained in:
1 parent
0535f30c87
commit
bb2b91ebe0
15 files changed
+259
-93
No files matched your search
@@ -5,6 +5,7 @@ import { agentApi } from '@/api';
|
||||
import { AgentWizard } from './AgentWizard';
|
||||
import { HostDetailDialog } from './HostDetailDialog';
|
||||
import { isOnline, timeAgo, asList } from './agentUtils';
|
||||
import type { AgentHostRecord } from '@/types';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -40,10 +41,10 @@ import {
|
||||
// ============ 组件 ============
|
||||
|
||||
export function AgentMonitor() {
|
||||
const [hosts, setHosts] = useState<any[]>([]);
|
||||
const [hosts, setHosts] = useState<AgentHostRecord[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [selectedHost, setSelectedHost] = useState<any>(null);
|
||||
const [selectedHost, setSelectedHost] = useState<AgentHostRecord | null>(null);
|
||||
const [wizardOpen, setWizardOpen] = useState(false);
|
||||
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
@@ -53,13 +54,13 @@ export function AgentMonitor() {
|
||||
const [cmdCommand, setCmdCommand] = useState('');
|
||||
const [cmdTimeout, setCmdTimeout] = useState(30);
|
||||
const [cmdSubmitting, setCmdSubmitting] = useState(false);
|
||||
const [cmdResult, setCmdResult] = useState<any>(null);
|
||||
const [cmdResult, setCmdResult] = useState<{ status: string; result?: string; output?: string; error?: string } | null>(null);
|
||||
|
||||
const loadLatest = useCallback(async (silent = false) => {
|
||||
if (!silent) setRefreshing(true);
|
||||
try {
|
||||
const data = await agentApi.getLatest();
|
||||
const list = asList(data);
|
||||
const list = asList(data) as AgentHostRecord[];
|
||||
setHosts(list);
|
||||
// 同步选中主机的最新数据
|
||||
if (selectedHost) {
|
||||
@@ -102,15 +103,16 @@ export function AgentMonitor() {
|
||||
setCmdSubmitting(true);
|
||||
setCmdResult(null);
|
||||
try {
|
||||
const res: Record<string, any> = await agentApi.execCommand({
|
||||
const res = await agentApi.execCommand({
|
||||
hostname: cmdHost,
|
||||
command: cmdCommand.trim(),
|
||||
timeout: Number(cmdTimeout) || 30,
|
||||
});
|
||||
}) as Record<string, unknown>;
|
||||
const resData = (res?.data ?? {}) as Record<string, unknown>;
|
||||
setCmdResult({
|
||||
status: res?.code === 200 ? 'completed' : 'failed',
|
||||
result: res?.data?.output || res?.message || '无输出',
|
||||
error: res?.data?.error,
|
||||
result: (resData.output as string) || (res?.message as string) || '无输出',
|
||||
error: resData.error as string | undefined,
|
||||
});
|
||||
} catch (err) {
|
||||
setCmdResult({ status: 'failed', result: err?.message || '执行失败' });
|
||||
@@ -209,7 +211,7 @@ export function AgentMonitor() {
|
||||
const cpu = Number(host.cpu_percent ?? host.cpu ?? 0);
|
||||
const mem = Number(host.mem_percent ?? host.mem ?? 0);
|
||||
const disk = Number(host.disk_percent ?? host.disk ?? 0);
|
||||
const ports: Record<string, any>[] = Array.isArray(host.ports) ? host.ports : [];
|
||||
const ports: Record<string, unknown>[] = Array.isArray(host.ports) ? (host.ports as Record<string, unknown>[]) : [];
|
||||
return (
|
||||
<Card
|
||||
key={host.hostname}
|
||||
|
||||
Reference in new issue
Block a user