From 46c3e5504e9e27222a5dfc20c2151eca57cd8bd1 Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 20 Sep 2026 09:31:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=93=81=E7=89=8C=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/features/workspace/WorkspacePage.tsx | 198 ++++++++++++++++++ apps/admin/src/main.tsx | 7 + packages/api-client/src/index.ts | 47 +++++ 3 files changed, 252 insertions(+) create mode 100644 apps/admin/src/features/workspace/WorkspacePage.tsx diff --git a/apps/admin/src/features/workspace/WorkspacePage.tsx b/apps/admin/src/features/workspace/WorkspacePage.tsx new file mode 100644 index 0000000..78ddcfc --- /dev/null +++ b/apps/admin/src/features/workspace/WorkspacePage.tsx @@ -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 }) => + client.updateAdminModule(id, body), + onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }), + }); + const createField = useMutation({ + mutationFn: (values: Omit) => + 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 ; + if (query.isError || !query.data) return 工作空间加载失败,请刷新重试。; + const { modules, fields, installations } = query.data; + return ( + + + + + + } + > + {installations.length ? `已安装 ${installations.length} 个模板` : "尚未安装模板"} + + + {value} }, + { title: "来源", dataIndex: "source" }, + { + title: "状态", + dataIndex: "isEnabled", + render: (value, item: BrandModule) => ( + + updateModule.mutate({ + id: item.id, + body: { sortOrder: Number(event.target.value) }, + }) + } + /> + ), + }, + ]} + /> + + setFieldOpen(true)}> + 新增字段 + + } + > +
item.source === "custom")} + columns={[ + { title: "字段", dataIndex: "label" }, + { title: "Key", dataIndex: "key" }, + { title: "作用域", dataIndex: "scope" }, + { title: "类型", dataIndex: "type" }, + { + title: "操作", + render: (_: unknown, item: BrandFieldDefinition) => ( + + ), + }, + ]} + /> + + { + setFieldOpen(false); + form.resetFields(); + }} + onOk={() => form.submit()} + confirmLoading={createField.isPending} + > +
+ createField.mutate({ + ...values, + required: values.required ?? false, + isVisible: true, + sortOrder: 99, + }) + } + > + + + + + + + + + + +
+ + ); +} diff --git a/apps/admin/src/main.tsx b/apps/admin/src/main.tsx index bbe694d..3120514 100644 --- a/apps/admin/src/main.tsx +++ b/apps/admin/src/main.tsx @@ -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 }) { }> } /> + } /> } /> } /> } /> diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index aaa320c..9977f4e 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -124,6 +124,26 @@ export interface OfferingCta { label: string; config?: Record; } +export interface BrandModule { + id: string; + type: string; + title: string; + isEnabled: boolean; + sortOrder: number; + source: string; + config?: Record | null; +} +export interface BrandFieldDefinition { + id: string; + scope: string; + key: string; + label: string; + type: string; + required: boolean; + isVisible: boolean; + sortOrder: number; + source: string; +} export interface Offering { id: string; brandId?: string; @@ -254,6 +274,33 @@ export class ApiClient { getPublicOffering(id: string): Promise { return this.request(`/public/offerings/${encodeURIComponent(id)}`); } + getAdminWorkspace(): Promise<{ + brand: BrandProfile; + installations: unknown[]; + modules: BrandModule[]; + fields: BrandFieldDefinition[]; + offerings: Offering[]; + forms: unknown[]; + }> { + return this.request("/admin/workspace"); + } + installAdminTemplate(templateKey: "personal" | "food"): Promise { + return this.request("/admin/workspace/install", { method: "POST", body: { templateKey } }); + } + updateAdminModule(id: string, body: Partial): Promise { + return this.request(`/admin/workspace/modules/${encodeURIComponent(id)}`, { + method: "PATCH", + body, + }); + } + createAdminField( + body: Omit, + ): Promise { + return this.request("/admin/workspace/fields", { method: "POST", body }); + } + deleteAdminField(id: string): Promise<{ deleted: boolean }> { + return this.request(`/admin/workspace/fields/${encodeURIComponent(id)}`, { method: "DELETE" }); + } listAdminOfferings(): Promise { return this.request("/admin/workspace/offerings"); }