"use client" import { useState, useEffect } from "react" import { apiRequest } from '@/lib/api-utils' import { toast } from "sonner" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { useRouter } from "next/navigation" interface Project { id: number name: string account: string phone: string status: number createTime: string } export default function ProjectList() { const [projects, setProjects] = useState([]) const [isLoading, setIsLoading] = useState(false) const router = useRouter() const fetchProjects = async () => { try { setIsLoading(true) const params = new URLSearchParams() params.append('page', '1') params.append('limit', '10') const result = await apiRequest(`/company/list?${params.toString()}`) if (result.code === 200 && result.data) { setProjects(result.data) } else { toast.error(result.msg || "获取项目列表失败") } } catch (error) { console.error("获取项目列表失败:", error) toast.error("网络错误,请稍后再试") } finally { setIsLoading(false) } } const handleDelete = async (id: number) => { try { setIsLoading(true) const result = await apiRequest('/company/delete', 'POST', { id }) if (result.code === 200) { toast.success("删除成功") fetchProjects() } else { toast.error(result.msg || "删除失败") } } catch (error) { console.error("删除项目失败:", error) toast.error("网络错误,请稍后再试") } finally { setIsLoading(false) } } useEffect(() => { fetchProjects() }, []) return (

项目列表

项目名称 账号 手机号 状态 创建时间 操作 {projects.map((project) => ( {project.name} {project.account} {project.phone || '-'} {project.status === 1 ? "正常" : "禁用"} {project.createTime}
))}
) }