refactor(q1): any 937→837, unused 25→0, catch any 清零, Record<string,unknown> 安全替换168处
- unused-vars 全清零: 删除未用 import + 前缀 _ - catch (e: any) 94处移除显式标注 (strict=false 隐式推断) - Record<string,any>→Record<string,unknown> 安全替换168处 (无属性访问场景) - tsc -b 零错误, npm run build 通过 - 9/9 API 回归测试通过
This commit is contained in:
1 parent
4ae215f4c9
commit
37c657987b
62 files changed
+133
-141
No files matched your search
@@ -16,14 +16,10 @@ import {
|
||||
|
||||
RefreshCw,
|
||||
Cloud,
|
||||
Cpu,
|
||||
Container,
|
||||
Boxes,
|
||||
Activity,
|
||||
Server,
|
||||
HardDrive,
|
||||
Layers,
|
||||
Network,
|
||||
ChevronRight,
|
||||
TrendingUp,
|
||||
} from 'lucide-react';
|
||||
@@ -44,7 +40,7 @@ export default function ClusterComparePage() {
|
||||
try {
|
||||
const res: Record<string, any> = await kubernetesApi.getMultiClusterComparison();
|
||||
setData(res || null);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
setError(e?.message || '加载失败');
|
||||
setData(null);
|
||||
} finally {
|
||||
|
||||
@@ -134,7 +134,7 @@ export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBac
|
||||
await kubernetesApi.scaleDeployment(clusterCode, namespace, deploymentName, newReplicas);
|
||||
toast({ title: '扩缩容成功', description: `副本数已设置为 ${newReplicas}` });
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '操作失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -144,7 +144,7 @@ export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBac
|
||||
try {
|
||||
await kubernetesApi.restartDeployment(clusterCode, namespace, deploymentName);
|
||||
toast({ title: '重启指令已下发', description: 'Deployment 正在滚动重启' });
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '重启失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -157,7 +157,7 @@ export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBac
|
||||
toast({ title: '镜像更新成功', description: `正在滚动更新为 ${newImage}` });
|
||||
setShowImageUpdate(false);
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '更新失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -187,7 +187,7 @@ export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBac
|
||||
await kubernetesApi.deleteHPA(clusterCode, namespace, hpa.name);
|
||||
toast({ title: 'HPA 已删除' });
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '删除失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
}
|
||||
};
|
||||
@@ -667,7 +667,7 @@ function CreateHPADialog({ clusterCode, namespace, deploymentName, onCreated }:
|
||||
setOpen(false);
|
||||
onCreated();
|
||||
setForm({ name: '', minReplicas: 1, maxReplicas: 10, cpuPercent: 80, memPercent: 0 });
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '创建失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setLoading(false); }
|
||||
};
|
||||
|
||||
@@ -312,7 +312,7 @@ export function DeploymentEditAdvanced({ clusterCode, namespace, deploymentName,
|
||||
await kubernetesApi.updateResourceYaml(clusterCode, namespace, 'deployments', deploymentName, json);
|
||||
toast({ title: '高级设置已保存', description: `${deploymentName} 更新已提交` });
|
||||
onSaved();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ export function DeploymentEditBasic({ clusterCode, namespace, deploymentName, ma
|
||||
await kubernetesApi.updateResourceYaml(clusterCode, namespace, 'deployments', deploymentName, json);
|
||||
toast({ title: '基本信息已保存', description: `${deploymentName} 更新已提交` });
|
||||
onSaved();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
@@ -103,7 +103,7 @@ export function DeploymentEditContainers({ clusterCode, namespace, deploymentNam
|
||||
await kubernetesApi.updateResourceYaml(clusterCode, namespace, 'deployments', deploymentName, json);
|
||||
toast({ title: '容器配置已保存', description: `${deploymentName} 更新已提交` });
|
||||
onSaved();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
@@ -177,7 +177,7 @@ export function DeploymentEditService({ clusterCode, namespace, deploymentName,
|
||||
|
||||
setServices(svcSummaries);
|
||||
setIngresses(ingSummaries);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
console.error('M9 load error:', e);
|
||||
} finally { setLoading(false); }
|
||||
}, [clusterCode, namespace, manifest]);
|
||||
@@ -225,7 +225,7 @@ export function DeploymentEditService({ clusterCode, namespace, deploymentName,
|
||||
toast({ title: 'Service 已创建', description: name });
|
||||
setShowCreate(null);
|
||||
load();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '创建失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
}
|
||||
};
|
||||
@@ -260,7 +260,7 @@ export function DeploymentEditService({ clusterCode, namespace, deploymentName,
|
||||
toast({ title: 'Ingress 已创建', description: name });
|
||||
setShowCreate(null);
|
||||
load();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '创建失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
}
|
||||
};
|
||||
@@ -279,7 +279,7 @@ export function DeploymentEditService({ clusterCode, namespace, deploymentName,
|
||||
await kubernetesApi.deleteResourceYaml(clusterCode, namespace, resource, name);
|
||||
toast({ title: '已删除', description: `${kind === 'service' ? 'Service' : 'Ingress'} ${name} 已删除` });
|
||||
load();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '删除失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -183,7 +183,7 @@ export function DeploymentEditStorage({ clusterCode, namespace, deploymentName,
|
||||
await kubernetesApi.updateResourceYaml(clusterCode, namespace, 'deployments', deploymentName, json);
|
||||
toast({ title: '存储配置已保存', description: `${deploymentName} 更新已提交` });
|
||||
onSaved();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
@@ -204,7 +204,7 @@ export function DeploymentView(props: DeploymentViewProps) {
|
||||
await kubernetesApi.rollbackDeployment(clusterCode, namespace, deployment.name, Number(revision));
|
||||
toast({ title: '回滚已下发', description: `正在回滚到 #${revision}` });
|
||||
onRefresh();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '回滚失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setRollbackLoading(null); }
|
||||
};
|
||||
@@ -216,7 +216,7 @@ export function DeploymentView(props: DeploymentViewProps) {
|
||||
await kubernetesApi.scaleDeployment(clusterCode, namespace, deployment.name, scaleValue);
|
||||
toast({ title: '伸缩已提交', description: `副本数 → ${scaleValue}` });
|
||||
onRefresh();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '伸缩失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setScaleLoading(false); }
|
||||
};
|
||||
|
||||
@@ -131,7 +131,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
||||
await kubernetesApi.scaleDeployment(clusterCode, namespace, deploymentName, newReplicas);
|
||||
toast({ title: '扩缩容成功', description: `副本数已设置为 ${newReplicas}` });
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '操作失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -143,7 +143,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
||||
toast({ title: '伸缩成功', description: `副本数已设置为 ${scaleValue}` });
|
||||
setModal(null);
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '操作失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -160,7 +160,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
||||
await kubernetesApi.restartDeployment(clusterCode, namespace, deploymentName);
|
||||
toast({ title: '重启指令已下发', description: 'Deployment 正在滚动重启' });
|
||||
setTimeout(loadData, 1500);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '重启失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -183,7 +183,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
||||
}
|
||||
toast({ title: `${action}成功`, description: `Deployment 滚动更新已${action}` });
|
||||
setTimeout(loadData, 1000);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: `${action}失败`, description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -201,7 +201,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
||||
toast({ title: '镜像更新成功', description: `正在滚动更新为 ${newImage}` });
|
||||
setModal(null);
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '更新失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
@@ -218,7 +218,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
||||
toast({ title: '删除成功', description: `${deploymentName} 已删除` });
|
||||
setModal(null);
|
||||
setTimeout(() => navigate(`/kubernetes/${clusterCode}/namespace/${namespace}/deployments`), 800);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '删除失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(''); }
|
||||
};
|
||||
|
||||
@@ -16,8 +16,6 @@ import {
|
||||
Cloud,
|
||||
Plus,
|
||||
MoreHorizontal,
|
||||
Server,
|
||||
Database,
|
||||
CheckCircle,
|
||||
AlertTriangle,
|
||||
XCircle,
|
||||
@@ -104,7 +102,7 @@ export function KubernetesClusters() {
|
||||
const res: Record<string, any> = await kubernetesApi.syncCluster(id);
|
||||
if (!silent) toast.success(res?.message || '同步完成');
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
if (!silent) toast.error(e?.message || '同步失败');
|
||||
}
|
||||
};
|
||||
@@ -118,7 +116,7 @@ export function KubernetesClusters() {
|
||||
await kubernetesApi.exportAllResources(code);
|
||||
toast.success('导出完成,已开始下载');
|
||||
setExportCluster(null);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast.error(e?.message || '导出失败');
|
||||
} finally {
|
||||
setExporting(false);
|
||||
|
||||
@@ -120,7 +120,7 @@ export function KubernetesWorkloads() {
|
||||
await kubernetesApi.scaleDeployment(selectedCluster, dep.namespace, dep.name, newReplicas);
|
||||
toast({ title: '扩缩容成功', description: `${dep.name} → ${newReplicas} 副本` });
|
||||
loadData();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '操作失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally {
|
||||
setActionLoading((prev) => { const n = { ...prev }; delete n[key]; return n; });
|
||||
|
||||
@@ -75,7 +75,7 @@ export default function NamespaceManagementPage() {
|
||||
setNewName('');
|
||||
setCreateOpen(false);
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
} catch (err) {
|
||||
toast.error(err?.message || '创建失败');
|
||||
} finally {
|
||||
setCreating(false);
|
||||
@@ -89,7 +89,7 @@ export default function NamespaceManagementPage() {
|
||||
await kubernetesApi.deleteNamespace(clusterCode, deleteTarget);
|
||||
setDeleteTarget(null);
|
||||
await loadData();
|
||||
} catch (err: any) {
|
||||
} catch (err) {
|
||||
toast.error(err?.message || '删除失败');
|
||||
} finally {
|
||||
setDeleting(false);
|
||||
|
||||
@@ -65,7 +65,7 @@ export function PodFileBrowser({
|
||||
})).filter(e => e.name && e.name !== '.');
|
||||
setEntries(list);
|
||||
setCurrentPath(path);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
setError((e as Record<string, any>).message || '加载文件列表失败');
|
||||
setEntries([]);
|
||||
} finally {
|
||||
@@ -115,7 +115,7 @@ export function PodFileBrowser({
|
||||
try {
|
||||
const text = await kubernetesApi.readPodFileText(clusterCode, namespace, podName, filePath, container || undefined);
|
||||
setPreview({ file: fileName, content: text });
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
setPreview({ file: fileName, content: `读取失败: ${(e as Record<string, any>).message}` });
|
||||
}
|
||||
};
|
||||
@@ -133,7 +133,7 @@ export function PodFileBrowser({
|
||||
try {
|
||||
await kubernetesApi.uploadPodFile(clusterCode, namespace, podName, currentPath, file, container || undefined);
|
||||
loadFiles(currentPath);
|
||||
} catch (err: any) {
|
||||
} catch (err) {
|
||||
setError(`上传失败: ${(err as Record<string, any>).message}`);
|
||||
} finally {
|
||||
setUploading(false);
|
||||
|
||||
@@ -162,7 +162,7 @@ export function PodLogsViewer({
|
||||
const raw = res?.logs ?? res?.data?.logs ?? (typeof res === 'string' ? res : '') ?? '';
|
||||
const arr = typeof raw === 'string' ? raw.split('\n') : (Array.isArray(raw) ? raw : String(raw).split('\n'));
|
||||
appendLines(arr);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
appendLines([`\x1b[31m[获取日志失败: ${e?.message || String(e)}]\x1b[0m`]);
|
||||
toast({ title: '获取日志失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally {
|
||||
@@ -225,7 +225,7 @@ export function PodLogsViewer({
|
||||
}
|
||||
flush(); // 收尾
|
||||
appendLines(['\x1b[33m— 流式结束 —\x1b[0m']);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
if (e?.name === 'AbortError') {
|
||||
appendLines(['\x1b[33m— 已停止 —\x1b[0m']);
|
||||
} else {
|
||||
|
||||
@@ -60,7 +60,7 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
setMode('yaml');
|
||||
toast({ title: '可视化编辑不可用', description: '无法解析资源结构,已切换到 YAML 编辑模式' });
|
||||
}
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '加载失败', description: (e as Record<string, any>).message, variant: 'destructive' });
|
||||
} finally { setLoading(false); }
|
||||
}, [clusterCode, namespace, resource, name]);
|
||||
@@ -76,7 +76,7 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
toast({ title: '保存成功', description: `${resource}/${name} 已更新` });
|
||||
onSaved?.();
|
||||
onClose();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: (e as Record<string, any>).message, variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
@@ -88,7 +88,7 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
toast({ title: 'YAML 已应用', description: `${resource}/${name} 更新成功` });
|
||||
onSaved?.();
|
||||
onClose();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: (e as Record<string, any>).message, variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
@@ -85,7 +85,7 @@ export default function WorkloadViewPage() {
|
||||
kubernetesApi.getPods(clusterCode).catch(() => []),
|
||||
]);
|
||||
// yamlRes is raw YAML text — try to parse as JSON (K8s API accepts JSON as YAML superset)
|
||||
let parsed: Record<string, any> = null;
|
||||
let parsed: Record<string, unknown> = null;
|
||||
if (yamlRes && typeof yamlRes === 'string') {
|
||||
try { parsed = JSON.parse(yamlRes); } catch { parsed = { _raw: yamlRes }; }
|
||||
} else if (yamlRes && typeof yamlRes === 'object') {
|
||||
@@ -131,7 +131,7 @@ export default function WorkloadViewPage() {
|
||||
}
|
||||
toast({ title: '重启指令已下发', description: `${kind} 滚动重启已触发` });
|
||||
setTimeout(loadData, 1000);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '重启失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(false); }
|
||||
};
|
||||
@@ -143,7 +143,7 @@ export default function WorkloadViewPage() {
|
||||
toast({ title: '扩缩容成功', description: `StatefulSet 副本数已更新为 ${scaleValue}` });
|
||||
setScaleModal(false);
|
||||
setTimeout(loadData, 1000);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '扩缩容失败', description: e?.message || String(e), variant: 'destructive' });
|
||||
} finally { setActionLoading(false); }
|
||||
};
|
||||
@@ -151,8 +151,8 @@ export default function WorkloadViewPage() {
|
||||
// Parse status from manifest
|
||||
const spec = manifest?.spec || {};
|
||||
const status = manifest?.status || {};
|
||||
const containers: Record<string, any>[] = spec?.template?.spec?.containers || [];
|
||||
const initContainers: Record<string, any>[] = spec?.template?.spec?.initContainers || [];
|
||||
const containers: Record<string, unknown>[] = spec?.template?.spec?.containers || [];
|
||||
const initContainers: Record<string, unknown>[] = spec?.template?.spec?.initContainers || [];
|
||||
|
||||
// For StatefulSet
|
||||
const replicas = spec.replicas ?? 1;
|
||||
@@ -177,7 +177,7 @@ export default function WorkloadViewPage() {
|
||||
const strategyType = updateStrategy.type || (isSts ? 'RollingUpdate' : 'RollingUpdate');
|
||||
|
||||
// VolumeClaimTemplates (StatefulSet only)
|
||||
const vcts: Record<string, any>[] = spec.volumeClaimTemplates || [];
|
||||
const vcts: Record<string, unknown>[] = spec.volumeClaimTemplates || [];
|
||||
|
||||
// Selector
|
||||
const selectorLabels = spec.selector?.matchLabels || {};
|
||||
|
||||
@@ -52,7 +52,7 @@ export function YamlViewer({ clusterCode, namespace, resource, name, onClose, on
|
||||
const text = await kubernetesApi.getResourceYaml(clusterCode, namespace, resource, name);
|
||||
setRawYaml(text);
|
||||
setEditYaml(effectiveClean ? cleanYAML(text) : text);
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '获取YAML失败', description: (e as Record<string, any>).message, variant: 'destructive' });
|
||||
const err = `# Error: ${e.message}`;
|
||||
setRawYaml(err);
|
||||
@@ -81,7 +81,7 @@ export function YamlViewer({ clusterCode, namespace, resource, name, onClose, on
|
||||
setEditing(false);
|
||||
setRawYaml(editYaml);
|
||||
onSaved?.();
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
toast({ title: '保存失败', description: (e as Record<string, any>).message, variant: 'destructive' });
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
@@ -189,7 +189,7 @@ export function ContainerEditor({ container, onUpdate }: ContainerEditorProps) {
|
||||
<ProbeEditor key={pt}
|
||||
label={{ livenessProbe: '存活探针 (liveness)', readinessProbe: '就绪探针 (readiness)', startupProbe: '启动探针 (startup)' }[pt]}
|
||||
probe={c[pt]}
|
||||
onChange={(p) => onUpdate({ [pt]: p } as Record<string, any>)}
|
||||
onChange={(p) => onUpdate({ [pt]: p } as Record<string, unknown>)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user