From f4061a24bd28d32a758fafc35b9870e2fa06c749 Mon Sep 17 00:00:00 2001 From: que01 Date: Thu, 8 Oct 2026 13:36:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B6=E6=95=9B=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=8F=91=E5=B8=83=E5=A5=91=E7=BA=A6=E5=B9=B6?= =?UTF-8?q?=E8=BF=98=E5=8E=9F=E9=A4=90=E9=A5=AE=E9=A1=B5=E9=9D=A2=E8=A7=86?= =?UTF-8?q?=E8=A7=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/TemplateListField.tsx | 15 +- apps/admin/src/features/brand/BrandPage.tsx | 6 +- .../src/features/brand/PresentationEditor.tsx | 279 ++++++-- .../features/brand/presentation-bindings.ts | 5 +- .../src/features/overview/OverviewPage.tsx | 4 +- .../features/publication/PublicationPage.tsx | 14 +- .../src/features/services/ServicesPage.tsx | 42 +- .../trust-content/TrustContentPage.tsx | 209 ++++-- .../src/features/workspace/WorkspacePage.tsx | 8 +- apps/admin/src/main.tsx | 2 +- apps/api/prisma/seed.ts | 121 ++-- apps/api/scripts/migrate-food-owner-visual.ts | 85 +++ .../scripts/migrate-food-template-content.ts | 157 +++++ apps/api/scripts/tsconfig.json | 5 + apps/api/scripts/verify-food-template.ts | 153 +++++ apps/api/src/admin-workspace.controller.ts | 39 +- apps/api/src/admin.dto.ts | 15 +- apps/api/src/brand-release-api.service.ts | 25 +- .../modules/admin/admin-config.controller.ts | 37 +- .../public/public-workspace.controller.ts | 97 ++- apps/api/src/template-workspace.service.ts | 47 ++ apps/api/test/http.integration.test.js | 365 ++++++++++- apps/api/test/run-integration.cjs | 23 + .../modules/inquiry-form/inquiry-form.js | 22 + .../modules/inquiry-form/inquiry-form.wxml | 17 +- .../modules/inquiry-form/inquiry-form.wxss | 10 + .../offering-detail/offering-detail.wxml | 2 +- apps/miniapp/package.json | 2 +- apps/miniapp/test/food-inquiry-page.test.cjs | 66 ++ apps/miniapp/test/food-profile-page.test.cjs | 38 ++ apps/miniapp/test/food-service-page.test.cjs | 63 ++ .../test/inquiry-form-component.test.cjs | 50 ++ apps/miniapp/test/runtime-workspace.test.cjs | 2 +- apps/miniapp/test/trust-content.test.cjs | 24 + apps/miniapp/utils/runtime-workspace.js | 4 +- apps/miniapp/utils/trust-content.js | 19 + docs/adr/0017-runtime-content-contract.md | 43 ++ docs/adr/0018-template-visual-slots.md | 31 + docs/engineering-delivery-checklist.md | 13 + docs/runtime-content-matrix.md | 17 + docs/template-data-flow.md | 54 ++ eslint.config.mjs | 1 + packages/api-client/src/index.ts | 29 +- .../config/src/generated-template-packages.js | 607 ++++++++++++++--- packages/config/src/index.ts | 36 +- .../miniapp/assets/owner/clock.png | Bin 0 -> 2579 bytes .../miniapp/assets/owner/clock.svg | 1 + .../miniapp/assets/owner/file-check.png | Bin 0 -> 1166 bytes .../miniapp/assets/owner/file-check.svg | 1 + .../miniapp/assets/owner/handshake.png | Bin 0 -> 2044 bytes .../miniapp/assets/owner/handshake.svg | 1 + .../miniapp/assets/owner/portrait.jpg | Bin 0 -> 107134 bytes .../miniapp/assets/owner/shield-check.png | Bin 0 -> 2044 bytes .../miniapp/assets/owner/shield-check.svg | 1 + .../miniapp/assets/owner/sparkles.png | Bin 0 -> 1647 bytes .../miniapp/assets/owner/sparkles.svg | 1 + .../miniapp/assets/service/bike-blue.png | Bin 0 -> 2477 bytes .../miniapp/assets/service/bike-blue.svg | 1 + .../miniapp/assets/service/bike.png | Bin 0 -> 2447 bytes .../miniapp/assets/service/bike.svg | 1 + .../miniapp/assets/service/clock.png | Bin 0 -> 3453 bytes .../miniapp/assets/service/clock.svg | 1 + .../miniapp/assets/service/footprints.png | Bin 0 -> 1786 bytes .../miniapp/assets/service/footprints.svg | 1 + .../miniapp/assets/service/list.png | Bin 0 -> 674 bytes .../miniapp/assets/service/list.svg | 1 + .../templates/acheng-home/acheng-home.wxml | 2 +- .../acheng-profile/acheng-profile.js | 13 +- .../acheng-profile/acheng-profile.wxml | 24 +- .../acheng-profile/acheng-profile.wxss | 150 +++-- .../miniapp/pages/bookings/index.js | 19 +- .../miniapp/pages/bookings/index.json | 2 +- .../miniapp/pages/bookings/index.wxml | 36 +- .../miniapp/pages/bookings/index.wxss | 322 +++++---- .../miniapp/pages/index/index.wxml | 2 +- .../miniapp/pages/inquiry/index.js | 35 +- .../miniapp/pages/inquiry/index.wxml | 14 +- .../miniapp/pages/inquiry/index.wxss | 56 +- .../miniapp/pages/stall-service/index.js | 67 +- .../miniapp/pages/stall-service/index.wxml | 17 +- .../miniapp/pages/stall-service/index.wxss | 89 ++- .../template-acheng-campus-food/template.json | 611 +++++++++++++++--- .../template-drill-consultant/template.json | 2 +- packages/template-contract/README.md | 8 + packages/template-contract/src/index.ts | 94 ++- .../test/editability.test.mjs | 237 ++++++- .../template-contract/test/manifest.test.mjs | 189 +++++- .../templates/linjing-home/linjing-home.js | 2 +- .../templates/linjing-home/linjing-home.wxml | 6 +- .../linjing-profile/linjing-profile.js | 1 + .../linjing-profile/linjing-profile.wxml | 5 + .../linjing-profile/linjing-profile.wxss | 11 + .../miniapp/pages/bookings/index.js | 7 +- .../miniapp/pages/bookings/index.wxml | 2 +- .../miniapp/pages/index/index.js | 16 +- .../miniapp/pages/index/index.wxml | 2 +- .../template-linjing-editorial/template.json | 77 ++- packages/types/package.json | 1 + packages/types/src/index.ts | 1 + .../types/src/runtime-content-contract.ts | 233 +++++++ packages/types/src/runtime-workspace.ts | 4 +- .../test/runtime-content-contract.test.mjs | 110 ++++ 102 files changed, 4510 insertions(+), 870 deletions(-) create mode 100644 apps/api/scripts/migrate-food-owner-visual.ts create mode 100644 apps/api/scripts/migrate-food-template-content.ts create mode 100644 apps/api/scripts/tsconfig.json create mode 100644 apps/api/scripts/verify-food-template.ts create mode 100644 apps/miniapp/test/food-inquiry-page.test.cjs create mode 100644 apps/miniapp/test/food-profile-page.test.cjs create mode 100644 apps/miniapp/test/food-service-page.test.cjs create mode 100644 apps/miniapp/test/inquiry-form-component.test.cjs create mode 100644 apps/miniapp/test/trust-content.test.cjs create mode 100644 apps/miniapp/utils/trust-content.js create mode 100644 docs/adr/0017-runtime-content-contract.md create mode 100644 docs/adr/0018-template-visual-slots.md create mode 100644 docs/runtime-content-matrix.md create mode 100644 docs/template-data-flow.md create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/clock.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/clock.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/file-check.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/file-check.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/handshake.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/handshake.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/portrait.jpg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/shield-check.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/shield-check.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/sparkles.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/owner/sparkles.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/bike-blue.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/bike-blue.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/bike.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/bike.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/clock.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/clock.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/footprints.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/footprints.svg create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/list.png create mode 100644 packages/template-acheng-campus-food/miniapp/assets/service/list.svg create mode 100644 packages/types/src/runtime-content-contract.ts create mode 100644 packages/types/test/runtime-content-contract.test.mjs diff --git a/apps/admin/src/components/TemplateListField.tsx b/apps/admin/src/components/TemplateListField.tsx index 1d4ec09..46ae173 100644 --- a/apps/admin/src/components/TemplateListField.tsx +++ b/apps/admin/src/components/TemplateListField.tsx @@ -10,8 +10,18 @@ export function TemplateListField({ }) { return ( - - {(rows, { add, remove }) => ( + + field.required && (!Array.isArray(values) || values.length === 0) + ? Promise.reject(new Error(`请至少填写一项${field.label}`)) + : Promise.resolve(), + }, + ]} + > + {(rows, { add, remove }, { errors }) => ( {rows.map((row, index) => ( @@ -32,6 +42,7 @@ export function TemplateListField({ ))} + )} diff --git a/apps/admin/src/features/brand/BrandPage.tsx b/apps/admin/src/features/brand/BrandPage.tsx index c27cd4b..488d894 100644 --- a/apps/admin/src/features/brand/BrandPage.tsx +++ b/apps/admin/src/features/brand/BrandPage.tsx @@ -33,7 +33,7 @@ export function BrandPage() { {!brand.data ? null : ( <> {template.data?.name ?? "当前模板"}} /> @@ -152,7 +152,9 @@ export function BrandPage() { - 小程序首页将优先使用以下信息 + + 这些资料会用于小程序首页和联系区域 + {brand.data.name || "品牌名称"} {brand.data.tagline || "一句话定位"} diff --git a/apps/admin/src/features/brand/PresentationEditor.tsx b/apps/admin/src/features/brand/PresentationEditor.tsx index 0fed01b..30d0bdf 100644 --- a/apps/admin/src/features/brand/PresentationEditor.tsx +++ b/apps/admin/src/features/brand/PresentationEditor.tsx @@ -2,17 +2,23 @@ import { Alert, Button, Card, + Divider, Col, Form, + Grid, Input, InputNumber, Row, + Select, + Segmented, Space, + Tag, Typography, message, } from "antd"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { useEffect, useMemo } from "react"; +import { useEffect, useMemo, useState } from "react"; +import { useNavigate } from "react-router-dom"; import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client"; import { createApiClient } from "../../lib/api.js"; import { ImageUrlField } from "../../components/ImageUrlField.js"; @@ -46,6 +52,22 @@ function renderField(field: TemplateAdminField) { return ; if (field.input === "number") return ; + if (field.input === "boolean") + return ( + + ); return ( (); const queryClient = useQueryClient(); - const sections = useMemo( - () => - (templateContent?.admin.sections ?? []) - .map((section) => ({ - ...section, - fields: section.fields.filter((field) => field.binding.startsWith("brand.config.")), - })) - .filter((section) => section.fields.length > 0), - [templateContent], + const navigate = useNavigate(); + const breakpoints = Grid.useBreakpoint(); + const [activePage, setActivePage] = useState(); + const sections = useMemo(() => { + const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({ + ...field, + binding: field.binding ?? `brand.config.templateData.${field.key}`, + })); + return [ + ...(declaredTemplateFields.length + ? [ + { + key: "template-data", + title: "模板专属内容", + description: "这些字段由当前小程序模板定义,保存后发布才会对外展示。", + page: templateContent?.templateFields?.[0]?.page ?? "home", + target: "brand" as const, + fields: declaredTemplateFields, + }, + ] + : []), + ...(templateContent?.admin.sections ?? []), + ] + .map((section) => ({ + ...section, + fields: section.fields.filter( + (field) => + field.binding.startsWith("brand.config.") || + [ + "brand.avatarUrl", + "brand.description", + "brand.contactPhone", + "brand.contactWechat", + "brand.address", + ].includes(field.binding), + ), + })) + .filter((section) => section.fields.length > 0); + }, [templateContent]); + const pageOptions = useMemo(() => { + const pages = new Map(); + for (const item of templateContent?.navigation ?? []) pages.set(item.page, item.label); + for (const section of templateContent?.admin.sections ?? []) { + const navigation = templateContent?.navigation.find((item) => item.page === section.page); + if (!pages.has(section.page)) + pages.set(section.page, navigation?.label ?? pageTitle(section.page)); + } + return [...pages].map(([value, label]) => ({ value, label })); + }, [templateContent]); + const selectedPage = pageOptions.some((item) => item.value === activePage) + ? activePage + : pageOptions[0]?.value; + const visibleSections = sections.filter((section) => section.page === selectedPage); + const relatedTargets = [ + ...(templateContent?.admin.sections ?? []) + .filter((section) => section.page === selectedPage && section.target !== "brand") + .map((section) => section.target), + ...((templateContent?.trustContentTypes ?? []).some((item) => + item.pages?.includes(selectedPage ?? ""), + ) + ? ["trust"] + : []), + ]; + const pageLinks = [...new Set(relatedTargets)].flatMap((target) => + target === "trust" + ? (templateContent?.trustContentTypes ?? []) + .filter((item) => item.pages?.includes(selectedPage ?? "")) + .map((item) => ({ + target: `trust:${item.type}`, + label: `编辑${item.label}`, + })) + : [ + { + target, + label: ( + { offering: "管理此页展示的业务内容", inquiry: "管理此页的咨询表单" } as Record< + string, + string + > + )[target], + }, + ], ); const initialValues = useMemo(() => { const values: PresentationValues = {}; @@ -105,10 +200,20 @@ export function PresentationEditor({ form.setFieldsValue(initialValues); }, [form, initialValues]); + useEffect(() => { + if (!pageOptions.some((item) => item.value === activePage)) + setActivePage(pageOptions[0]?.value); + }, [activePage, pageOptions]); + return ( - + {templateContent.displayName} : null} + style={{ marginTop: 32 }} + styles={{ body: { minHeight: breakpoints.md ? 760 : 620 } }} + > - 编辑访客在小程序中看到的文字和图片。不同模板会提供适合本行业的内容项目。 + 按小程序页面查找内容。这里修改的是草稿,发布后访客才会看到更新。 {loading ? : null} {error ? ( @@ -119,51 +224,108 @@ export function PresentationEditor({ ) : null} {templateContent ? ( <> - {templateContent.displayName} + + {breakpoints.xs ? ( + - - - + {!hasTemplateDetailCopy ? ( + + + + ) : null} diff --git a/apps/admin/src/features/trust-content/TrustContentPage.tsx b/apps/admin/src/features/trust-content/TrustContentPage.tsx index c0800c5..9bdf1bc 100644 --- a/apps/admin/src/features/trust-content/TrustContentPage.tsx +++ b/apps/admin/src/features/trust-content/TrustContentPage.tsx @@ -1,6 +1,6 @@ import { Button, - Card, + Divider, Form, Input, List, @@ -14,12 +14,14 @@ import { message, } from "antd"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { isTrustContentComplete } from "@personal-brand/api-client"; import type { TemplateAdminField, TrustContent, TrustContentInput, } from "@personal-brand/api-client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; +import { useSearchParams } from "react-router-dom"; import { createApiClient } from "../../lib/api.js"; import { AdminPageHeader } from "../../components/AdminPageHeader.js"; import { ImageUrlField } from "../../components/ImageUrlField.js"; @@ -61,14 +63,25 @@ const types = [ type TrustTypeOption = { type: string; label: string; + adminFields: { + title: string; + summary: string; + content: string; + summaryHelp?: string; + summaryPlaceholder?: string; + }; + pages?: string[]; help?: string; placeholder?: string; required?: boolean; configFields?: TemplateAdminField[]; + hideStandardFields?: Array<"summary" | "content">; + maxPublishedItems?: number; }; const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({ type: value, label, + adminFields: { title: "标题", summary: "摘要", content: "详细内容" }, help, })); @@ -78,6 +91,7 @@ export function TrustContentPage() { const [editing, setEditing] = useState(null); const [open, setOpen] = useState(false); const [form] = Form.useForm(); + const [searchParams] = useSearchParams(); const selectedType = Form.useWatch("type", form); const query = useQuery({ queryKey: ["trust-content"], @@ -91,6 +105,21 @@ export function TrustContentPage() { ?.length ? workspace.data.templateContent.trustContentTypes : fallbackTypes; + const pageLabel = (page: string) => + workspace.data?.templateContent?.navigation.find((item) => item.page === page)?.label ?? + ( + { home: "首页", offerings: "业务展示页", detail: "详情页", profile: "主理人页" } as Record< + string, + string + > + )[page] ?? + page; + const trustPageLabels = [ + ...new Set(availableTypes.flatMap((item) => item.pages ?? []).map(pageLabel)), + ]; + const trustPlacement = trustPageLabels.length + ? `小程序的${trustPageLabels.join("、")}中` + : "小程序对应的信任展示区域中"; const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType); const contentByType = new Map(); for (const item of query.data ?? []) { @@ -109,13 +138,14 @@ export function TrustContentPage() { availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ?? availableTypes[0]?.type ?? "credential"; + const requestedType = searchParams.get("type"); const save = useMutation({ mutationFn: (values: TrustContentInput) => editing ? client.updateAdminTrustContent(editing.id, values) : client.createAdminTrustContent(values), onSuccess: () => { - message.success("信任内容已保存"); + message.success("品牌内容已保存为草稿,发布后小程序才会更新"); setOpen(false); setEditing(null); form.resetFields(); @@ -125,7 +155,7 @@ export function TrustContentPage() { const remove = useMutation({ mutationFn: (id: string) => client.deleteAdminTrustContent(id), onSuccess: () => { - message.success("内容已删除"); + message.success("品牌内容已删除"); void queryClient.invalidateQueries({ queryKey: ["trust-content"] }); }, }); @@ -146,6 +176,10 @@ export function TrustContentPage() { : { type: type ?? firstMissingRequiredType, isPublished: false, config: {} }, ); }; + useEffect(() => { + if (!requestedType || !availableTypes.some((item) => item.type === requestedType)) return; + begin(contentByType.get(requestedType), requestedType); + }, [requestedType, availableTypes.length]); return ( void Promise.all([query.refetch(), workspace.refetch()])} > begin()}> - 新增信任内容 + 添加品牌内容 } /> - +
+ + 当前模板需要配置的内容 + - 这些内容会帮助访客判断你是否值得信任。带有“发布必需”的项目需要填写完整后,才能发布小程序。 + 标记为“发布必填”的项目需要填写完整后,才能发布小程序。 { const content = contentByType.get(item.type); - const complete = Boolean(content?.title?.trim() && content?.content?.trim()); + const publishedCount = (query.data ?? []).filter( + (record) => record.type === item.type && record.isPublished, + ).length; + const tooMany = + item.maxPublishedItems !== undefined && publishedCount > item.maxPublishedItems; + const complete = Boolean(content && isTrustContentComplete(content, item) && !tooMany); return ( {item.label} - {item.required && 发布必需} + {item.required && 发布必填} + {(item.pages ?? []).map((page) => ( + {pageLabel(page)} + ))} - {complete ? "内容完整" : content ? "需要完善" : "尚未填写"} + {tooMany + ? `公开内容过多(${publishedCount} 条)` + : complete + ? "内容完整" + : content + ? "需要完善" + : "尚未填写"} {item.help && {item.help}} @@ -196,15 +247,16 @@ export function TrustContentPage() { ); }} /> - - +
+ +
( {availableTypes.find((item) => item.type === value)?.label ?? value} @@ -212,15 +264,32 @@ export function TrustContentPage() { }, { title: "标题", dataIndex: "title" }, { - title: "摘要", - dataIndex: "summary", - render: (value) => (typeof value === "string" && value ? value : "未填写"), + title: "内容预览", + ellipsis: { showTitle: true }, + render: (_value: unknown, item: TrustContent) => { + const meta = availableTypes.find((type) => type.type === item.type); + if (meta?.hideStandardFields?.includes("content")) { + return ( + meta.configFields + ?.flatMap((field) => { + const value = item.config?.[field.key]; + if (Array.isArray(value)) + return value.length ? [`${field.label}:${value.length} 项`] : []; + return typeof value === "string" && value.trim() + ? [`${field.label}:${value}`] + : []; + }) + .join(";") || "尚未填写区块内容" + ); + } + return item.summary || item.content || "未填写"; + }, }, { - title: "状态", + title: "发布状态", dataIndex: "isPublished", render: (value) => ( - {value ? "已公开" : "草稿"} + {value ? "随发布展示" : "草稿"} ), }, { @@ -232,7 +301,7 @@ export function TrustContentPage() { remove.mutate(item.id)} >