'use client'; import { useEffect, useState } from 'react'; import { Building2, Phone, Mail, MapPin, ShieldCheck, FileText, Loader2, } from 'lucide-react'; import { AdminHeader } from '@/components/admin/AdminHeader'; 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 } from '@/components/ui/card'; import { ImageUpload } from '@/components/admin/ImageUpload'; import { RichEditor } from '@/components/admin/RichEditor'; import { adminApi } from '@/lib/admin-services'; import type { SiteConfig } from '@/lib/types'; interface FormState { siteName: string; logo: string; tel: string; address: string; email: string; copyright: string; icp: string; aboutTitle: string; aboutContent: string; } const DEFAULT: FormState = { siteName: '', logo: '', tel: '', address: '', email: '', copyright: '', icp: '', aboutTitle: '', aboutContent: '', }; function SectionHead({ icon, title, desc, }: { icon: React.ReactNode; title: string; desc: string; }) { return (
{icon}
{title}
{desc}
); } function Field({ label, required, children, }: { label: string; required?: boolean; children: React.ReactNode; }) { return (
{children}
); } export default function SiteConfigAdminPage() { const [hydrated, setHydrated] = useState(false); const [form, setForm] = useState(DEFAULT); const [saving, setSaving] = useState(false); const [loaded, setLoaded] = useState(false); useEffect(() => setHydrated(true), []); useEffect(() => { if (!hydrated) return; adminApi .siteConfigGet() .then((c: SiteConfig) => { setForm({ siteName: c.siteName, logo: c.logo, tel: c.tel, address: c.address, email: c.email, copyright: c.copyright, icp: c.icp, aboutTitle: c.aboutTitle, aboutContent: c.aboutContent ?? '', }); setLoaded(true); }) .catch((e) => alert((e as Error).message)); }, [hydrated]); const onSave = async () => { if (!form.siteName) { alert('请填写网站名称'); return; } setSaving(true); try { await adminApi.siteConfigUpdate(form); alert('保存成功'); } catch (e) { alert((e as Error).message); } finally { setSaving(false); } }; if (!loaded) { return (
加载中…
); } const cardCls = 'border-slate-200/70 bg-white shadow-[0_1px_3px_rgba(15,23,42,0.04),0_8px_24px_-12px_rgba(79,70,229,0.12)]'; return (
{saving ? ( <> 保存中… ) : ( '保存配置' )} } />
{/* ===== 品牌标识 ===== */} } title="品牌标识" desc="站点名称与 Logo" />
setForm({ ...form, siteName: e.target.value }) } placeholder="如:智管物业" /> setForm({ ...form, logo: url })} hint="透明背景 PNG 最佳,建议 200x48" />
{/* ===== 联系方式 ===== */} } title="联系方式" desc="客户咨询与对外联络" />
setForm({ ...form, tel: e.target.value }) } placeholder="400-000-0000" />
setForm({ ...form, email: e.target.value }) } placeholder="business@example.com" />
setForm({ ...form, address: e.target.value }) } placeholder="省市区详细地址" />
{/* ===== 版权与备案 ===== */} } title="版权与备案" desc="底部声明与合规信息" />