"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { toast } from "sonner"; export default function NewSoftwarePage() { const router = useRouter(); const [loading, setLoading] = useState(false); function generateSlug(name: string) { return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""); } async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); const fd = new FormData(e.currentTarget); const res = await fetch("/api/software", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: fd.get("name"), slug: fd.get("slug"), description: fd.get("description"), }), }); if (res.ok) { toast.success("创建成功"); router.push("/admin/software"); router.refresh(); } else { const err = await res.json(); toast.error(err.error || "创建失败"); } setLoading(false); } return (

新建软件

软件信息
{ const slugInput = document.getElementById("slug") as HTMLInputElement; if (slugInput) slugInput.value = generateSlug(e.target.value); }} />