From 896f3240f99b0c9394226f285f873a61d4c9d93a Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 14 Oct 2026 13:55:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8B=86=E5=88=86=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=B2=BB=E7=90=86=E4=B8=8E=E5=92=A8=E8=AF=A2=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /admin/workspace 收敛为「咨询表单与字段」,只做咨询入口表单与高级自定义字段 - 行业模板版本升级/回滚迁入「配置与发布 → 内容发布 → 选择表达方式」 - 移除行业模板安装入口、视觉模板历史与模板组合预览等不可达 UI - 表单下拉的业务选项改用本品牌后台数据,避免公开接口回退默认品牌导致跨品牌串数据 - 侧栏导航与设计文档同步 --- apps/admin/design.md | 27 +- .../capabilities/CapabilitiesPage.tsx | 6 +- .../features/publication/PublicationPage.tsx | 73 ++- .../src/features/workspace/WorkspacePage.tsx | 541 ++++-------------- .../features/workspace/workspace-mutations.ts | 93 +-- .../features/workspace/workspace-queries.ts | 21 + .../features/workspace/workspace-templates.ts | 18 - apps/admin/src/main.tsx | 8 +- packages/api-client/src/resources/template.ts | 2 +- 9 files changed, 206 insertions(+), 583 deletions(-) create mode 100644 apps/admin/src/features/workspace/workspace-queries.ts delete mode 100644 apps/admin/src/features/workspace/workspace-templates.ts diff --git a/apps/admin/design.md b/apps/admin/design.md index 54844f4..d27f912 100644 --- a/apps/admin/design.md +++ b/apps/admin/design.md @@ -262,6 +262,7 @@ - 空状态统一用 `EmptyState`(`components/EmptyState.tsx`);表格内用 `compact` 变体,整块区域用默认变体。禁止再使用 antd 默认 `Empty` 插画。 - 列表 / 表格加载统一用 `TableSkeleton`、`ListSkeleton`(`components/TableSkeleton.tsx`)替换内容区,不使用 antd `Table` 的转圈遮罩;卡片级加载用 `LoadingStack`。 - 卡片内的写操作只在「有未保存修改」时使用主按钮,其余状态用次要按钮并禁用,同时用 `StatusTag` 标明修改状态。 +- 发布准备度、内容检查这类清单,条目文案只描述「检查什么」(中性名词),是否达标由「已完成 / 待完善」标签表达;帮助文案只在待完善时展示。禁止出现「已完成 · 请先完善…」这类自相矛盾的措辞。 --- @@ -269,19 +270,19 @@ 以下为各页面的视觉结构约定,业务逻辑不变。 -| 页面 | 结构要点 | -| -------------- | ---------------------------------------------------------------------------------------------------------------------- | -| 登录 | 居中 400px 卡片,标识 + 说明 + 表单 + 通栏主按钮;错误态展示在字段下方 | -| 首次改密 | 同登录卡片形态,说明文案 + 三个密码字段 + 「保存新密码」 | -| 品牌概览 | 品牌卡 + 三张指标卡(等宽一行)+ 两栏(发布准备度 / 品牌内容检查) | -| 配置与发布 | 三 Tab(内容发布 / 小程序发布 / 小程序配置);发布状态卡 + 草稿卡 + 历史版本表 | -| 小程序页面 | 左右两栏:左 380px 编辑面板,右预览画布;预览内选中区域虚线高亮 + 区域名气泡 | -| 信任内容 | 列表行(类型图标或配图 + 标题 + 发布状态标签 + 类型/展示位置说明 + 两行摘要 + 行内操作),按模板类型顺序排列,不用表格 | -| 业务提供项 | 表格(名称 / 价格 / 状态开关 / 排序 / 操作)+ 新增弹窗 | -| 咨询记录 | 顶部三指标 + 左 380px 列表 + 右详情的主从布局 | -| 模板与表单设置 | 行业模板网格(三列)+ 咨询表单字段编辑器 + 底部危险操作区 | -| 能力插件 | 插件卡片列表(图标 + 名称 + 说明 + 开关),停用态降低对比度 | -| 团队成员 | 表格(成员 / 角色 / 状态 / 最近登录 / 操作)+ 邀请弹窗 | +| 页面 | 结构要点 | +| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | +| 登录 | 居中 400px 卡片,标识 + 说明 + 表单 + 通栏主按钮;错误态展示在字段下方 | +| 首次改密 | 同登录卡片形态,说明文案 + 三个密码字段 + 「保存新密码」 | +| 品牌概览 | 品牌卡 + 三张指标卡(等宽一行)+ 两栏(发布准备度 / 品牌内容检查) | +| 配置与发布 | 三 Tab(内容发布 / 小程序发布 / 小程序配置);内容发布含「选择表达方式」(行业模板 + 视觉模板 + 版本升级/回滚)+ 发布状态卡 + 草稿卡 + 历史版本表 | +| 小程序页面 | 左右两栏:左 380px 编辑面板,右预览画布;预览内选中区域虚线高亮 + 区域名气泡 | +| 信任内容 | 列表行(类型图标或配图 + 标题 + 发布状态标签 + 类型/展示位置说明 + 两行摘要 + 行内操作),按模板类型顺序排列,不用表格 | +| 业务提供项 | 表格(名称 / 价格 / 状态开关 / 排序 / 操作)+ 新增弹窗 | +| 咨询记录 | 顶部三指标 + 左 380px 列表 + 右详情的主从布局 | +| 咨询表单与字段 | 咨询表单表(名称 / 版本 / 字段数 / 状态 / 操作)+ 新增与编辑弹窗(含选项编辑);高级自定义字段表 + 新增弹窗 | +| 能力插件 | 插件卡片列表(图标 + 名称 + 说明 + 开关),停用态降低对比度 | +| 团队成员 | 表格(成员 / 角色 / 状态 / 最近登录 / 操作)+ 邀请弹窗 | 两栏页面在小屏下折叠为单列,编辑/预览改为上下排列。 diff --git a/apps/admin/src/features/capabilities/CapabilitiesPage.tsx b/apps/admin/src/features/capabilities/CapabilitiesPage.tsx index c4d222c..412dc56 100644 --- a/apps/admin/src/features/capabilities/CapabilitiesPage.tsx +++ b/apps/admin/src/features/capabilities/CapabilitiesPage.tsx @@ -30,10 +30,8 @@ export function CapabilitiesPage() { } title="当前模板没有可配置能力" - description="安装行业模板后,这里会列出可开关的能力插件。" - action={ - - } + description="能力的开关由品牌当前使用的行业模板决定;更换行业模板不在本版本范围内。" + action={} /> )} diff --git a/apps/admin/src/features/publication/PublicationPage.tsx b/apps/admin/src/features/publication/PublicationPage.tsx index 16fc30d..89daa4c 100644 --- a/apps/admin/src/features/publication/PublicationPage.tsx +++ b/apps/admin/src/features/publication/PublicationPage.tsx @@ -83,6 +83,10 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool queryKey: ["publication-miniapp-settings"], queryFn: () => client.getAdminMiniAppSettings(), }); + const templatePreview = useQuery({ + queryKey: ["publication-template-preview"], + queryFn: () => client.getAdminTemplateUpgradePreview(), + }); useEffect(() => { if (!miniAppSettings.data) return; miniAppSettingsForm.setFieldsValue({ @@ -108,6 +112,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool "publication-workspace", "publication-sample", "publication-readiness", + "publication-template-preview", "publication-releases", "publication-miniapp-releases", "admin-shell-brand", @@ -125,6 +130,20 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool refresh(); }, }); + const upgradeTemplate = useMutation({ + mutationFn: () => client.upgradeAdminTemplate(), + onSuccess: () => { + message.success("行业模板已升级,现有内容未被覆盖"); + refresh(); + }, + }); + const rollbackTemplate = useMutation({ + mutationFn: () => client.rollbackAdminTemplate(), + onSuccess: () => { + message.success("行业模板配置基线已回滚"); + refresh(); + }, + }); const selectVisual = useMutation({ mutationFn: (key: string) => client.updateAdminBrand({ @@ -405,14 +424,50 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool options={visuals.map((item) => ({ value: item.key, label: item.name }))} onChange={(key) => selectVisual.mutate(key)} /> - {canManageTemplate && ( - - )} - {workspace.data?.installations.length ? ( -

- 当前品牌已安装主模板。模板版本与升级在高级设置中管理。 -

+ {industryKey ? ( +
+ + + + {templatePreview.data?.canUpgrade ? ( + + ) : ( + + )} + {templatePreview.data?.canRollback ? ( + + ) : null} + +

+ 行业模板随品牌身份固定,只能升级版本、不能更换行业;升级只补充字段与模块,不覆盖已有内容。视觉模板只替换排版风格。 +

+ +
) : null} @@ -517,7 +572,9 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool label={check.passed ? "已完成" : "待完善"} /> {check.label} - {check.help ? {check.help} : null} + {!check.passed && check.help ? ( + {check.help} + ) : null} {!check.passed ? ( diff --git a/apps/admin/src/features/workspace/WorkspacePage.tsx b/apps/admin/src/features/workspace/WorkspacePage.tsx index 5f9112a..c127f9f 100644 --- a/apps/admin/src/features/workspace/WorkspacePage.tsx +++ b/apps/admin/src/features/workspace/WorkspacePage.tsx @@ -1,26 +1,15 @@ -import { Button, Card, Form, Input, Modal, Select, Space, Table, Typography } from "antd"; -import { useNavigate } from "react-router-dom"; -import { ApiClientError } from "@personal-brand/api-client"; -import { createApiClient } from "../../lib/api.js"; -import type { - BrandFieldDefinition, - BrandTemplateKey, - InquiryForm, -} from "@personal-brand/api-client"; -import { useQuery, useQueryClient } from "@tanstack/react-query"; import { useState } from "react"; -import { - useWorkspaceQueries, - useTemplateMutations, - useFieldMutations, - useInquiryFormMutations, -} from "./workspace-mutations.js"; -import { supportsIndustry, type IndustryTarget } from "./workspace-templates.js"; +import { useQueryClient } from "@tanstack/react-query"; +import { Button, Card, Form, Input, Modal, Select, Space, Table } from "antd"; +import type { BrandFieldDefinition, InquiryForm } from "@personal-brand/api-client"; import { AdminPageHeader } from "../../components/AdminPageHeader.js"; +import { AdminSection } from "../../components/AdminSection.js"; import { EmptyState } from "../../components/EmptyState.js"; -import { MutationError } from "../../components/QueryState.js"; +import { MutationError, QueryState } from "../../components/QueryState.js"; import { StatusTag } from "../../components/StatusTag.js"; import { ListSkeleton } from "../../components/TableSkeleton.js"; +import { useFieldMutations, useInquiryFormMutations } from "./workspace-mutations.js"; +import { useFormWorkspaceQueries } from "./workspace-queries.js"; export const inquiryFieldTypes = [ { value: "text", label: "简短文字" }, @@ -34,6 +23,20 @@ export const inquiryFieldTypes = [ { value: "multi-select", label: "多项选择" }, ]; +const fieldScopes = [ + { value: "profile", label: "品牌资料" }, + { value: "service", label: "业务提供项" }, + { value: "inquiry", label: "咨询表单" }, +]; + +function fieldTypeLabel(type: unknown): string { + return inquiryFieldTypes.find((item) => item.value === type)?.label ?? "自定义"; +} + +function fieldScopeLabel(scope: unknown): string { + return fieldScopes.find((item) => item.value === scope)?.label ?? "其他"; +} + export function readOptionLabel(option: unknown): string { const value = option as { label?: unknown } | null | undefined; return typeof value?.label === "string" ? value.label : ""; @@ -47,16 +50,12 @@ export function normalizeOptionLabels(options: unknown): Array<{ label: string; } export function WorkspacePage() { - const navigate = useNavigate(); const queryClient = useQueryClient(); + const { workspace, forms } = useFormWorkspaceQueries(); const [fieldOpen, setFieldOpen] = useState(false); const [formOpen, setFormOpen] = useState(false); const [editingForm, setEditingForm] = useState(null); - const [visualTarget, setVisualTarget] = useState(null); - const [industryTarget, setIndustryTarget] = useState(null); - const [previewIndustry, setPreviewIndustry] = useState(null); - const [previewVisual, setPreviewVisual] = useState(null); - const [form] = Form.useForm>(); + const [fieldForm] = Form.useForm>(); const [inquiryForm] = Form.useForm>(); const openNewInquiryForm = () => { setEditingForm(null); @@ -71,40 +70,8 @@ export function WorkspacePage() { }); setFormOpen(true); }; - const { query, runtimeQuery, templateCatalog, forms, templatePreview } = useWorkspaceQueries(); - const previewIndustryKey = - previewIndustry ?? - query.data?.brand.templateKey ?? - query.data?.installations[0]?.templateKey ?? - templateCatalog.data?.industries[0]?.key; - const previewVisualKey = - previewVisual ?? - runtimeQuery.data?.visualTemplate?.key ?? - (templateCatalog.data?.visuals ?? []).find((visual) => - supportsIndustry(visual, previewIndustryKey ?? ""), - )?.key; - const combinationPreview = useQuery({ - queryKey: ["template-combination-preview", previewIndustryKey, previewVisualKey], - queryFn: () => - createApiClient().previewPublicTemplateCombination( - previewIndustryKey ?? "", - previewVisualKey ?? "", - ), - enabled: Boolean(templateCatalog.data && previewIndustryKey && previewVisualKey), - }); - const compatibleVisuals = (templateCatalog.data?.visuals ?? []).filter((visual) => - supportsIndustry(visual, query.data?.brand?.templateKey ?? ""), - ); - const { visualTemplate, rollbackVisual, install, upgrade, rollback } = useTemplateMutations({ - runtimeConfig: runtimeQuery.data?.brand?.config ?? undefined, - queryClient, - }); - const visualHistory = useQuery({ - queryKey: ["visual-template-history"], - queryFn: () => createApiClient().getAdminVisualTemplateHistory(), - }); const { createField, removeField } = useFieldMutations({ - form, + form: fieldForm, queryClient, onClose: () => setFieldOpen(false), }); @@ -116,309 +83,20 @@ export function WorkspacePage() { setEditingForm(null); }, }); - if (query.isLoading) return ; - if (query.isError || !query.data) { - const errorStatus = - query.error instanceof ApiClientError - ? query.error.status - : (query.error as { status?: number } | null)?.status; - const expired = errorStatus === 401; - return ( - window.dispatchEvent(new Event("admin-auth-expired"))} - > - 重新登录 - - ) : ( - - ) - } - > - {expired - ? "请重新登录后再访问工作空间。" - : query.error instanceof Error - ? query.error.message - : "请检查 API 服务后刷新重试。"} - - ); - } - const { fields, installations } = query.data; + return ( -
+ void Promise.all([workspace.refetch(), forms.refetch()])} + > - -

- 下面这些入口面向日常经营,不需要理解模板或技术设置。完成后回到“配置与发布”统一检查并上线。 -

- - - - - - -
- - {runtimeQuery.isError ? ( - - ) : ( -
- - - - - -

- 小程序和后台预览会使用同一份已发布内容。这里的能力由当前模板自动提供,通常不需要手动调整。 -

-
-

已启用的服务能力

- {(runtimeQuery.data?.plugins ?? []).map((plugin) => ( - -
- {plugin.displayName} - -
-

- 这项能力已接入当前小程序流程,无需单独配置技术参数。 -

-
- ))} - {!runtimeQuery.data?.plugins?.length && ( - - )} -
- - 视觉模板 - setPreviewIndustry(key)} - options={(templateCatalog.data?.industries ?? []).map((item) => ({ - value: item.key, - label: item.name, - }))} - /> - - updateForm.mutate({ id: item.id, body: { isEnabled } }) - } - /> ), }, @@ -505,46 +185,29 @@ export function WorkspacePage() { )} - - + - 负责人设置 - - - } + description="仅在某个字段需要跨业务复用时才在这里添加;日常问题直接写在表单里即可。" + extra={} > item.source === "custom")} + dataSource={(workspace.data?.fields ?? []).filter((item) => item.source === "custom")} + pagination={false} locale={{ emptyText: ( ), }} columns={[ { title: "字段", dataIndex: "label" }, - { - title: "使用位置", - dataIndex: "scope", - render: (value) => - ({ profile: "品牌资料", service: "业务提供项", inquiry: "咨询表单" })[ - String(value) - ] ?? "其他", - }, - { - title: "填写方式", - dataIndex: "type", - render: (value) => - inquiryFieldTypes.find((item) => item.value === value)?.label ?? "自定义", - }, + { title: "使用位置", dataIndex: "scope", render: fieldScopeLabel }, + { title: "填写方式", dataIndex: "type", render: fieldTypeLabel }, { title: "操作", render: (_: unknown, item: BrandFieldDefinition) => ( @@ -557,19 +220,19 @@ export function WorkspacePage() { /> - + { setFieldOpen(false); - form.resetFields(); + fieldForm.resetFields(); }} - onOk={() => form.submit()} + onOk={() => fieldForm.submit()} confirmLoading={createField.isPending} >
createField.mutate({ @@ -584,41 +247,20 @@ export function WorkspacePage() { } as Omit) } > - - - - + - + + + + @@ -626,7 +268,7 @@ export function WorkspacePage() {
{ setFormOpen(false); setEditingForm(null); @@ -637,7 +279,7 @@ export function WorkspacePage() { width={760} >

- 先确定客户要提交的事情,再设置你希望客户填写的问题。保存后还需要在“配置与发布”中检查并发布,才会在小程序生效。 + 先确定客户要提交的事情,再设置希望客户填写的问题。保存后需在“配置与发布”发布,才会在小程序生效。

- +