'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import CreateTaskForm from '../components/CreateTaskForm'; interface Task { id: string; name: string; status: string; priority: string; progress: number; assignee_user_id: string; created_at: string; updated_at: string; } const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'; export default function ProjectsPage() { const [tasks, setTasks] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const [showCreateForm, setShowCreateForm] = useState(false); // 模拟项目ID,生产环境应该从路由或上下文获取 const projectId = 'demo_project_1'; const workspaceId = 'demo_workspace_1'; useEffect(() => { fetchTasks(); }, []); const fetchTasks = async () => { setLoading(true); try { const res = await fetch(`${API_BASE}/api/v1/project-management/tasks?project_id=${projectId}`); if (!res.ok) throw new Error('获取任务列表失败'); const data = await res.json(); setTasks(data); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; const getStatusColor = (status: string) => { const colors: Record = { pending: '#86909C', in_progress: '#165DFF', completed: '#00B42A', blocked: '#F53F3F', cancelled: '#6E7681', }; return colors[status] || '#6E7681'; }; const getStatusText = (status: string) => { const texts: Record = { pending: '待开始', in_progress: '进行中', completed: '已完成', blocked: '阻塞', cancelled: '已取消', }; return texts[status] || status; }; const getPriorityText = (priority: string) => { const texts: Record = { low: '低', medium: '中', high: '高', urgent: '紧急', }; return texts[priority] || priority; }; if (loading && !showCreateForm) { return (

加载中...

); } return (
{/* Header */}
📁 项目推进器 Demo 项目
{/* Main Content */}
{error && (
{error}
)} {showCreateForm ? ( { setShowCreateForm(false); fetchTasks(); }} onCancel={() => setShowCreateForm(false)} /> ) : tasks.length === 0 ? (

暂无任务

点击右上角"+ 新增任务"创建第一个任务

) : (
{tasks.map((task) => ( ))}
任务名称 状态 优先级 进度 创建时间
{task.name} {getStatusText(task.status)} {getPriorityText(task.priority)}
{task.progress}%
{new Date(task.created_at).toLocaleDateString('zh-CN')}
)}
{/* Footer */}
); }