Update application code and dependencies

This commit is contained in:
root
2026-05-06 17:22:50 +08:00
parent efc8f4bf78
commit a3ee04379d
60 changed files with 6793 additions and 860 deletions
+196
View File
@@ -0,0 +1,196 @@
'use client'
import { useState } from "react"
import { useRouter } from "next/navigation"
export default function AgentForm({
categories,
agent,
}: {
categories: { id: number; name: string }[]
agent?: {
id?: number
name: string
slug: string
description: string
icon?: string
categoryId?: number
features?: string
status?: string
}
}) {
const router = useRouter()
const [formData, setFormData] = useState({
name: agent?.name || "",
slug: agent?.slug || "",
description: agent?.description || "",
icon: agent?.icon || "",
categoryId: agent?.categoryId || "",
features: agent?.features || "",
status: agent?.status || "active",
})
const [loading, setLoading] = useState(false)
const [error, setError] = useState("")
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true)
setError("")
try {
const url = agent?.id
? `/api/admin/agents/${agent.id}`
: "/api/admin/agents"
const method = agent?.id ? "PUT" : "POST"
const res = await fetch(url, {
method,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(formData),
})
if (res.ok) {
router.push("/admin/agents")
} else {
setError("保存失败")
}
} catch (err) {
setError("保存失败,请稍后重试")
} finally {
setLoading(false)
}
}
return (
<form onSubmit={handleSubmit} className="space-y-6">
{error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm">
{error}
</div>
)}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<input
type="text"
required
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="智能客服助手"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Slug
</label>
<input
type="text"
required
value={formData.slug}
onChange={(e) => setFormData({ ...formData, slug: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="smart-customer-service"
/>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<textarea
required
rows={4}
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="描述智能体的功能和特点..."
/>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
(Emoji)
</label>
<input
type="text"
value={formData.icon}
onChange={(e) => setFormData({ ...formData, icon: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="🤖"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<select
value={formData.categoryId}
onChange={(e) => setFormData({ ...formData, categoryId: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
>
<option value=""></option>
{categories.map((cat) => (
<option key={cat.id} value={cat.id}>
{cat.name}
</option>
))}
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<select
value={formData.status}
onChange={(e) => setFormData({ ...formData, status: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
>
<option value="active"></option>
<option value="maintenance"></option>
<option value="inactive"></option>
</select>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
()
</label>
<input
type="text"
value={formData.features}
onChange={(e) => setFormData({ ...formData, features: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="智能问答, 知识库查询, 工单提交"
/>
</div>
<div className="flex gap-4">
<button
type="submit"
disabled={loading}
className="bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700 disabled:bg-blue-400"
>
{loading ? "保存中..." : "保存"}
</button>
<button
type="button"
onClick={() => window.history.back()}
className="border border-gray-300 text-gray-700 px-6 py-2 rounded-lg hover:bg-gray-50"
>
</button>
</div>
</form>
)
}
+34
View File
@@ -0,0 +1,34 @@
'use client'
import { useRouter } from "next/navigation"
export default function DeleteButton({ id }: { id: number }) {
const router = useRouter()
const handleDelete = async () => {
if (!confirm("确定要删除这个智能体吗?")) {
return
}
try {
const res = await fetch(`/api/admin/agents/${id}`, {
method: "DELETE",
})
if (res.ok) {
router.refresh()
}
} catch (error) {
alert("删除失败")
}
}
return (
<button
onClick={handleDelete}
className="text-red-600 hover:text-red-700 text-sm"
>
</button>
)
}
+59
View File
@@ -0,0 +1,59 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import { prisma } from "@/app/lib/prisma"
import AgentForm from "../../AgentForm"
export default async function EditAgentPage({
params,
}: {
params: Promise<{ id: string }>
}) {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const { id } = await params
const agent = await prisma.agent.findUnique({
where: { id: parseInt(id) },
})
if (!agent) {
redirect("/admin/agents")
}
const categories = await prisma.category.findMany()
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<Link href="/admin/agents" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
</div>
</nav>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<AgentForm
categories={categories}
agent={{
id: agent.id,
name: agent.name,
slug: agent.slug,
description: agent.description,
icon: agent.icon || "",
categoryId: agent.categoryId || undefined,
features: agent.features,
status: agent.status,
}}
/>
</div>
</main>
</div>
)
}
+34
View File
@@ -0,0 +1,34 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import { prisma } from "@/app/lib/prisma"
import AgentForm from "../AgentForm"
export default async function NewAgentPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const categories = await prisma.category.findMany()
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<Link href="/admin/agents" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
</div>
</nav>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<AgentForm categories={categories} />
</div>
</main>
</div>
)
}
+99
View File
@@ -0,0 +1,99 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import { prisma } from "@//app/lib/prisma"
import Link from "next/link"
import DeleteButton from "./DeleteButton"
export default async function AdminAgentsPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const agents = await prisma.agent.findMany({
include: { category: true },
orderBy: { createdAt: "desc" },
})
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<div className="flex items-center gap-4">
<Link href="/admin" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
<Link href="/admin/agents/new" className="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-blue-700">
</Link>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
<table className="w-full">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">使</th>
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase"></th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{agents.map((agent) => (
<tr key={agent.id} className="hover:bg-gray-50">
<td className="px-6 py-4">
<div className="flex items-center gap-3">
<span className="text-2xl">{agent.icon || "🤖"}</span>
<div>
<div className="font-medium text-gray-900">{agent.name}</div>
<div className="text-sm text-gray-500">{agent.slug}</div>
</div>
</div>
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{agent.category?.name || "-"}
</td>
<td className="px-6 py-4">
<span className={`inline-flex px-2 py-1 text-xs font-medium rounded-full ${
agent.status === "active"
? "bg-green-100 text-green-700"
: "bg-gray-100 text-gray-700"
}`}>
{agent.status === "active" ? "运行中" : agent.status}
</span>
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{agent.usageCount}
</td>
<td className="px-6 py-4 text-right">
<div className="flex items-center justify-end gap-2">
<Link
href={`/admin/agents/${agent.id}/edit`}
className="text-blue-600 hover:text-blue-700 text-sm"
>
</Link>
<DeleteButton id={agent.id} />
</div>
</td>
</tr>
))}
</tbody>
</table>
{agents.length === 0 && (
<div className="text-center py-12 text-gray-500">
<Link href="/admin/agents/new" className="text-blue-600"></Link>
</div>
)}
</div>
</main>
</div>
)
}
+121
View File
@@ -0,0 +1,121 @@
'use client'
import { useState } from "react"
import { useRouter } from "next/navigation"
export default function CategoryForm({
category,
}: {
category?: {
id?: number
name: string
icon?: string
description?: string
}
}) {
const router = useRouter()
const [formData, setFormData] = useState({
name: category?.name || "",
icon: category?.icon || "",
description: category?.description || "",
})
const [loading, setLoading] = useState(false)
const [error, setError] = useState("")
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true)
setError("")
try {
const url = category?.id
? `/api/admin/categories/${category.id}`
: "/api/admin/categories"
const method = category?.id ? "PUT" : "POST"
const res = await fetch(url, {
method,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(formData),
})
if (res.ok) {
router.push("/admin/categories")
} else {
setError("保存失败")
}
} catch (err) {
setError("保存失败,请稍后重试")
} finally {
setLoading(false)
}
}
return (
<form onSubmit={handleSubmit} className="space-y-6">
{error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm">
{error}
</div>
)}
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<input
type="text"
required
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="客服"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
(Emoji)
</label>
<input
type="text"
value={formData.icon}
onChange={(e) => setFormData({ ...formData, icon: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="🤖"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<textarea
rows={4}
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="描述分类的用途和场景..."
/>
</div>
<div className="flex gap-4">
<button
type="submit"
disabled={loading}
className="bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700 disabled:bg-blue-400"
>
{loading ? "保存中..." : "保存"}
</button>
<button
type="button"
onClick={() => window.history.back()}
className="border border-gray-300 text-gray-700 px-6 py-2 rounded-lg hover:bg-gray-50"
>
</button>
</div>
</form>
)
}
@@ -0,0 +1,34 @@
'use client'
import { useRouter } from "next/navigation"
export default function DeleteCategoryButton({ id }: { id: number }) {
const router = useRouter()
const handleDelete = async () => {
if (!confirm("确定要删除这个分类吗?关联的智能体会变为无分类状态。")) {
return
}
try {
const res = await fetch(`/api/admin/categories/${id}`, {
method: "DELETE",
})
if (res.ok) {
router.refresh()
}
} catch (error) {
alert("删除失败")
}
}
return (
<button
onClick={handleDelete}
className="text-red-600 hover:text-red-700 text-sm"
>
</button>
)
}
+52
View File
@@ -0,0 +1,52 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import { prisma } from "@/app/lib/prisma"
import CategoryForm from "../../CategoryForm"
export default async function EditCategoryPage({
params,
}: {
params: Promise<{ id: string }>
}) {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const { id } = await params
const category = await prisma.category.findUnique({
where: { id: parseInt(id) },
})
if (!category) {
redirect("/admin/categories")
}
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<Link href="/admin/categories" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
</div>
</nav>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<CategoryForm
category={{
id: category.id,
name: category.name,
icon: category.icon || "",
description: category.description || "",
}}
/>
</div>
</main>
</div>
)
}
+31
View File
@@ -0,0 +1,31 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import CategoryForm from "../CategoryForm"
export default async function NewCategoryPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<Link href="/admin/categories" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
</div>
</nav>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<CategoryForm />
</div>
</main>
</div>
)
}
+84
View File
@@ -0,0 +1,84 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import { prisma } from "@//app/lib/prisma"
import Link from "next/link"
import DeleteCategoryButton from "./DeleteCategoryButton"
export default async function AdminCategoriesPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const categories = await prisma.category.findMany({
include: { _count: { select: { agents: true } } },
orderBy: { createdAt: "desc" },
})
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<div className="flex items-center gap-4">
<Link href="/admin" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
<Link href="/admin/categories/new" className="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-blue-700">
</Link>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
<table className="w-full">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase"></th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{categories.map((cat) => (
<tr key={cat.id} className="hover:bg-gray-50">
<td className="px-6 py-4">
<div className="font-medium text-gray-900">{cat.name}</div>
<div className="text-sm text-gray-500">{cat.description}</div>
</td>
<td className="px-6 py-4 text-2xl">
{cat.icon || "-"}
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{cat._count.agents}
</td>
<td className="px-6 py-4 text-right">
<div className="flex items-center justify-end gap-2">
<Link
href={`/admin/categories/${cat.id}/edit`}
className="text-blue-600 hover:text-blue-700 text-sm"
>
</Link>
<DeleteCategoryButton id={cat.id} />
</div>
</td>
</tr>
))}
</tbody>
</table>
{categories.length === 0 && (
<div className="text-center py-12 text-gray-500">
<Link href="/admin/categories/new" className="text-blue-600"></Link>
</div>
)}
</div>
</main>
</div>
)
}
+101
View File
@@ -0,0 +1,101 @@
'use client'
import { signIn } from "next-auth/react"
import { useState } from "react"
import { useRouter } from "next/navigation"
export default function LoginPage() {
const [username, setUsername] = useState("")
const [password, setPassword] = useState("")
const [error, setError] = useState("")
const [loading, setLoading] = useState(false)
const router = useRouter()
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true)
setError("")
try {
const result = await signIn("credentials", {
username,
password,
redirect: false,
})
if (result?.error) {
setError("用户名或密码错误")
} else {
router.push("/admin")
}
} catch (err) {
setError("登录失败,请稍后重试")
} finally {
setLoading(false)
}
}
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50">
<div className="max-w-md w-full space-y-8 p-8 bg-white rounded-2xl shadow-lg">
<div className="text-center">
<div className="w-16 h-16 bg-blue-600 rounded-2xl flex items-center justify-center mx-auto mb-4">
<span className="text-white font-bold text-2xl">A</span>
</div>
<h2 className="text-3xl font-bold text-gray-900"></h2>
<p className="mt-2 text-gray-600">广</p>
</div>
<form className="mt-8 space-y-6" onSubmit={handleSubmit}>
{error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm">
{error}
</div>
)}
<div>
<label htmlFor="username" className="block text-sm font-medium text-gray-700 mb-2">
</label>
<input
id="username"
type="text"
required
value={username}
onChange={(e) => setUsername(e.target.value)}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="请输入用户名"
/>
</div>
<div>
<label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-2">
</label>
<input
id="password"
type="password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="请输入密码"
/>
</div>
<button
type="submit"
disabled={loading}
className="w-full bg-blue-600 text-white py-3 rounded-lg font-medium hover:bg-blue-700 transition disabled:bg-blue-400"
>
{loading ? "登录中..." : "登录"}
</button>
</form>
<div className="text-center text-sm text-gray-500">
默认账号: admin / admin123
</div>
</div>
</div>
)
}
+34
View File
@@ -0,0 +1,34 @@
'use client'
import { useRouter } from "next/navigation"
export default function DeleteNewsButton({ id }: { id: number }) {
const router = useRouter()
const handleDelete = async () => {
if (!confirm("确定要删除这条新闻吗?")) {
return
}
try {
const res = await fetch(`/api/admin/news/${id}`, {
method: "DELETE",
})
if (res.ok) {
router.refresh()
}
} catch (error) {
alert("删除失败")
}
}
return (
<button
onClick={handleDelete}
className="text-red-600 hover:text-red-700 text-sm"
>
</button>
)
}
+142
View File
@@ -0,0 +1,142 @@
'use client'
import { useState } from "react"
import { useRouter } from "next/navigation"
export default function NewsForm({
news,
}: {
news?: {
id?: number
title: string
content: string
type?: string
published?: boolean
}
}) {
const router = useRouter()
const [formData, setFormData] = useState({
title: news?.title || "",
content: news?.content || "",
type: news?.type || "news",
published: news?.published || false,
})
const [loading, setLoading] = useState(false)
const [error, setError] = useState("")
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true)
setError("")
try {
const url = news?.id
? `/api/admin/news/${news.id}`
: "/api/admin/news"
const method = news?.id ? "PUT" : "POST"
const res = await fetch(url, {
method,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(formData),
})
if (res.ok) {
router.push("/admin/news")
} else {
setError("保存失败")
}
} catch (err) {
setError("保存失败,请稍后重试")
} finally {
setLoading(false)
}
}
return (
<form onSubmit={handleSubmit} className="space-y-6">
{error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm">
{error}
</div>
)}
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<input
type="text"
required
value={formData.title}
onChange={(e) => setFormData({ ...formData, title: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="输入新闻标题"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<textarea
required
rows={6}
value={formData.content}
onChange={(e) => setFormData({ ...formData, content: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
placeholder="输入新闻内容..."
/>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<select
value={formData.type}
onChange={(e) => setFormData({ ...formData, type: e.target.value })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
>
<option value="news"></option>
<option value="industry"></option>
<option value="cooperation"></option>
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
</label>
<select
value={formData.published ? "true" : "false"}
onChange={(e) => setFormData({ ...formData, published: e.target.value === "true" })}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
>
<option value="true"></option>
<option value="false">稿</option>
</select>
</div>
</div>
<div className="flex gap-4">
<button
type="submit"
disabled={loading}
className="bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700 disabled:bg-blue-400"
>
{loading ? "保存中..." : "保存"}
</button>
<button
type="button"
onClick={() => window.history.back()}
className="border border-gray-300 text-gray-700 px-6 py-2 rounded-lg hover:bg-gray-50"
>
</button>
</div>
</form>
)
}
+53
View File
@@ -0,0 +1,53 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import { prisma } from "@/app/lib/prisma"
import NewsForm from "../../NewsForm"
export default async function EditNewsPage({
params,
}: {
params: Promise<{ id: string }>
}) {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const { id } = await params
const news = await prisma.news.findUnique({
where: { id: parseInt(id) },
})
if (!news) {
redirect("/admin/news")
}
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<Link href="/admin/news" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
</div>
</nav>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<NewsForm
news={{
id: news.id,
title: news.title,
content: news.content,
type: news.type,
published: news.published,
}}
/>
</div>
</main>
</div>
)
}
+31
View File
@@ -0,0 +1,31 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import NewsForm from "../NewsForm"
export default async function NewNewsPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<Link href="/admin/news" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
</div>
</nav>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<NewsForm />
</div>
</main>
</div>
)
}
+92
View File
@@ -0,0 +1,92 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import { prisma } from "@//app/lib/prisma"
import Link from "next/link"
import DeleteNewsButton from "./DeleteNewsButton"
export default async function AdminNewsPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const news = await prisma.news.findMany({
orderBy: { createdAt: "desc" },
})
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<div className="flex items-center gap-4">
<Link href="/admin" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
<Link href="/admin/news/new" className="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-blue-700">
</Link>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
<table className="w-full">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase"></th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{news.map((item) => (
<tr key={item.id} className="hover:bg-gray-50">
<td className="px-6 py-4">
<div className="font-medium text-gray-900">{item.title}</div>
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{item.type}
</td>
<td className="px-6 py-4">
<span className={`inline-flex px-2 py-1 text-xs font-medium rounded-full ${
item.published
? "bg-green-100 text-green-700"
: "bg-yellow-100 text-yellow-700"
}`}>
{item.published ? "已发布" : "草稿"}
</span>
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{new Date(item.createdAt).toLocaleDateString("zh-CN")}
</td>
<td className="px-6 py-4 text-right">
<div className="flex items-center justify-end gap-2">
<Link
href={`/admin/news/${item.id}/edit`}
className="text-blue-600 hover:text-blue-700 text-sm"
>
</Link>
<DeleteNewsButton id={item.id} />
</div>
</td>
</tr>
))}
</tbody>
</table>
{news.length === 0 && (
<div className="text-center py-12 text-gray-500">
<Link href="/admin/news/new" className="text-blue-600"></Link>
</div>
)}
</div>
</main>
</div>
)
}
+114
View File
@@ -0,0 +1,114 @@
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import Link from "next/link"
import { prisma } from "@//app/lib/prisma"
export default async function AdminDashboard() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const agentsCount = await prisma.agent.count()
const newsCount = await prisma.news.count()
const categoriesCount = await prisma.category.count()
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<div className="flex items-center gap-4">
<span className="text-sm text-gray-600">{session.user?.name}</span>
<Link
href="/api/auth/signout"
className="text-sm text-red-600 hover:text-red-700"
>
退
</Link>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-6 py-8">
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200">
<div className="flex items-center gap-4 mb-4">
<div className="w-12 h-12 bg-blue-100 rounded-xl flex items-center justify-center text-2xl">
🤖
</div>
<div>
<p className="text-sm text-gray-500"></p>
<p className="text-2xl font-bold text-gray-900">{agentsCount}</p>
</div>
</div>
<Link href="/admin/agents" className="text-blue-600 text-sm hover:underline">
</Link>
</div>
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200">
<div className="flex items-center gap-4 mb-4">
<div className="w-12 h-12 bg-green-100 rounded-xl flex items-center justify-center text-2xl">
📰
</div>
<div>
<p className="text-sm text-gray-500"></p>
<p className="text-2xl font-bold text-gray-900">{newsCount}</p>
</div>
</div>
<Link href="/admin/news" className="text-blue-600 text-sm hover:underline">
</Link>
</div>
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200">
<div className="flex items-center gap-4 mb-4">
<div className="w-12 h-12 bg-purple-100 rounded-xl flex items-center justify-center text-2xl">
📂
</div>
<div>
<p className="text-sm text-gray-500"></p>
<p className="text-2xl font-bold text-gray-900">{categoriesCount}</p>
</div>
</div>
<Link href="/admin/categories" className="text-blue-600 text-sm hover:underline">
</Link>
</div>
</div>
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
<h2 className="text-lg font-semibold text-gray-900 mb-4"></h2>
<div className="flex flex-wrap gap-4">
<Link
href="/admin/agents/new"
className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition"
>
</Link>
<Link
href="/admin/news/new"
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition"
>
</Link>
<Link
href="/admin/categories/new"
className="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition"
>
</Link>
<Link
href="/"
className="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition"
>
</Link>
</div>
</div>
</main>
</div>
)
}