feat: 接入后台信任内容管理页面

This commit is contained in:
que01 committed 2026-09-19 17:50:20 +08:00
1 parent f29e64724d
commit ad70eef8eb
2 files changed
+18 -3

No files matched your search

+12 -3
View File
@@ -1,9 +1,9 @@
import React, { useState } from "react";
import { createRoot } from "react-dom/client";
import { QueryClient, QueryClientProvider, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { App, Button, Card, Form, Input, Layout, Menu, Select, Space, Typography, message } from "antd";
import { App, Button, Card, Form, Input, Layout, Menu, Select, Space, Typography, message, Table, Tag, Popconfirm, Modal } from "antd";
import { ApiClient } from "@personal-brand/api-client";
import type { BrandProfile } from "@personal-brand/api-client";
import type { BrandProfile, TrustContent, TrustContentInput } from "@personal-brand/api-client";
import "antd/dist/reset.css";
const apiBaseUrl = "http://localhost:3001";
@@ -26,7 +26,16 @@ function BrandPage() {
return <Card title="品牌信任配置"><Form form={form} layout="vertical" initialValues={brand.data} onFinish={(values) => save.mutate(values)}><Form.Item name="templateKey" label="行业模板"><Select options={[{ value: "personal", label: "个人品牌" }, { value: "food", label: "餐饮模板" }]} /></Form.Item><Form.Item name="name" label="品牌名称" rules={[{ required: true }]}><Input /></Form.Item><Form.Item name="tagline" label="一句话定位"><Input /></Form.Item><Form.Item name="description" label="品牌简介"><Input.TextArea rows={5} /></Form.Item><Form.Item name="hours" label="服务时间"><Input /></Form.Item><Form.Item name="address" label="所在位置"><Input /></Form.Item><Form.Item name="contactPhone" label="联系电话"><Input /></Form.Item><Form.Item name="contactWechat" label="微信号"><Input /></Form.Item><Button type="primary" htmlType="submit" loading={save.isPending}>保存配置</Button></Form></Card>;
}
function Dashboard() { const [page, setPage] = useState("brand"); return <Layout style={{ minHeight: "100vh" }}><Layout.Sider><Typography.Title level={4} style={{ color: "white", padding: 20 }}>个人品牌</Typography.Title><Menu theme="dark" selectedKeys={[page]} onClick={({ key }) => setPage(key)} items={[{ key: "brand", label: "品牌信任" }, { key: "trust", label: "信任内容" }, { key: "services", label: "服务与合作" }, { key: "inquiries", label: "咨询记录" }]} /></Layout.Sider><Layout><Layout.Header style={{ background: "white" }}><Space>品牌管理后台</Space></Layout.Header><Layout.Content style={{ padding: 24 }}>{page === "brand" ? <BrandPage /> : <Card title="即将开放">该模块正在接入通用配置接口。</Card>}</Layout.Content></Layout></Layout>; }
function TrustContentPage() {
const client = api(); const queryClientHook = useQueryClient(); const [editing, setEditing] = useState<TrustContent | null>(null); const [modalOpen, setModalOpen] = useState(false); const [form] = Form.useForm<TrustContentInput>();
const query = useQuery({ queryKey: ["trust-content"], queryFn: () => client.listAdminTrustContent() });
const save = useMutation({ mutationFn: (values: TrustContentInput) => editing ? client.updateAdminTrustContent(editing.id, values) : client.createAdminTrustContent(values), onSuccess: () => { message.success("信任内容已保存"); setEditing(null); form.resetFields(); void queryClientHook.invalidateQueries({ queryKey: ["trust-content"] }); } });
const remove = useMutation({ mutationFn: (id: string) => client.deleteAdminTrustContent(id), onSuccess: () => { message.success("内容已删除"); void queryClientHook.invalidateQueries({ queryKey: ["trust-content"] }); } });
function open(item?: TrustContent) { setEditing(item ?? null); setModalOpen(true); form.setFieldsValue(item ? { type: item.type, title: item.title, summary: item.summary ?? undefined, content: item.content, sortOrder: item.sortOrder, isPublished: item.isPublished } : { type: "profile", isPublished: true }); }
return <Card title="信任内容" extra={<Button type="primary" onClick={() => open()}>新增内容</Button>}><Table rowKey="id" loading={query.isLoading} dataSource={query.data ?? []} columns={[{ title: "类型", dataIndex: "type", render: (value) => <Tag>{value}</Tag> }, { title: "标题", dataIndex: "title" }, { title: "状态", dataIndex: "isPublished", render: (value) => value ? "已发布" : "草稿" }, { title: "操作", render: (_: unknown, item: TrustContent) => <Space><Button size="small" onClick={() => open(item)}>编辑</Button><Popconfirm title="确认删除?" onConfirm={() => remove.mutate(item.id)}><Button size="small" danger>删除</Button></Popconfirm></Space> }]} /> <Modal open={modalOpen} title={editing ? "编辑信任内容" : "新增信任内容"} onCancel={() => { setModalOpen(false); setEditing(null); form.resetFields(); }} onOk={() => form.submit()} confirmLoading={save.isPending}><Form form={form} layout="vertical" onFinish={(values) => { save.mutate(values); setModalOpen(false); }}><Form.Item name="type" label="内容类型" rules={[{ required: true }]}><Select options={["profile", "experience", "credential", "portfolio", "process", "testimonial"].map((value) => ({ value, label: value }))} /></Form.Item><Form.Item name="title" label="标题" rules={[{ required: true }]}><Input /></Form.Item><Form.Item name="summary" label="摘要"><Input /></Form.Item><Form.Item name="content" label="内容" rules={[{ required: true }]}><Input.TextArea rows={7} /></Form.Item><Form.Item name="isPublished" label="发布状态"><Select options={[{ value: true, label: "已发布" }, { value: false, label: "草稿" }]} /></Form.Item></Form></Modal></Card>;
}
function Dashboard() { const [page, setPage] = useState("brand"); return <Layout style={{ minHeight: "100vh" }}><Layout.Sider><Typography.Title level={4} style={{ color: "white", padding: 20 }}>个人品牌</Typography.Title><Menu theme="dark" selectedKeys={[page]} onClick={({ key }) => setPage(key)} items={[{ key: "brand", label: "品牌信任" }, { key: "trust", label: "信任内容" }, { key: "services", label: "服务与合作" }, { key: "inquiries", label: "咨询记录" }]} /></Layout.Sider><Layout><Layout.Header style={{ background: "white" }}><Space>品牌管理后台</Space></Layout.Header><Layout.Content style={{ padding: 24 }}>{page === "brand" ? <BrandPage /> : page === "trust" ? <TrustContentPage /> : <Card title="即将开放">该模块正在接入通用配置接口。</Card>}</Layout.Content></Layout></Layout>; }
function Root() { const [loggedIn, setLoggedIn] = useState(Boolean(localStorage.getItem("adminToken"))); return loggedIn ? <Dashboard /> : <Login onLogin={() => setLoggedIn(true)} />; }
createRoot(document.getElementById("app")!).render(<React.StrictMode><QueryClientProvider client={queryClient}><App><Root /></App></QueryClientProvider></React.StrictMode>);