diff --git a/SuperAdmin/app/dashboard/projects/[id]/edit/page.tsx b/SuperAdmin/app/dashboard/projects/[id]/edit/page.tsx index 7ec4c486..9c7f266e 100644 --- a/SuperAdmin/app/dashboard/projects/[id]/edit/page.tsx +++ b/SuperAdmin/app/dashboard/projects/[id]/edit/page.tsx @@ -8,9 +8,11 @@ import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" -import { ArrowLeft, Plus, Trash } from "lucide-react" +import { ArrowLeft, Plus, Trash, X } from "lucide-react" import Link from "next/link" import { toast, Toaster } from "sonner" +import Image from "next/image" +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" // 为React.use添加类型声明 declare module 'react' { @@ -36,6 +38,7 @@ interface Project { userCount: number username: string status: number + s2_accountId?: number devices?: Device[] } @@ -46,6 +49,9 @@ export default function EditProjectPage({ params }: { params: { id: string } }) const [project, setProject] = useState(null) const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") + const [isModalOpen, setIsModalOpen] = useState(false) + const [qrCodeData, setQrCodeData] = useState("") + const [isAddingDevice, setIsAddingDevice] = useState(false) const { id } = React.use(params) useEffect(() => { @@ -112,8 +118,42 @@ export default function EditProjectPage({ params }: { params: { id: string } }) } } - const handleAddDevice = () => { - router.push(`/dashboard/projects/${id}/devices/new`) + const handleAddDevice = async () => { + if (!project?.s2_accountId) { + toast.error("无法添加设备,未找到账号ID") + return + } + + setIsAddingDevice(true) + try { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/v1/api/device/add`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + accountId: project.s2_accountId + }), + }) + + const data = await response.json() + + if (data.code === 200 && data.data?.qrCode) { + setQrCodeData(data.data.qrCode) + setIsModalOpen(true) + } else { + toast.error(data.msg || "获取设备二维码失败") + } + } catch (error) { + toast.error("网络错误,请稍后重试") + } finally { + setIsAddingDevice(false) + } + } + + const closeModal = () => { + setIsModalOpen(false) + setQrCodeData("") } if (isLoading) { @@ -232,8 +272,18 @@ export default function EditProjectPage({ params }: { params: { id: string } }) /> ))} - @@ -254,11 +304,43 @@ export default function EditProjectPage({ params }: { params: { id: string } }) 取消 + + {/* 使用Dialog组件替代自定义模态框 */} + !open && closeModal()}> + + + 添加设备 + + 请使用新设备进行扫码添加 + + +
+
+ {qrCodeData ? ( + 设备二维码 + ) : ( +
+

二维码加载中...

+
+ )} +
+
+ + + +
+
) }