超管后台 - 调整页面路由为动态路由请求,修改页面渲染为tabs标签形式
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from "react"
|
||||
import Link from "next/link"
|
||||
import { useSearchParams, useRouter, usePathname } from "next/navigation"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
@@ -19,6 +18,7 @@ import {
|
||||
} from "@/components/ui/dialog"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { PaginationControls } from "@/components/ui/pagination-controls"
|
||||
import { useTabContext } from "@/app/dashboard/layout"
|
||||
|
||||
interface Project {
|
||||
id: number
|
||||
@@ -36,6 +36,8 @@ export default function ProjectsPage() {
|
||||
const searchParams = useSearchParams()
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
const { addTab } = useTabContext()
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState("")
|
||||
const [projects, setProjects] = useState<Project[]>([])
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
@@ -136,6 +138,7 @@ export default function ProjectsPage() {
|
||||
|
||||
if (data.code === 200) {
|
||||
toast.success("删除成功")
|
||||
|
||||
// Fetch projects again after delete
|
||||
const fetchProjects = async () => {
|
||||
setIsLoading(true)
|
||||
@@ -168,14 +171,39 @@ export default function ProjectsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
// 打开项目详情
|
||||
const handleViewProject = (project: Project) => {
|
||||
addTab({
|
||||
label: `项目 #${project.id} - 详情`,
|
||||
path: `/dashboard/projects/${project.id}`,
|
||||
closable: true
|
||||
});
|
||||
}
|
||||
|
||||
// 打开编辑项目
|
||||
const handleEditProject = (project: Project) => {
|
||||
addTab({
|
||||
label: `项目 #${project.id} - 编辑`,
|
||||
path: `/dashboard/projects/${project.id}/edit`,
|
||||
closable: true
|
||||
});
|
||||
}
|
||||
|
||||
// 打开新建项目
|
||||
const handleNewProject = () => {
|
||||
addTab({
|
||||
label: "新建项目",
|
||||
path: "/dashboard/projects/new",
|
||||
closable: true
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex justify-between">
|
||||
<h1 className="text-2xl font-bold">项目列表</h1>
|
||||
<Button asChild>
|
||||
<Link href="/dashboard/projects/new">
|
||||
<Plus className="mr-2 h-4 w-4" /> 新建项目
|
||||
</Link>
|
||||
<Button onClick={handleNewProject}>
|
||||
<Plus className="mr-2 h-4 w-4" /> 新建项目
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -207,7 +235,7 @@ export default function ProjectsPage() {
|
||||
<TableBody>
|
||||
{isLoading ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="h-24 text-center">
|
||||
<TableCell colSpan={6} className="h-24 text-center">
|
||||
加载中...
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -232,15 +260,11 @@ export default function ProjectsPage() {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/dashboard/projects/${project.id}`}>
|
||||
<Eye className="mr-2 h-4 w-4" /> 查看详情
|
||||
</Link>
|
||||
<DropdownMenuItem onClick={() => handleViewProject(project)}>
|
||||
<Eye className="mr-2 h-4 w-4" /> 查看详情
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/dashboard/projects/${project.id}/edit`}>
|
||||
<Edit className="mr-2 h-4 w-4" /> 编辑项目
|
||||
</Link>
|
||||
<DropdownMenuItem onClick={() => handleEditProject(project)}>
|
||||
<Edit className="mr-2 h-4 w-4" /> 编辑项目
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
@@ -255,7 +279,7 @@ export default function ProjectsPage() {
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="h-24 text-center">
|
||||
<TableCell colSpan={6} className="h-24 text-center">
|
||||
未找到项目
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
Reference in New Issue
Block a user