2025-10-22 15:12:59 +08:00
|
|
|
|
import { useState, useEffect, useRef } from "react";
|
2025-09-20 00:09:00 +08:00
|
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
|
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
|
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
|
|
|
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
2025-10-22 15:12:59 +08:00
|
|
|
|
import { Progress } from "@/components/ui/progress";
|
2025-10-22 22:18:19 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Plus,
|
|
|
|
|
|
Search,
|
|
|
|
|
|
GitBranch,
|
|
|
|
|
|
Calendar,
|
|
|
|
|
|
Users,
|
|
|
|
|
|
Settings,
|
2025-09-20 00:09:00 +08:00
|
|
|
|
ExternalLink,
|
|
|
|
|
|
Code,
|
|
|
|
|
|
Shield,
|
|
|
|
|
|
Activity,
|
2025-10-22 15:12:59 +08:00
|
|
|
|
Upload,
|
|
|
|
|
|
FileText,
|
|
|
|
|
|
AlertCircle
|
2025-09-20 00:09:00 +08:00
|
|
|
|
} from "lucide-react";
|
2025-10-22 15:12:59 +08:00
|
|
|
|
import { api } from "@/shared/config/database";
|
|
|
|
|
|
import { scanZipFile, validateZipFile } from "@/features/projects/services";
|
|
|
|
|
|
import type { Project, CreateProjectForm } from "@/shared/types";
|
2025-09-20 00:09:00 +08:00
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
|
import { toast } from "sonner";
|
2025-10-22 22:18:19 +08:00
|
|
|
|
import CreateTaskDialog from "@/components/audit/CreateTaskDialog";
|
2025-10-24 20:23:22 +08:00
|
|
|
|
import TerminalProgressDialog from "@/components/audit/TerminalProgressDialog";
|
2025-09-20 00:09:00 +08:00
|
|
|
|
|
|
|
|
|
|
export default function Projects() {
|
|
|
|
|
|
const [projects, setProjects] = useState<Project[]>([]);
|
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
const [searchTerm, setSearchTerm] = useState("");
|
|
|
|
|
|
const [showCreateDialog, setShowCreateDialog] = useState(false);
|
2025-10-22 22:18:19 +08:00
|
|
|
|
const [showCreateTaskDialog, setShowCreateTaskDialog] = useState(false);
|
|
|
|
|
|
const [selectedProjectForTask, setSelectedProjectForTask] = useState<string>("");
|
2025-10-22 15:12:59 +08:00
|
|
|
|
const [uploadProgress, setUploadProgress] = useState(0);
|
|
|
|
|
|
const [uploading, setUploading] = useState(false);
|
|
|
|
|
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
2025-10-24 20:23:22 +08:00
|
|
|
|
const [showTerminalDialog, setShowTerminalDialog] = useState(false);
|
|
|
|
|
|
const [currentTaskId, setCurrentTaskId] = useState<string | null>(null);
|
2025-09-20 00:09:00 +08:00
|
|
|
|
const [createForm, setCreateForm] = useState<CreateProjectForm>({
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
description: "",
|
|
|
|
|
|
repository_url: "",
|
|
|
|
|
|
repository_type: "github",
|
|
|
|
|
|
default_branch: "main",
|
|
|
|
|
|
programming_languages: []
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const supportedLanguages = [
|
|
|
|
|
|
'JavaScript', 'TypeScript', 'Python', 'Java', 'Go', 'Rust', 'C++', 'C#', 'PHP', 'Ruby'
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
loadProjects();
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const loadProjects = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
const data = await api.getProjects();
|
|
|
|
|
|
setProjects(data);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to load projects:', error);
|
|
|
|
|
|
toast.error("加载项目失败");
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleCreateProject = async () => {
|
|
|
|
|
|
if (!createForm.name.trim()) {
|
|
|
|
|
|
toast.error("请输入项目名称");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
await api.createProject({
|
|
|
|
|
|
...createForm,
|
|
|
|
|
|
// 无登录场景下不传 owner_id,由后端置为 null
|
|
|
|
|
|
} as any);
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
toast.success("项目创建成功");
|
|
|
|
|
|
setShowCreateDialog(false);
|
2025-10-22 15:12:59 +08:00
|
|
|
|
resetCreateForm();
|
2025-09-20 00:09:00 +08:00
|
|
|
|
loadProjects();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to create project:', error);
|
|
|
|
|
|
toast.error("创建项目失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
const resetCreateForm = () => {
|
|
|
|
|
|
setCreateForm({
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
description: "",
|
|
|
|
|
|
repository_url: "",
|
|
|
|
|
|
repository_type: "github",
|
|
|
|
|
|
default_branch: "main",
|
|
|
|
|
|
programming_languages: []
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
|
const file = event.target.files?.[0];
|
|
|
|
|
|
if (!file) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 验证文件
|
|
|
|
|
|
const validation = validateZipFile(file);
|
|
|
|
|
|
if (!validation.valid) {
|
|
|
|
|
|
toast.error(validation.error);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否有项目名称
|
|
|
|
|
|
if (!createForm.name.trim()) {
|
|
|
|
|
|
toast.error("请先输入项目名称");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
setUploading(true);
|
|
|
|
|
|
setUploadProgress(0);
|
|
|
|
|
|
|
|
|
|
|
|
// 创建项目
|
|
|
|
|
|
const project = await api.createProject({
|
|
|
|
|
|
...createForm,
|
|
|
|
|
|
repository_type: "other"
|
|
|
|
|
|
} as any);
|
|
|
|
|
|
|
|
|
|
|
|
// 模拟上传进度
|
|
|
|
|
|
const progressInterval = setInterval(() => {
|
|
|
|
|
|
setUploadProgress(prev => {
|
|
|
|
|
|
if (prev >= 90) {
|
|
|
|
|
|
clearInterval(progressInterval);
|
|
|
|
|
|
return 90;
|
|
|
|
|
|
}
|
|
|
|
|
|
return prev + 10;
|
|
|
|
|
|
});
|
|
|
|
|
|
}, 200);
|
|
|
|
|
|
|
|
|
|
|
|
// 扫描ZIP文件
|
|
|
|
|
|
const taskId = await scanZipFile({
|
|
|
|
|
|
projectId: project.id,
|
|
|
|
|
|
zipFile: file,
|
|
|
|
|
|
excludePatterns: ['node_modules/**', '.git/**', 'dist/**', 'build/**'],
|
2025-10-24 18:34:55 +08:00
|
|
|
|
createdBy: 'local-user' // 使用默认本地用户ID
|
2025-10-22 15:12:59 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
clearInterval(progressInterval);
|
|
|
|
|
|
setUploadProgress(100);
|
|
|
|
|
|
|
2025-10-24 20:23:22 +08:00
|
|
|
|
// 关闭创建对话框
|
2025-10-22 15:12:59 +08:00
|
|
|
|
setShowCreateDialog(false);
|
|
|
|
|
|
resetCreateForm();
|
|
|
|
|
|
loadProjects();
|
|
|
|
|
|
|
2025-10-24 20:23:22 +08:00
|
|
|
|
// 显示终端进度窗口
|
|
|
|
|
|
setCurrentTaskId(taskId);
|
|
|
|
|
|
setShowTerminalDialog(true);
|
2025-10-22 15:12:59 +08:00
|
|
|
|
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
console.error('Upload failed:', error);
|
|
|
|
|
|
toast.error(error.message || "上传失败");
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setUploading(false);
|
|
|
|
|
|
setUploadProgress(0);
|
|
|
|
|
|
if (fileInputRef.current) {
|
|
|
|
|
|
fileInputRef.current.value = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
const filteredProjects = projects.filter(project =>
|
|
|
|
|
|
project.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
|
|
|
|
project.description?.toLowerCase().includes(searchTerm.toLowerCase())
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const getRepositoryIcon = (type?: string) => {
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case 'github': return '🐙';
|
|
|
|
|
|
case 'gitlab': return '🦊';
|
|
|
|
|
|
default: return '📁';
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const formatDate = (dateString: string) => {
|
|
|
|
|
|
return new Date(dateString).toLocaleDateString('zh-CN');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-22 22:18:19 +08:00
|
|
|
|
const handleCreateTask = (projectId: string) => {
|
|
|
|
|
|
setSelectedProjectForTask(projectId);
|
|
|
|
|
|
setShowCreateTaskDialog(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleTaskCreated = () => {
|
|
|
|
|
|
toast.success("审计任务已创建", {
|
|
|
|
|
|
description: '因为网络和代码文件大小等因素,审计时长通常至少需要1分钟,请耐心等待...',
|
|
|
|
|
|
duration: 5000
|
|
|
|
|
|
});
|
|
|
|
|
|
// 任务创建后会自动跳转到项目详情页面
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
if (loading) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="flex items-center justify-center min-h-screen">
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<div className="animate-spin rounded-full h-32 w-32 border-b-2 border-primary"></div>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="space-y-6 animate-fade-in">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
{/* 页面标题和操作 */}
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<div>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<h1 className="page-title">项目管理</h1>
|
|
|
|
|
|
<p className="page-subtitle">管理您的代码项目,配置审计规则和查看分析结果</p>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Dialog open={showCreateDialog} onOpenChange={setShowCreateDialog}>
|
|
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
|
|
<Button>
|
|
|
|
|
|
<Plus className="w-4 h-4 mr-2" />
|
|
|
|
|
|
新建项目
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</DialogTrigger>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<DialogContent className="max-w-3xl">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<DialogHeader>
|
|
|
|
|
|
<DialogTitle>创建新项目</DialogTitle>
|
|
|
|
|
|
</DialogHeader>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Tabs defaultValue="repository" className="w-full">
|
|
|
|
|
|
<TabsList className="grid w-full grid-cols-2">
|
|
|
|
|
|
<TabsTrigger value="repository">Git 仓库</TabsTrigger>
|
|
|
|
|
|
<TabsTrigger value="upload">上传代码</TabsTrigger>
|
|
|
|
|
|
</TabsList>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<TabsContent value="repository" className="space-y-4 mt-6">
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="name">项目名称 *</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="name"
|
|
|
|
|
|
value={createForm.name}
|
|
|
|
|
|
onChange={(e) => setCreateForm({ ...createForm, name: e.target.value })}
|
|
|
|
|
|
placeholder="输入项目名称"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="repository_type">仓库类型</Label>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
<Select
|
|
|
|
|
|
value={createForm.repository_type}
|
2025-10-22 15:12:59 +08:00
|
|
|
|
onValueChange={(value: any) => setCreateForm({ ...createForm, repository_type: value })}
|
|
|
|
|
|
>
|
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
|
<SelectValue />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
<SelectItem value="github">GitHub</SelectItem>
|
|
|
|
|
|
<SelectItem value="gitlab">GitLab</SelectItem>
|
|
|
|
|
|
<SelectItem value="other">其他</SelectItem>
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<div className="space-y-2">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Label htmlFor="description">项目描述</Label>
|
|
|
|
|
|
<Textarea
|
|
|
|
|
|
id="description"
|
|
|
|
|
|
value={createForm.description}
|
|
|
|
|
|
onChange={(e) => setCreateForm({ ...createForm, description: e.target.value })}
|
|
|
|
|
|
placeholder="简要描述项目内容和目标"
|
|
|
|
|
|
rows={3}
|
2025-09-20 00:09:00 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="repository_url">仓库地址</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="repository_url"
|
|
|
|
|
|
value={createForm.repository_url}
|
|
|
|
|
|
onChange={(e) => setCreateForm({ ...createForm, repository_url: e.target.value })}
|
|
|
|
|
|
placeholder="https://github.com/user/repo"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="default_branch">默认分支</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="default_branch"
|
|
|
|
|
|
value={createForm.default_branch}
|
|
|
|
|
|
onChange={(e) => setCreateForm({ ...createForm, default_branch: e.target.value })}
|
|
|
|
|
|
placeholder="main"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label>编程语言</Label>
|
|
|
|
|
|
<div className="grid grid-cols-3 gap-2">
|
|
|
|
|
|
{supportedLanguages.map((lang) => (
|
|
|
|
|
|
<label key={lang} className="flex items-center space-x-2">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
checked={createForm.programming_languages.includes(lang)}
|
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
|
if (e.target.checked) {
|
|
|
|
|
|
setCreateForm({
|
|
|
|
|
|
...createForm,
|
|
|
|
|
|
programming_languages: [...createForm.programming_languages, lang]
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setCreateForm({
|
|
|
|
|
|
...createForm,
|
|
|
|
|
|
programming_languages: createForm.programming_languages.filter(l => l !== lang)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="rounded"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span className="text-sm">{lang}</span>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex justify-end space-x-3 pt-4">
|
|
|
|
|
|
<Button variant="outline" onClick={() => setShowCreateDialog(false)}>
|
|
|
|
|
|
取消
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button onClick={handleCreateProject}>
|
|
|
|
|
|
创建项目
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</TabsContent>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<TabsContent value="upload" className="space-y-4 mt-6">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<div className="space-y-2">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Label htmlFor="upload-name">项目名称 *</Label>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Input
|
2025-10-22 15:12:59 +08:00
|
|
|
|
id="upload-name"
|
|
|
|
|
|
value={createForm.name}
|
|
|
|
|
|
onChange={(e) => setCreateForm({ ...createForm, name: e.target.value })}
|
|
|
|
|
|
placeholder="输入项目名称"
|
2025-09-20 00:09:00 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<div className="space-y-2">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Label htmlFor="upload-description">项目描述</Label>
|
|
|
|
|
|
<Textarea
|
|
|
|
|
|
id="upload-description"
|
|
|
|
|
|
value={createForm.description}
|
|
|
|
|
|
onChange={(e) => setCreateForm({ ...createForm, description: e.target.value })}
|
|
|
|
|
|
placeholder="简要描述项目内容和目标"
|
|
|
|
|
|
rows={3}
|
2025-09-20 00:09:00 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label>编程语言</Label>
|
|
|
|
|
|
<div className="grid grid-cols-3 gap-2">
|
|
|
|
|
|
{supportedLanguages.map((lang) => (
|
|
|
|
|
|
<label key={lang} className="flex items-center space-x-2">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
checked={createForm.programming_languages.includes(lang)}
|
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
|
if (e.target.checked) {
|
|
|
|
|
|
setCreateForm({
|
|
|
|
|
|
...createForm,
|
|
|
|
|
|
programming_languages: [...createForm.programming_languages, lang]
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setCreateForm({
|
|
|
|
|
|
...createForm,
|
|
|
|
|
|
programming_languages: createForm.programming_languages.filter(l => l !== lang)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="rounded"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span className="text-sm">{lang}</span>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
{/* 文件上传区域 */}
|
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
|
<Label>上传代码文件</Label>
|
|
|
|
|
|
<div className="border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-gray-400 transition-colors">
|
|
|
|
|
|
<Upload className="w-12 h-12 text-gray-400 mx-auto mb-4" />
|
|
|
|
|
|
<h3 className="text-lg font-medium text-gray-900 mb-2">上传 ZIP 文件</h3>
|
|
|
|
|
|
<p className="text-sm text-gray-500 mb-4">
|
|
|
|
|
|
支持 ZIP 格式,最大 100MB
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<input
|
|
|
|
|
|
ref={fileInputRef}
|
|
|
|
|
|
type="file"
|
|
|
|
|
|
accept=".zip"
|
|
|
|
|
|
onChange={handleFileUpload}
|
|
|
|
|
|
className="hidden"
|
|
|
|
|
|
disabled={uploading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
onClick={() => fileInputRef.current?.click()}
|
|
|
|
|
|
disabled={uploading || !createForm.name.trim()}
|
|
|
|
|
|
>
|
|
|
|
|
|
<FileText className="w-4 h-4 mr-2" />
|
|
|
|
|
|
选择文件
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{uploading && (
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<div className="flex items-center justify-between text-sm">
|
|
|
|
|
|
<span>上传并分析中...</span>
|
|
|
|
|
|
<span>{uploadProgress}%</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Progress value={uploadProgress} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<div className="bg-red-50 border border-red-200 rounded-lg p-4">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex items-start space-x-3">
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<AlertCircle className="w-5 h-5 text-primary mt-0.5" />
|
|
|
|
|
|
<div className="text-sm text-red-800">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<p className="font-medium mb-1">上传说明:</p>
|
|
|
|
|
|
<ul className="space-y-1 text-xs">
|
|
|
|
|
|
<li>• 请确保 ZIP 文件包含完整的项目代码</li>
|
|
|
|
|
|
<li>• 系统会自动排除 node_modules、.git 等目录</li>
|
|
|
|
|
|
<li>• 上传后将立即开始代码分析</li>
|
|
|
|
|
|
<li>• 分析完成后可在任务详情页查看结果</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-end space-x-3 pt-4">
|
|
|
|
|
|
<Button variant="outline" onClick={() => setShowCreateDialog(false)} disabled={uploading}>
|
|
|
|
|
|
取消
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</TabsContent>
|
|
|
|
|
|
</Tabs>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</DialogContent>
|
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 搜索和筛选 */}
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardContent className="p-4">
|
|
|
|
|
|
<div className="flex items-center space-x-4">
|
|
|
|
|
|
<div className="flex-1 relative">
|
|
|
|
|
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
placeholder="搜索项目名称或描述..."
|
|
|
|
|
|
value={searchTerm}
|
|
|
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Button variant="outline">
|
|
|
|
|
|
<Settings className="w-4 h-4 mr-2" />
|
|
|
|
|
|
筛选
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 项目列表 */}
|
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
|
|
|
|
|
{filteredProjects.length > 0 ? (
|
|
|
|
|
|
filteredProjects.map((project) => (
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Card key={project.id} className="card-modern group">
|
|
|
|
|
|
<CardHeader className="pb-4">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<div className="flex items-start justify-between">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex items-center space-x-3">
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<div className="w-10 h-10 rounded-lg bg-gradient-to-br from-primary to-accent flex items-center justify-center text-white text-lg">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
{getRepositoryIcon(project.repository_type)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<CardTitle className="text-lg group-hover:text-primary transition-colors">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Link to={`/projects/${project.id}`}>
|
|
|
|
|
|
{project.name}
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
</CardTitle>
|
|
|
|
|
|
{project.description && (
|
|
|
|
|
|
<p className="text-sm text-gray-500 mt-1 line-clamp-2">
|
|
|
|
|
|
{project.description}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Badge variant={project.is_active ? "default" : "secondary"} className="flex-shrink-0">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
{project.is_active ? '活跃' : '暂停'}
|
|
|
|
|
|
</Badge>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardHeader>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
|
{/* 项目信息 */}
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="space-y-3">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
{project.repository_url && (
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex items-center text-sm text-gray-500">
|
|
|
|
|
|
<GitBranch className="w-4 h-4 mr-2 flex-shrink-0" />
|
2025-10-22 22:18:19 +08:00
|
|
|
|
<a
|
|
|
|
|
|
href={project.repository_url}
|
|
|
|
|
|
target="_blank"
|
2025-09-20 00:09:00 +08:00
|
|
|
|
rel="noopener noreferrer"
|
2025-10-22 17:42:48 +08:00
|
|
|
|
className="hover:text-primary transition-colors flex items-center truncate"
|
2025-09-20 00:09:00 +08:00
|
|
|
|
>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<span className="truncate">{project.repository_url.replace('https://', '')}</span>
|
|
|
|
|
|
<ExternalLink className="w-3 h-3 ml-1 flex-shrink-0" />
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</a>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex items-center justify-between text-sm text-gray-500">
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
<Calendar className="w-4 h-4 mr-2" />
|
|
|
|
|
|
{formatDate(project.created_at)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
<Users className="w-4 h-4 mr-2" />
|
|
|
|
|
|
{project.owner?.full_name || '未知'}
|
|
|
|
|
|
</div>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 编程语言 */}
|
|
|
|
|
|
{project.programming_languages && (
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
|
{JSON.parse(project.programming_languages).slice(0, 4).map((lang: string) => (
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Badge key={lang} variant="outline" className="text-xs">
|
|
|
|
|
|
{lang}
|
|
|
|
|
|
</Badge>
|
|
|
|
|
|
))}
|
2025-10-22 15:12:59 +08:00
|
|
|
|
{JSON.parse(project.programming_languages).length > 4 && (
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Badge variant="outline" className="text-xs">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
+{JSON.parse(project.programming_languages).length - 4}
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</Badge>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 快速操作 */}
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="flex gap-2 pt-2">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Link to={`/projects/${project.id}`} className="flex-1">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Button variant="outline" size="sm" className="w-full btn-secondary">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Code className="w-4 h-4 mr-2" />
|
|
|
|
|
|
查看详情
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Link>
|
2025-10-22 22:18:19 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
className="btn-primary"
|
|
|
|
|
|
onClick={() => handleCreateTask(project.id)}
|
|
|
|
|
|
>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Shield className="w-4 h-4 mr-2" />
|
2025-10-22 22:18:19 +08:00
|
|
|
|
新建任务
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
))
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="col-span-full">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Card className="card-modern">
|
|
|
|
|
|
<CardContent className="empty-state py-16">
|
|
|
|
|
|
<div className="empty-icon">
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<Code className="w-8 h-8 text-primary" />
|
2025-10-22 15:12:59 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<h3 className="text-lg font-medium text-gray-900 mb-2">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
{searchTerm ? '未找到匹配的项目' : '暂无项目'}
|
|
|
|
|
|
</h3>
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<p className="text-gray-500 mb-6 max-w-md">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
{searchTerm ? '尝试调整搜索条件' : '创建您的第一个项目开始代码审计'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
{!searchTerm && (
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Button onClick={() => setShowCreateDialog(true)} className="btn-primary">
|
2025-09-20 00:09:00 +08:00
|
|
|
|
<Plus className="w-4 h-4 mr-2" />
|
|
|
|
|
|
创建项目
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 项目统计 */}
|
|
|
|
|
|
{projects.length > 0 && (
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
|
|
|
|
|
<Card className="stat-card">
|
|
|
|
|
|
<CardContent className="p-5">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="stat-label">总项目数</p>
|
|
|
|
|
|
<p className="stat-value text-xl">{projects.length}</p>
|
|
|
|
|
|
</div>
|
2025-10-22 17:42:48 +08:00
|
|
|
|
<div className="stat-icon from-primary to-accent">
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Code className="w-5 h-5 text-white" />
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Card className="stat-card">
|
|
|
|
|
|
<CardContent className="p-5">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="stat-label">活跃项目</p>
|
|
|
|
|
|
<p className="stat-value text-xl">{projects.filter(p => p.is_active).length}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="stat-icon from-emerald-500 to-emerald-600">
|
|
|
|
|
|
<Activity className="w-5 h-5 text-white" />
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Card className="stat-card">
|
|
|
|
|
|
<CardContent className="p-5">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="stat-label">GitHub</p>
|
|
|
|
|
|
<p className="stat-value text-xl">{projects.filter(p => p.repository_type === 'github').length}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="stat-icon from-purple-500 to-purple-600">
|
|
|
|
|
|
<GitBranch className="w-5 h-5 text-white" />
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2025-10-22 15:12:59 +08:00
|
|
|
|
<Card className="stat-card">
|
|
|
|
|
|
<CardContent className="p-5">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="stat-label">GitLab</p>
|
|
|
|
|
|
<p className="stat-value text-xl">{projects.filter(p => p.repository_type === 'gitlab').length}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="stat-icon from-orange-500 to-orange-600">
|
|
|
|
|
|
<Shield className="w-5 h-5 text-white" />
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-10-22 22:18:19 +08:00
|
|
|
|
|
|
|
|
|
|
{/* 创建任务对话框 */}
|
|
|
|
|
|
<CreateTaskDialog
|
|
|
|
|
|
open={showCreateTaskDialog}
|
|
|
|
|
|
onOpenChange={setShowCreateTaskDialog}
|
|
|
|
|
|
onTaskCreated={handleTaskCreated}
|
|
|
|
|
|
preselectedProjectId={selectedProjectForTask}
|
|
|
|
|
|
/>
|
2025-10-24 20:23:22 +08:00
|
|
|
|
|
|
|
|
|
|
{/* 终端进度对话框 */}
|
|
|
|
|
|
<TerminalProgressDialog
|
|
|
|
|
|
open={showTerminalDialog}
|
|
|
|
|
|
onOpenChange={setShowTerminalDialog}
|
|
|
|
|
|
taskId={currentTaskId}
|
|
|
|
|
|
taskType="zip"
|
|
|
|
|
|
/>
|
2025-09-20 00:09:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|