官网 初版

This commit is contained in:
rucky
2026-03-18 17:13:27 +08:00
parent 879c4bdfc8
commit 241a76caeb
95 changed files with 8889 additions and 113 deletions

View File

@@ -0,0 +1,84 @@
"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<HTMLFormElement>) {
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 (
<div className="mx-auto max-w-lg space-y-6">
<h1 className="text-3xl font-bold"></h1>
<Card>
<CardHeader><CardTitle></CardTitle></CardHeader>
<CardContent>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name"> *</Label>
<Input
id="name" name="name" required
onChange={(e) => {
const slugInput = document.getElementById("slug") as HTMLInputElement;
if (slugInput) slugInput.value = generateSlug(e.target.value);
}}
/>
</div>
<div className="space-y-2">
<Label htmlFor="slug">Slug *</Label>
<Input id="slug" name="slug" required pattern="[a-z0-9-]+" />
</div>
<div className="space-y-2">
<Label htmlFor="description"></Label>
<Textarea id="description" name="description" rows={3} />
</div>
<div className="flex gap-3">
<Button type="submit" disabled={loading}>
{loading ? "创建中..." : "创建"}
</Button>
<Button type="button" variant="outline" onClick={() => router.back()}>
</Button>
</div>
</form>
</CardContent>
</Card>
</div>
);
}