feat: 增加后台品牌工作空间配置页面
This commit is contained in:
1 parent
6e1aca3e27
commit
46c3e5504e
3 files changed
+252
No files matched your search
@@ -0,0 +1,198 @@
|
||||
import { Button, Card, Form, Input, Modal, Select, Space, Table, Tag, message } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import type { BrandFieldDefinition, BrandModule } from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
|
||||
export function WorkspacePage() {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const [fieldOpen, setFieldOpen] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const query = useQuery({
|
||||
queryKey: ["admin-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const install = useMutation({
|
||||
mutationFn: (key: "personal" | "food") => client.installAdminTemplate(key),
|
||||
onSuccess: () => {
|
||||
message.success("模板已安装");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
},
|
||||
});
|
||||
const updateModule = useMutation({
|
||||
mutationFn: ({ id, body }: { id: string; body: Partial<BrandModule> }) =>
|
||||
client.updateAdminModule(id, body),
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }),
|
||||
});
|
||||
const createField = useMutation({
|
||||
mutationFn: (values: Omit<BrandFieldDefinition, "id" | "source">) =>
|
||||
client.createAdminField(values),
|
||||
onSuccess: () => {
|
||||
message.success("字段已创建");
|
||||
setFieldOpen(false);
|
||||
form.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
},
|
||||
});
|
||||
const removeField = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminField(id),
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }),
|
||||
});
|
||||
if (query.isLoading) return <Card loading />;
|
||||
if (query.isError || !query.data) return <Card>工作空间加载失败,请刷新重试。</Card>;
|
||||
const { modules, fields, installations } = query.data;
|
||||
return (
|
||||
<Space direction="vertical" size="large" style={{ width: "100%" }}>
|
||||
<Card
|
||||
title="模板安装"
|
||||
extra={
|
||||
<Space>
|
||||
<Button onClick={() => install.mutate("personal")} loading={install.isPending}>
|
||||
安装个人品牌模板
|
||||
</Button>
|
||||
<Button onClick={() => install.mutate("food")} loading={install.isPending}>
|
||||
安装餐饮模板
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Tag>{installations.length ? `已安装 ${installations.length} 个模板` : "尚未安装模板"}</Tag>
|
||||
</Card>
|
||||
<Card title="页面模块">
|
||||
<Table
|
||||
rowKey="id"
|
||||
dataSource={modules}
|
||||
columns={[
|
||||
{ title: "模块", dataIndex: "title" },
|
||||
{ title: "类型", dataIndex: "type", render: (value) => <Tag>{value}</Tag> },
|
||||
{ title: "来源", dataIndex: "source" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isEnabled",
|
||||
render: (value, item: BrandModule) => (
|
||||
<Select
|
||||
size="small"
|
||||
value={value}
|
||||
onChange={(next) =>
|
||||
updateModule.mutate({ id: item.id, body: { isEnabled: next } })
|
||||
}
|
||||
options={[
|
||||
{ value: true, label: "启用" },
|
||||
{ value: false, label: "停用" },
|
||||
]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "排序",
|
||||
dataIndex: "sortOrder",
|
||||
render: (value, item: BrandModule) => (
|
||||
<Input
|
||||
size="small"
|
||||
type="number"
|
||||
defaultValue={value}
|
||||
onBlur={(event) =>
|
||||
updateModule.mutate({
|
||||
id: item.id,
|
||||
body: { sortOrder: Number(event.target.value) },
|
||||
})
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
<Card
|
||||
title="自定义字段"
|
||||
extra={
|
||||
<Button type="primary" onClick={() => setFieldOpen(true)}>
|
||||
新增字段
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
dataSource={fields.filter((item) => item.source === "custom")}
|
||||
columns={[
|
||||
{ title: "字段", dataIndex: "label" },
|
||||
{ title: "Key", dataIndex: "key" },
|
||||
{ title: "作用域", dataIndex: "scope" },
|
||||
{ title: "类型", dataIndex: "type" },
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: BrandFieldDefinition) => (
|
||||
<Button danger size="small" onClick={() => removeField.mutate(item.id)}>
|
||||
删除
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
<Modal
|
||||
open={fieldOpen}
|
||||
title="新增自定义字段"
|
||||
onCancel={() => {
|
||||
setFieldOpen(false);
|
||||
form.resetFields();
|
||||
}}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={createField.isPending}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={(values) =>
|
||||
createField.mutate({
|
||||
...values,
|
||||
required: values.required ?? false,
|
||||
isVisible: true,
|
||||
sortOrder: 99,
|
||||
})
|
||||
}
|
||||
>
|
||||
<Form.Item name="scope" label="作用域" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={[
|
||||
{ value: "profile", label: "品牌资料" },
|
||||
{ value: "service", label: "服务" },
|
||||
{ value: "inquiry", label: "咨询表单" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="key" label="字段 Key" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="label" label="显示名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="type" label="字段类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={[
|
||||
"text",
|
||||
"textarea",
|
||||
"number",
|
||||
"date",
|
||||
"select",
|
||||
"multi-select",
|
||||
"image",
|
||||
"url",
|
||||
"phone",
|
||||
].map((value) => ({ value, label: value }))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="required" label="是否必填">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "是" },
|
||||
{ value: false, label: "否" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
@@ -44,6 +44,11 @@ const FeatureServicesPage = React.lazy(() =>
|
||||
const FeatureBrandPage = React.lazy(() =>
|
||||
import("./features/brand/BrandPage.js").then((module) => ({ default: module.BrandPage })),
|
||||
);
|
||||
const FeatureWorkspacePage = React.lazy(() =>
|
||||
import("./features/workspace/WorkspacePage.js").then((module) => ({
|
||||
default: module.WorkspacePage,
|
||||
})),
|
||||
);
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
BrandProfile,
|
||||
@@ -94,6 +99,7 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
const page = location.pathname.split("/")[2] || "brand";
|
||||
const items = [
|
||||
{ key: "brand", label: "品牌信任" },
|
||||
{ key: "workspace", label: "工作空间" },
|
||||
{ key: "trust", label: "信任内容" },
|
||||
{ key: "services", label: "服务与合作" },
|
||||
{ key: "inquiries", label: "咨询记录" },
|
||||
@@ -129,6 +135,7 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
<Suspense fallback={<Card loading />}>
|
||||
<Routes>
|
||||
<Route path="/admin/brand" element={<FeatureBrandPage />} />
|
||||
<Route path="/admin/workspace" element={<FeatureWorkspacePage />} />
|
||||
<Route path="/admin/trust" element={<FeatureTrustContentPage />} />
|
||||
<Route path="/admin/services" element={<FeatureServicesPage />} />
|
||||
<Route path="/admin/inquiries" element={<FeatureInquiriesPage />} />
|
||||
|
||||
Reference in new issue
Block a user