"use client"; import { useEffect, useState } from "react"; import {Plus } from "lucide-react"; import { listTasks, updateTask } from "@/lib/api-v2"; import { PageContainer, Badge } from "@/components/shared/PageContainer"; import { LoadingSpinner } from "@/components/shared/LoadingSpinner"; import { EmptyState } from "@/components/shared/EmptyState"; import { toast } from "sonner"; /** 任务项。 */ interface TaskItem { id: string; title: string; status: string; priority: string; description?: string; } const STATUS_LABELS: Record = { todo: "待办", in_progress: "进行中", done: "已完成", cancelled: "已取消", }; const PRIORITY_COLORS: Record = { urgent: "red", high: "amber", medium: "gray", low: "blue", }; export default function TasksPage() { const [items, setItems] = useState([]); const [isLoading, setIsLoading] = useState(true); const load = () => { listTasks() .then((resp) => setItems((resp.data as TaskItem[]) ?? [])) .catch(() => setItems([])) .finally(() => setIsLoading(false)); }; useEffect(() => { load(); }, []); const handleStatusChange = async (id: string, status: string) => { try { await updateTask(id, { status }); toast.success("状态已更新"); load(); } catch { toast.error("更新失败"); } }; const columns = ["todo", "in_progress", "done"]; return ( 新建任务 } > {isLoading ? ( ) : items.length === 0 ? ( ) : (
{columns.map((col) => (

{STATUS_LABELS[col]}

{items.filter((i) => i.status === col).map((item, i) => (
{item.title} {item.priority}
{item.description &&

{item.description}

}
))}
))}
)}
); }