feat: 接入后台咨询记录管理
This commit is contained in:
1 parent
c393a5231e
commit
3dcc31d717
1 file changed
+14
-2
+14
-2
@@ -1,7 +1,7 @@
|
||||
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, Table, Tag, Popconfirm, Modal } from "antd";
|
||||
import { App, Button, Card, Form, Input, Layout, Menu, Select, Space, Typography, message, Table, Tag, Popconfirm, Modal, Badge } from "antd";
|
||||
import { ApiClient } from "@personal-brand/api-client";
|
||||
import type { BrandProfile, PublicService, TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
||||
import "antd/dist/reset.css";
|
||||
@@ -44,7 +44,19 @@ function ServicesPage() {
|
||||
return <Card title="服务与合作" extra={<Button type="primary" onClick={() => open()}>新增服务</Button>}><Table rowKey="id" loading={query.isLoading} dataSource={query.data ?? []} columns={[{ title: "服务名称", dataIndex: "name" }, { title: "分类", dataIndex: "categoryKey", render: (value) => <Tag>{value}</Tag> }, { title: "价格展示", dataIndex: "priceText" }, { title: "状态", dataIndex: "isEnabled", render: (value) => value ? "已上架" : "已下架" }, { title: "操作", render: (_: unknown, item: PublicService) => <Space><Button size="small" onClick={() => open(item)}>编辑</Button><Button size="small" onClick={() => remove.mutate(item)}>{item.isEnabled ? "下架" : "上架"}</Button></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)}><Form.Item name="name" label="服务名称" rules={[{ required: true }]}><Input /></Form.Item><Form.Item name="description" label="服务描述" rules={[{ required: true }]}><Input.TextArea rows={4} /></Form.Item><Form.Item name="categoryKey" label="服务分类" rules={[{ required: true }]}><Input placeholder="例如:standard、consulting、food-package" /></Form.Item><Form.Item name="priceText" label="价格展示"><Input placeholder="例如:¥ 1,500 起 / 沟通报价" /></Form.Item><Form.Item name="sortOrder" label="排序"><Input type="number" /></Form.Item><Form.Item name="bookingEnabled" label="允许提交需求"><Select options={[{ value: true, label: "允许" }, { value: false, label: "暂不接受" }]} /></Form.Item><Form.Item name="isEnabled" 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 /> : page === "services" ? <ServicesPage /> : <Card title="即将开放">该模块正在接入通用配置接口。</Card>}</Layout.Content></Layout></Layout>; }
|
||||
const bookingStatusOptions = ["received", "contacting", "confirmed", "completed", "cancelled"] as const;
|
||||
const bookingStatusLabels: Record<string, string> = { received: "待处理", contacting: "沟通中", confirmed: "已确认", completed: "已完成", cancelled: "已取消" };
|
||||
|
||||
function InquiriesPage() {
|
||||
const client = api(); const queryClientHook = useQueryClient();
|
||||
const [status, setStatus] = useState<string | undefined>();
|
||||
const query = useQuery({ queryKey: ["admin-bookings", status], queryFn: () => client.listAdminBookings(status ? { status: status as never } : {}) });
|
||||
const update = useMutation({ mutationFn: ({ id, nextStatus, note }: { id: string; nextStatus: never; note?: string }) => client.updateAdminBookingStatus(id, nextStatus, note), onSuccess: () => { message.success("咨询状态已更新"); void queryClientHook.invalidateQueries({ queryKey: ["admin-bookings"] }); } });
|
||||
const markRead = useMutation({ mutationFn: (id: string) => client.markAdminBookingRead(id), onSuccess: () => void queryClientHook.invalidateQueries({ queryKey: ["admin-bookings"] }) });
|
||||
return <Card title="咨询记录" extra={<Space><Select allowClear placeholder="全部状态" style={{ width: 130 }} value={status} onChange={setStatus} options={bookingStatusOptions.map((value) => ({ value, label: bookingStatusLabels[value] }))} /><Badge count={query.data?.filter((item) => !(item as AdminBooking & { isRead?: boolean }).isRead).length ?? 0} showZero /></Space>}><Table rowKey="id" loading={query.isLoading} dataSource={query.data ?? []} columns={[{ title: "编号", dataIndex: "bookingNo" }, { title: "类型", render: (_: unknown, item: AdminBooking & { requestType?: string }) => item.requestType === "inquiry" ? "品牌咨询" : item.requestType === "private_chef" ? "定制服务" : "服务预约" }, { title: "联系人", dataIndex: "customerName" }, { title: "提交时间", dataIndex: "createdAt", render: (value: string) => new Date(value).toLocaleString("zh-CN") }, { title: "状态", dataIndex: "status", render: (value: string) => <Tag color={value === "cancelled" ? "default" : "processing"}>{bookingStatusLabels[value] ?? value}</Tag> }, { title: "操作", render: (_: unknown, item: AdminBooking) => <Space><Select size="small" value={item.status} onChange={(nextStatus) => update.mutate({ id: item.id, nextStatus: nextStatus as never })} options={bookingStatusOptions.map((value) => ({ value, label: bookingStatusLabels[value] }))} /><Button size="small" onClick={() => markRead.mutate(item.id)}>标记已读</Button></Space> }]} /></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 /> : page === "services" ? <ServicesPage /> : <InquiriesPage />}</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>);
|
||||
Reference in new issue
Block a user