超管后台 - 对接删除项目

This commit is contained in:
柳清爽
2025-04-21 11:46:54 +08:00
parent cc05564328
commit fef6e0fd84
3 changed files with 89 additions and 11 deletions

View File

@@ -8,6 +8,14 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
import { Plus, Search, MoreHorizontal, Edit, Eye, Trash, ChevronLeft, ChevronRight } from "lucide-react"
import { toast } from "sonner"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
interface Project {
id: number
@@ -27,6 +35,9 @@ export default function ProjectsPage() {
const [currentPage, setCurrentPage] = useState(1)
const [totalPages, setTotalPages] = useState(1)
const [pageSize] = useState(10)
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)
const [deletingProjectId, setDeletingProjectId] = useState<number | null>(null)
const [isDeleting, setIsDeleting] = useState(false)
// 获取项目列表
useEffect(() => {
@@ -59,6 +70,44 @@ export default function ProjectsPage() {
}
}
const handleDeleteClick = (projectId: number) => {
setDeletingProjectId(projectId)
setDeleteDialogOpen(true)
}
const handleConfirmDelete = async () => {
if (!deletingProjectId) return
setIsDeleting(true)
try {
const response = await fetch("http://yishi.com/company/delete", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: deletingProjectId
}),
})
const data = await response.json()
if (data.code === 200) {
toast.success("删除成功")
// 刷新项目列表
window.location.reload()
} else {
toast.error(data.msg || "删除失败")
}
} catch (error) {
toast.error("网络错误,请稍后重试")
} finally {
setIsDeleting(false)
setDeleteDialogOpen(false)
setDeletingProjectId(null)
}
}
return (
<div className="space-y-6">
<div className="flex justify-between">
@@ -127,7 +176,10 @@ export default function ProjectsPage() {
<Edit className="mr-2 h-4 w-4" />
</Link>
</DropdownMenuItem>
<DropdownMenuItem className="text-destructive">
<DropdownMenuItem
className="text-red-600"
onClick={() => handleDeleteClick(project.id)}
>
<Trash className="mr-2 h-4 w-4" />
</DropdownMenuItem>
</DropdownMenuContent>
@@ -179,6 +231,34 @@ export default function ProjectsPage() {
</Button>
</div>
)}
{/* 删除确认对话框 */}
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button
variant="outline"
onClick={() => setDeleteDialogOpen(false)}
disabled={isDeleting}
>
</Button>
<Button
variant="destructive"
onClick={handleConfirmDelete}
disabled={isDeleting}
>
{isDeleting ? "删除中..." : "确认删除"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}