From f48c12f1ec840bd80292a1d8e75324d215176581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Thu, 24 Apr 2025 10:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DReact=E9=A1=B5=E9=9D=A2=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E3=80=81=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96=E5=AD=90=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E5=88=97=E8=A1=A8=E7=9A=84=E8=AF=B7=E6=B1=82=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E3=80=81=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E3=80=81=E9=A2=9C=E8=89=B2=E6=98=BE=E7=A4=BA=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dashboard/projects/[id]/page.tsx | 161 ++++++++++-------- SuperAdmin/app/dashboard/projects/page.tsx | 40 ++++- 2 files changed, 128 insertions(+), 73 deletions(-) diff --git a/SuperAdmin/app/dashboard/projects/[id]/page.tsx b/SuperAdmin/app/dashboard/projects/[id]/page.tsx index 0fe60923..f5b9e064 100644 --- a/SuperAdmin/app/dashboard/projects/[id]/page.tsx +++ b/SuperAdmin/app/dashboard/projects/[id]/page.tsx @@ -11,6 +11,7 @@ import { ArrowLeft, Edit } from "lucide-react" import { toast } from "sonner" import { use } from "react" import Image from "next/image" +import { Badge } from "@/components/ui/badge" interface ProjectProfile { id: number @@ -112,15 +113,7 @@ export default function ProjectDetailPage({ params }: { params: { id: string } } if (activeTab === "accounts") { setIsSubUsersLoading(true) try { - const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/subusers`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - companyId: parseInt(id) - }) - }) + const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/subusers?companyId=${id}`) const data = await response.json() if (data.code === 200) { @@ -243,32 +236,53 @@ export default function ProjectDetailPage({ params }: { params: { id: string } } ) : devices.length === 0 ? (
暂无数据
) : ( - - - - 设备名称 - 设备型号 - 品牌 - IMEI - 设备状态 - 微信状态 - 微信好友数量 - - - - {devices.map((device) => ( - - {device.memo} - {device.model} - {device.brand} - {device.imei} - {device.alive === 1 ? "在线" : "离线"} - {device.wAlive === 1 ? "在线" : device.wAlive === 0 ? "离线" : "未登录微信"} - {device.friendCount || 0} + <> +
+ + + 设备名称 + 设备型号 + 品牌 + IMEI + 设备状态 + 微信状态 + 微信好友数量 - ))} - -
+ + + {devices.map((device) => ( + + {device.memo} + {device.model} + {device.brand} + {device.imei} + + + {device.alive === 1 ? "在线" : "离线"} + + + + + {device.wAlive === 1 ? "已登录" : device.wAlive === 0 ? "已登出" : "未登录微信"} + + + {device.friendCount || 0} + + ))} + + +
+ 共 {devices.length} 条数据 +
+ )} @@ -286,42 +300,51 @@ export default function ProjectDetailPage({ params }: { params: { id: string } } ) : subUsers.length === 0 ? (
暂无数据
) : ( - - - - 头像 - 账号ID - 登录账号 - 昵称 - 手机号 - 状态 - 账号类型 - 创建时间 - - - - {subUsers.map((user) => ( - - - - - {user.id} - {user.account} - {user.username} - {user.phone} - {user.status === 1 ? "登录" : "禁用"} - {user.typeId === 1 ? "操盘手" : "门店顾问"} - {user.createTime} + <> +
+ + + 头像 + 账号ID + 登录账号 + 昵称 + 手机号 + 状态 + 账号类型 + 创建时间 - ))} - -
+ + + {subUsers.map((user) => ( + + + {user.username} + + {user.id} + {user.account} + {user.username} + {user.phone} + + + {user.status === 1 ? "启用" : "禁用"} + + + {user.typeId === 1 ? "操盘手" : "门店顾问"} + {user.createTime} + + ))} + + +
+ 共 {subUsers.length} 条数据 +
+ )} diff --git a/SuperAdmin/app/dashboard/projects/page.tsx b/SuperAdmin/app/dashboard/projects/page.tsx index 609c3680..6caca435 100644 --- a/SuperAdmin/app/dashboard/projects/page.tsx +++ b/SuperAdmin/app/dashboard/projects/page.tsx @@ -2,6 +2,7 @@ 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" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" @@ -32,17 +33,39 @@ interface Project { } export default function ProjectsPage() { + const searchParams = useSearchParams() + const router = useRouter() + const pathname = usePathname() const [searchTerm, setSearchTerm] = useState("") const [projects, setProjects] = useState([]) const [isLoading, setIsLoading] = useState(true) - const [currentPage, setCurrentPage] = useState(1) + const [currentPage, setCurrentPage] = useState(parseInt(searchParams.get("page") || "1")) const [totalPages, setTotalPages] = useState(1) - const [pageSize, setPageSize] = useState(10) + const [pageSize, setPageSize] = useState(parseInt(searchParams.get("pageSize") || "10")) const [totalItems, setTotalItems] = useState(0) const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) const [deletingProjectId, setDeletingProjectId] = useState(null) const [isDeleting, setIsDeleting] = useState(false) + // 从URL更新状态 + useEffect(() => { + const page = parseInt(searchParams.get("page") || "1") + const size = parseInt(searchParams.get("pageSize") || "10") + setCurrentPage(page) + setPageSize(size) + }, [searchParams]) + + // 更新URL查询参数 + const updateUrlParams = (page: number, size: number) => { + const params = new URLSearchParams() + params.set("page", page.toString()) + params.set("pageSize", size.toString()) + if (searchTerm) { + params.set("search", searchTerm) + } + router.replace(`${pathname}?${params.toString()}`) + } + // 获取项目列表 useEffect(() => { const fetchProjects = async () => { @@ -72,12 +95,21 @@ export default function ProjectsPage() { } fetchProjects() - }, [currentPage, pageSize]) + // 更新URL参数 + updateUrlParams(currentPage, pageSize) + }, [currentPage, pageSize, pathname]) // 处理页面大小变化 const handlePageSizeChange = (newSize: number) => { setPageSize(newSize) setCurrentPage(1) + updateUrlParams(1, newSize) + } + + // 处理页面变化 + const handlePageChange = (newPage: number) => { + setCurrentPage(newPage) + updateUrlParams(newPage, pageSize) } const handleDeleteClick = (projectId: number) => { @@ -237,7 +269,7 @@ export default function ProjectsPage() { totalPages={totalPages} pageSize={pageSize} totalItems={totalItems} - onPageChange={setCurrentPage} + onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} />