refactor: 标准化项目结构 frontend/ + backend/ + SQLite + run.sh

- 目录重构: app/ -> frontend/,与 backend/ 并列
- 数据库: 默认 SQLite(零配置),修复 DSN() bug
- run.sh: 一键启动前后端,支持 start/stop/restart/status
- Makefile: install/dev/build/lint/clean 快捷命令
- vite.config.ts: 配置 dev server 端口 5173 + API 代理到 8080
- config.yaml: SQLite 默认配置,开箱即用
- docs/: 完整开发文档(项目结构/API/数据库/规范/部署)
- 修复: GORM foreign key 关联声明
- 修复: go get gorm.io/driver/sqlite 依赖
This commit is contained in:
attacker committed 2026-06-13 23:34:23 +08:00
1 parent 7d6674bddd
commit 97c4207ff8
132 files changed
+1572 -34

No files matched your search

@@ -0,0 +1,219 @@
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import {
Plus,
Search,
Edit2,
Trash2,
CloudCog,
Server,
CheckCircle2,
XCircle,
ExternalLink
} from 'lucide-react';
import { platforms } from '@/mocks/data';
interface Platform {
id: string;
name: string;
code: string;
type: 'public' | 'private' | 'hybrid';
status: 'active' | 'inactive';
accountCount: number;
regionCount: number;
serverCount: number;
website: string;
description: string;
}
const typeLabels: Record<string, string> = {
public: '公有云',
private: '私有云',
hybrid: '混合云',
};
const typeColors: Record<string, string> = {
public: 'bg-blue-500/20 text-blue-400',
private: 'bg-purple-500/20 text-purple-400',
hybrid: 'bg-cyan-500/20 text-cyan-400',
};
export function PlatformManager() {
const [searchQuery, setSearchQuery] = useState('');
const [selectedType, setSelectedType] = useState<string>('all');
const filteredPlatforms = platforms.filter(platform => {
const matchesSearch = platform.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
platform.code.toLowerCase().includes(searchQuery.toLowerCase());
const matchesType = selectedType === 'all' || platform.type === selectedType;
return matchesSearch && matchesType;
});
const stats = {
total: platforms.length,
public: platforms.filter(p => p.type === 'public').length,
private: platforms.filter(p => p.type === 'private').length,
totalServers: platforms.reduce((sum, p) => sum + p.serverCount, 0),
};
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-slate-100">云平台管理</h1>
<p className="text-slate-400 mt-1">管理多云平台和云服务提供商</p>
</div>
<Button className="bg-blue-600 hover:bg-blue-700">
<Plus className="h-4 w-4 mr-2" />
添加平台
</Button>
</div>
{/* Stats */}
<div className="grid grid-cols-4 gap-4">
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">平台总数</p>
<p className="text-2xl font-bold text-slate-100 mt-1">{stats.total}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center">
<CloudCog className="h-5 w-5 text-blue-400" />
</div>
</div>
</CardContent>
</Card>
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">公有云</p>
<p className="text-2xl font-bold text-blue-400 mt-1">{stats.public}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center">
<CloudCog className="h-5 w-5 text-blue-400" />
</div>
</div>
</CardContent>
</Card>
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">私有云</p>
<p className="text-2xl font-bold text-purple-400 mt-1">{stats.private}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-purple-500/20 flex items-center justify-center">
<CloudCog className="h-5 w-5 text-purple-400" />
</div>
</div>
</CardContent>
</Card>
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">服务器总数</p>
<p className="text-2xl font-bold text-green-400 mt-1">{stats.totalServers}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-green-500/20 flex items-center justify-center">
<Server className="h-5 w-5 text-green-400" />
</div>
</div>
</CardContent>
</Card>
</div>
{/* Filters */}
<div className="flex items-center gap-4">
<div className="relative flex-1 max-w-md">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400" />
<Input
placeholder="搜索平台名称或代码..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10 bg-slate-800 border-slate-700 text-slate-100"
/>
</div>
<select
value={selectedType}
onChange={(e) => setSelectedType(e.target.value)}
className="px-3 py-2 bg-slate-800 border border-slate-700 rounded-md text-slate-100 text-sm"
>
<option value="all">全部类型</option>
<option value="public">公有云</option>
<option value="private">私有云</option>
<option value="hybrid">混合云</option>
</select>
</div>
{/* Platform List */}
<div className="grid grid-cols-2 gap-4">
{filteredPlatforms.map((platform) => (
<Card key={platform.id} className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-start justify-between">
<div className="flex items-start gap-3">
<div className="w-12 h-12 rounded-lg bg-gradient-to-br from-blue-500 to-cyan-500 flex items-center justify-center text-white font-bold text-lg">
{platform.name.slice(0, 2)}
</div>
<div>
<div className="flex items-center gap-2">
<h3 className="font-medium text-slate-100">{platform.name}</h3>
<Badge className={typeColors[platform.type]}>
{typeLabels[platform.type]}
</Badge>
{platform.status === 'active' ? (
<Badge className="bg-green-500/20 text-green-400 border-0">
<CheckCircle2 className="h-3 w-3 mr-1" />
启用
</Badge>
) : (
<Badge className="bg-slate-500/20 text-slate-400 border-0">
<XCircle className="h-3 w-3 mr-1" />
停用
</Badge>
)}
</div>
<p className="text-sm text-slate-400 mt-0.5">{platform.code}</p>
<p className="text-xs text-slate-500 mt-1">{platform.description}</p>
</div>
</div>
<div className="flex items-center gap-1">
<Button variant="ghost" size="icon" className="h-8 w-8 text-slate-400 hover:text-blue-400">
<ExternalLink className="h-4 w-4" />
</Button>
<Button variant="ghost" size="icon" className="h-8 w-8 text-slate-400 hover:text-blue-400">
<Edit2 className="h-4 w-4" />
</Button>
<Button variant="ghost" size="icon" className="h-8 w-8 text-slate-400 hover:text-red-400">
<Trash2 className="h-4 w-4" />
</Button>
</div>
</div>
<div className="grid grid-cols-3 gap-4 mt-4 pt-4 border-t border-slate-700">
<div>
<p className="text-xs text-slate-400">账号数</p>
<p className="text-lg font-medium text-slate-100">{platform.accountCount}</p>
</div>
<div>
<p className="text-xs text-slate-400">区域数</p>
<p className="text-lg font-medium text-slate-100">{platform.regionCount}</p>
</div>
<div>
<p className="text-xs text-slate-400">服务器数</p>
<p className="text-lg font-medium text-slate-100">{platform.serverCount}</p>
</div>
</div>
</CardContent>
</Card>
))}
</div>
</div>
);
}