From 00aa18951ed92150b953ad6b3296f4ac43404d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 15 Apr 2025 16:33:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E5=85=B3=E8=81=94=E8=AE=BE=E5=A4=87=E5=8A=9F=E8=83=BD=E5=B0=86?= =?UTF-8?q?=E5=8F=AA=E5=9C=A8=E7=BC=96=E8=BE=91=E9=A1=B5=E9=9D=A2=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dashboard/projects/new/page.tsx | 168 +++++++++++------- 1 file changed, 105 insertions(+), 63 deletions(-) diff --git a/SuperAdmin/app/dashboard/projects/new/page.tsx b/SuperAdmin/app/dashboard/projects/new/page.tsx index 424c5251..d501d69b 100644 --- a/SuperAdmin/app/dashboard/projects/new/page.tsx +++ b/SuperAdmin/app/dashboard/projects/new/page.tsx @@ -1,7 +1,6 @@ "use client" import type React from "react" - import { useState } from "react" import { useRouter } from "next/navigation" import { Button } from "@/components/ui/button" @@ -10,36 +9,71 @@ import { Textarea } from "@/components/ui/textarea" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" -import { ArrowLeft, Plus, Trash } from "lucide-react" +import { ArrowLeft } from "lucide-react" import Link from "next/link" +import { toast } from "sonner" export default function NewProjectPage() { const router = useRouter() const [isSubmitting, setIsSubmitting] = useState(false) - const [devices, setDevices] = useState([{ id: "1", name: "" }]) - const [status, setStatus] = useState("1") // 默认启用 + const [formData, setFormData] = useState({ + name: "", + account: "", + password: "", + confirmPassword: "", + realName: "", + nickname: "", + description: "" + }) - const handleAddDevice = () => { - setDevices([...devices, { id: Date.now().toString(), name: "" }]) + const handleChange = (e: React.ChangeEvent) => { + const { id, value } = e.target + setFormData(prev => ({ + ...prev, + [id]: value + })) } - const handleRemoveDevice = (id: string) => { - setDevices(devices.filter((device) => device.id !== id)) - } - - const handleDeviceChange = (id: string, value: string) => { - setDevices(devices.map((device) => (device.id === id ? { ...device, name: value } : device))) - } - - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() + + // 表单验证 + if (formData.password !== formData.confirmPassword) { + toast.error("两次输入的密码不一致") + return + } + setIsSubmitting(true) - // Simulate API call - setTimeout(() => { + try { + const response = await fetch("http://yishi.com/company/create", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: formData.name, + account: formData.account, + password: formData.password, + realName: formData.realName, + nickname: formData.nickname, + description: formData.description + }), + }) + + const data = await response.json() + + if (data.code === 200) { + toast.success("创建成功") + router.push("/dashboard/projects") + } else { + toast.error(data.msg || "创建失败") + } + } catch (error) { + toast.error("创建失败,请稍后重试") + } finally { setIsSubmitting(false) - router.push("/dashboard/projects") - }, 1500) + } } return ( @@ -61,78 +95,86 @@ export default function NewProjectPage() {
- - + +
- -
- -
- - +
- +
- +
- +
- -
-
- -
- -
- {devices.map((device, index) => ( -
- handleDeviceChange(device.id, e.target.value)} - /> - {devices.length > 1 && ( - - )} -
- ))} - +
-