From 745dde358e62200bba54fc232707b103ed3c85ce Mon Sep 17 00:00:00 2001 From: attacker Date: Mon, 15 Jun 2026 12:07:46 +0800 Subject: [PATCH] refactor: ScriptManager split into 5 files (730 to 546 lines) - script-helpers.tsx (97 lines): Script/ExecutionRecord types, mapScript, scriptTypes, getTypeBadge, genCode, getStatusBadge, formatDate - ScriptFormDialog.tsx (113 lines): new/edit script dialog - ScriptDetailDialog.tsx (49 lines): view script content dialog - ScriptLogsDialog.tsx (39 lines): execution logs dialog - ScriptManager.tsx (546 lines): main component, imports sub-components Verified: tsc --noEmit zero errors, npm run build passes, browser tested all 3 dialogs + tabs + stats cards, console zero errors --- .../automation/ScriptDetailDialog.tsx | 49 ++++ .../automation/ScriptFormDialog.tsx | 113 ++++++++ .../automation/ScriptLogsDialog.tsx | 39 +++ .../components/automation/ScriptManager.tsx | 250 +++--------------- .../components/automation/script-helpers.tsx | 97 +++++++ 5 files changed, 331 insertions(+), 217 deletions(-) create mode 100644 frontend/src/components/automation/ScriptDetailDialog.tsx create mode 100644 frontend/src/components/automation/ScriptFormDialog.tsx create mode 100644 frontend/src/components/automation/ScriptLogsDialog.tsx create mode 100644 frontend/src/components/automation/script-helpers.tsx diff --git a/frontend/src/components/automation/ScriptDetailDialog.tsx b/frontend/src/components/automation/ScriptDetailDialog.tsx new file mode 100644 index 0000000..820f082 --- /dev/null +++ b/frontend/src/components/automation/ScriptDetailDialog.tsx @@ -0,0 +1,49 @@ +// Script 查看内容弹窗 // Logan.Li +import { FileCode, Edit } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { + Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, +} from '@/components/ui/dialog'; +import { ScrollArea } from '@/components/ui/scroll-area'; +import type { Script } from './script-helpers'; +import { getTypeBadge } from './script-helpers'; + +interface Props { + open: boolean; + onOpenChange: (open: boolean) => void; + script: Script | null; + onEdit: (sc: Script) => void; +} + +const ScriptDetailDialog: React.FC = ({ open, onOpenChange, script, onEdit }) => { + return ( + + + + + + {script?.name} + {script && getTypeBadge(script.type)} + + {script?.description} + + +
+            {script?.content || '(空)'}
+          
+
+ + + {script && ( + + )} + +
+
+ ); +}; + +export default ScriptDetailDialog; diff --git a/frontend/src/components/automation/ScriptFormDialog.tsx b/frontend/src/components/automation/ScriptFormDialog.tsx new file mode 100644 index 0000000..3ab1bb2 --- /dev/null +++ b/frontend/src/components/automation/ScriptFormDialog.tsx @@ -0,0 +1,113 @@ +// Script 新建/编辑弹窗 // Logan.Li +import { CheckCircle } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { + Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, +} from '@/components/ui/dialog'; +import { + Select, SelectContent, SelectItem, SelectTrigger, SelectValue, +} from '@/components/ui/select'; +import { Label } from '@/components/ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { scriptTypes } from './script-helpers'; + +export interface ScriptFormData { + name: string; + description: string; + content: string; + type: string; + timeout: number; +} + +interface Props { + open: boolean; + onOpenChange: (open: boolean) => void; + editingId: number | null; + editingCode: string; + formData: ScriptFormData; + setFormData: React.Dispatch>; + onTypeChange: (t: string) => void; + onSave: () => void; +} + +const ScriptFormDialog: React.FC = ({ + open, onOpenChange, editingId, editingCode, formData, setFormData, onTypeChange, onSave, +}) => { + return ( + + + + {editingId !== null ? '编辑脚本' : '新建脚本'} + 编写运维脚本,支持 Shell / Python / PowerShell + +
+
+
+ + setFormData({ ...formData, name: e.target.value })} + placeholder="如:系统巡检脚本" + /> +
+
+ + +
+
+
+ + setFormData({ ...formData, description: e.target.value })} + placeholder="脚本用途说明" + /> +
+
+
+ + setFormData({ ...formData, timeout: Number(e.target.value) })} + placeholder="300" + /> +
+ {editingId !== null && ( +
+ + +
+ )} +
+
+ +