feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮
This commit is contained in:
1 parent
d0b94d39c0
commit
2354959811
14 files changed
+1355
-575
No files matched your search
@@ -1,166 +1,180 @@
|
||||
// 服务器表格行 — 纯展示子组件(接收 props,不直接调 API) // Logan.Li
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { TableCell, TableRow } from '@/components/ui/table';
|
||||
import { Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2, Download } from 'lucide-react';
|
||||
import { getStatusBadge, getTags, getUsageColor } from './serverHelpers';
|
||||
|
||||
interface ServerTableRowProps {
|
||||
server: any;
|
||||
selected: boolean;
|
||||
onToggleSelect: (id: string) => void;
|
||||
onOpenTerminal: (server: any) => void;
|
||||
onOpenEdit: (server: any) => void;
|
||||
onDelete: (id: string) => void;
|
||||
}
|
||||
|
||||
export function ServerTableRow({
|
||||
server,
|
||||
selected,
|
||||
onToggleSelect,
|
||||
onOpenTerminal,
|
||||
onOpenEdit,
|
||||
onDelete,
|
||||
}: ServerTableRowProps) {
|
||||
const cpuUsage = Number(server.cpu_usage || 0);
|
||||
const memoryUsage = Number(server.memory_usage || 0);
|
||||
const tags = getTags(server);
|
||||
const memGB = server.memory ? Math.round(server.memory / 1024) : 0;
|
||||
|
||||
return (
|
||||
<TableRow className="border-[var(--dg-border)] hover:bg-[var(--dg-bg-tertiary)]/50">
|
||||
<TableCell>
|
||||
<Checkbox
|
||||
checked={selected}
|
||||
onCheckedChange={() => onToggleSelect(server.id)}
|
||||
className="border-[var(--dg-border)]"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<ServerIcon className="h-4 w-4 text-[var(--dg-text-muted)]" />
|
||||
<div>
|
||||
<p className="font-medium text-[var(--dg-text-primary)]">{server.hostname}</p>
|
||||
<p className="text-xs text-[var(--dg-text-muted)]">{server.os}</p>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<code className="text-sm text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)] px-2 py-0.5 rounded">
|
||||
{server.ip}
|
||||
</code>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{server.public_ip ? (
|
||||
<code className="text-sm text-[var(--dg-cyan)] bg-[var(--dg-cyan)]/10 px-2 py-0.5 rounded">
|
||||
{server.public_ip}
|
||||
</code>
|
||||
) : (
|
||||
<span className="text-sm text-[var(--dg-text-muted)]">-</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{getStatusBadge(server.status)}</TableCell>
|
||||
<TableCell>
|
||||
<div className="text-sm text-[var(--dg-text-secondary)]">
|
||||
<span className="text-[var(--dg-text-muted)]">{server.cpu}核</span>
|
||||
<span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span>
|
||||
<span className="text-[var(--dg-text-muted)]">{memGB}GB</span>
|
||||
<span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span>
|
||||
<span className="text-[var(--dg-text-muted)]">{server.disk}GB</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-[var(--dg-text-muted)] w-8">CPU</span>
|
||||
<div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden">
|
||||
<div
|
||||
className={cn('h-full rounded-full', getUsageColor(cpuUsage))}
|
||||
style={{ width: `${cpuUsage}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs text-[var(--dg-text-secondary)]">{cpuUsage.toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-[var(--dg-text-muted)] w-8">内存</span>
|
||||
<div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden">
|
||||
<div
|
||||
className={cn('h-full rounded-full', getUsageColor(memoryUsage))}
|
||||
style={{ width: `${memoryUsage}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs text-[var(--dg-text-secondary)]">{memoryUsage.toFixed(1)}%</span>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{tags.slice(0, 3).map((tag) => (
|
||||
<Badge
|
||||
key={tag}
|
||||
variant="outline"
|
||||
className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)]/50"
|
||||
>
|
||||
{tag}
|
||||
</Badge>
|
||||
))}
|
||||
{tags.length > 3 && (
|
||||
<Badge variant="outline" className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)]">
|
||||
+{tags.length - 3}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-blue)]" onClick={() => onOpenTerminal(server)}>
|
||||
<Terminal className="h-4 w-4" />
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)]">
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)]">
|
||||
<DropdownMenuLabel className="text-[var(--dg-text-secondary)]">操作</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator className="bg-[var(--dg-border)]" />
|
||||
<DropdownMenuItem
|
||||
className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
|
||||
onClick={() => onOpenEdit(server)}
|
||||
>
|
||||
<Edit className="h-4 w-4 mr-2" />
|
||||
编辑
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
|
||||
onClick={() => onOpenTerminal(server)}
|
||||
>
|
||||
<Terminal className="h-4 w-4 mr-2" />
|
||||
终端
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="bg-[var(--dg-border)]" />
|
||||
<DropdownMenuItem
|
||||
className="text-red-400 focus:bg-[var(--dg-bg-hover)] focus:text-red-400 cursor-pointer"
|
||||
onClick={() => onDelete(server.id)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
删除
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
1|// 服务器表格行 — 纯展示子组件(接收 props,不直接调 API) // Logan.Li
|
||||
2|import { cn } from '@/lib/utils';
|
||||
3|import { Badge } from '@/components/ui/badge';
|
||||
4|import { Button } from '@/components/ui/button';
|
||||
5|import { Checkbox } from '@/components/ui/checkbox';
|
||||
6|import {
|
||||
7| DropdownMenu,
|
||||
8| DropdownMenuContent,
|
||||
9| DropdownMenuItem,
|
||||
10| DropdownMenuLabel,
|
||||
11| DropdownMenuSeparator,
|
||||
12| DropdownMenuTrigger,
|
||||
13|} from '@/components/ui/dropdown-menu';
|
||||
14|import { TableCell, TableRow } from '@/components/ui/table';
|
||||
15|<<<<<<< HEAD
|
||||
16|import { Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2, Download } from 'lucide-react';
|
||||
17|=======
|
||||
18|import { Cpu, Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2 } from 'lucide-react';
|
||||
19|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
|
||||
20|import { getStatusBadge, getTags, getUsageColor } from './serverHelpers';
|
||||
21|
|
||||
22|interface ServerTableRowProps {
|
||||
23| server: any;
|
||||
24| selected: boolean;
|
||||
25| onToggleSelect: (id: string) => void;
|
||||
26| onOpenTerminal: (server: any) => void;
|
||||
27| onOpenEdit: (server: any) => void;
|
||||
28| onDelete: (id: string) => void;
|
||||
29| onInstallAgent: (server: any) => void;
|
||||
30|}
|
||||
31|
|
||||
32|export function ServerTableRow({
|
||||
33| server,
|
||||
34| selected,
|
||||
35| onToggleSelect,
|
||||
36| onOpenTerminal,
|
||||
37| onOpenEdit,
|
||||
38| onDelete,
|
||||
39| onInstallAgent,
|
||||
40|}: ServerTableRowProps) {
|
||||
41| const cpuUsage = Number(server.cpu_usage || 0);
|
||||
42| const memoryUsage = Number(server.memory_usage || 0);
|
||||
43| const tags = getTags(server);
|
||||
44| const memGB = server.memory ? Math.round(server.memory / 1024) : 0;
|
||||
45|
|
||||
46| return (
|
||||
47| <TableRow className="border-[var(--dg-border)] hover:bg-[var(--dg-bg-tertiary)]/50">
|
||||
48| <TableCell>
|
||||
49| <Checkbox
|
||||
50| checked={selected}
|
||||
51| onCheckedChange={() => onToggleSelect(server.id)}
|
||||
52| className="border-[var(--dg-border)]"
|
||||
53| />
|
||||
54| </TableCell>
|
||||
55| <TableCell>
|
||||
56| <div className="flex items-center gap-2">
|
||||
57| <ServerIcon className="h-4 w-4 text-[var(--dg-text-muted)]" />
|
||||
58| <div>
|
||||
59| <p className="font-medium text-[var(--dg-text-primary)]">{server.hostname}</p>
|
||||
60| <p className="text-xs text-[var(--dg-text-muted)]">{server.os}</p>
|
||||
61| </div>
|
||||
62| </div>
|
||||
63| </TableCell>
|
||||
64| <TableCell>
|
||||
65| <code className="text-sm text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)] px-2 py-0.5 rounded">
|
||||
66| {server.ip}
|
||||
67| </code>
|
||||
68| </TableCell>
|
||||
69| <TableCell>
|
||||
70| {server.public_ip ? (
|
||||
71| <code className="text-sm text-[var(--dg-cyan)] bg-[var(--dg-cyan)]/10 px-2 py-0.5 rounded">
|
||||
72| {server.public_ip}
|
||||
73| </code>
|
||||
74| ) : (
|
||||
75| <span className="text-sm text-[var(--dg-text-muted)]">-</span>
|
||||
76| )}
|
||||
77| </TableCell>
|
||||
78| <TableCell>{getStatusBadge(server.status)}</TableCell>
|
||||
79| <TableCell>
|
||||
80| <div className="text-sm text-[var(--dg-text-secondary)]">
|
||||
81| <span className="text-[var(--dg-text-muted)]">{server.cpu}核</span>
|
||||
82| <span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span>
|
||||
83| <span className="text-[var(--dg-text-muted)]">{memGB}GB</span>
|
||||
84| <span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span>
|
||||
85| <span className="text-[var(--dg-text-muted)]">{server.disk}GB</span>
|
||||
86| </div>
|
||||
87| </TableCell>
|
||||
88| <TableCell>
|
||||
89| <div className="space-y-1">
|
||||
90| <div className="flex items-center gap-2">
|
||||
91| <span className="text-xs text-[var(--dg-text-muted)] w-8">CPU</span>
|
||||
92| <div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden">
|
||||
93| <div
|
||||
94| className={cn('h-full rounded-full', getUsageColor(cpuUsage))}
|
||||
95| style={{ width: `${cpuUsage}%` }}
|
||||
96| />
|
||||
97| </div>
|
||||
98| <span className="text-xs text-[var(--dg-text-secondary)]">{cpuUsage.toFixed(1)}%</span>
|
||||
99| </div>
|
||||
100| <div className="flex items-center gap-2">
|
||||
101| <span className="text-xs text-[var(--dg-text-muted)] w-8">内存</span>
|
||||
102| <div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden">
|
||||
103| <div
|
||||
104| className={cn('h-full rounded-full', getUsageColor(memoryUsage))}
|
||||
105| style={{ width: `${memoryUsage}%` }}
|
||||
106| />
|
||||
107| </div>
|
||||
108| <span className="text-xs text-[var(--dg-text-secondary)]">{memoryUsage.toFixed(1)}%</span>
|
||||
109| </div>
|
||||
110| </div>
|
||||
111| </TableCell>
|
||||
112| <TableCell>
|
||||
113| <div className="flex flex-wrap gap-1">
|
||||
114| {tags.slice(0, 3).map((tag) => (
|
||||
115| <Badge
|
||||
116| key={tag}
|
||||
117| variant="outline"
|
||||
118| className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)]/50"
|
||||
119| >
|
||||
120| {tag}
|
||||
121| </Badge>
|
||||
122| ))}
|
||||
123| {tags.length > 3 && (
|
||||
124| <Badge variant="outline" className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)]">
|
||||
125| +{tags.length - 3}
|
||||
126| </Badge>
|
||||
127| )}
|
||||
128| </div>
|
||||
129| </TableCell>
|
||||
130| <TableCell className="text-right">
|
||||
131| <div className="flex items-center justify-end gap-1">
|
||||
132| <Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-blue)]" onClick={() => onOpenTerminal(server)}>
|
||||
133| <Terminal className="h-4 w-4" />
|
||||
134| </Button>
|
||||
135| <DropdownMenu>
|
||||
136| <DropdownMenuTrigger asChild>
|
||||
137| <Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)]">
|
||||
138| <MoreHorizontal className="h-4 w-4" />
|
||||
139| </Button>
|
||||
140| </DropdownMenuTrigger>
|
||||
141| <DropdownMenuContent align="end" className="w-48 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)]">
|
||||
142| <DropdownMenuLabel className="text-[var(--dg-text-secondary)]">操作</DropdownMenuLabel>
|
||||
143| <DropdownMenuSeparator className="bg-[var(--dg-border)]" />
|
||||
144| <DropdownMenuItem
|
||||
145| className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
|
||||
146| onClick={() => onOpenEdit(server)}
|
||||
147| >
|
||||
148| <Edit className="h-4 w-4 mr-2" />
|
||||
149| 编辑
|
||||
150| </DropdownMenuItem>
|
||||
151| <DropdownMenuItem
|
||||
152| className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
|
||||
153| onClick={() => onOpenTerminal(server)}
|
||||
154| >
|
||||
155| <Terminal className="h-4 w-4 mr-2" />
|
||||
156| 终端
|
||||
157| </DropdownMenuItem>
|
||||
158| <DropdownMenuItem
|
||||
159| className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
|
||||
160| onClick={() => onInstallAgent(server)}
|
||||
161| >
|
||||
162| <Cpu className="h-4 w-4 mr-2" />
|
||||
163| 安装Agent
|
||||
164| </DropdownMenuItem>
|
||||
165| <DropdownMenuSeparator className="bg-[var(--dg-border)]" />
|
||||
166| <DropdownMenuItem
|
||||
167| className="text-red-400 focus:bg-[var(--dg-bg-hover)] focus:text-red-400 cursor-pointer"
|
||||
168| onClick={() => onDelete(server.id)}
|
||||
169| >
|
||||
170| <Trash2 className="h-4 w-4 mr-2" />
|
||||
171| 删除
|
||||
172| </DropdownMenuItem>
|
||||
173| </DropdownMenuContent>
|
||||
174| </DropdownMenu>
|
||||
175| </div>
|
||||
176| </TableCell>
|
||||
177| </TableRow>
|
||||
178| );
|
||||
179|}
|
||||
180|
|
||||
Reference in new issue
Block a user