From e3a4074d8e0f3ac39922937bb1974d44d78a4de4 Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 27 Sep 2026 12:51:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A9=E6=A8=A1=E6=9D=BF=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E4=BF=A1=E4=BB=BB=E5=86=85=E5=AE=B9=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trust-items-content-migration/PROGRESS.md | 3 + .../trust-content/TrustContentPage.tsx | 37 ++++++++-- .../src/features/workspace/WorkspacePage.tsx | 10 +-- .../migration.sql | 2 + apps/api/src/admin-workspace.controller.ts | 1 + apps/api/test/http.integration.test.js | 2 + packages/api-client/src/index.ts | 1 + .../config/src/generated-template-packages.js | 70 ++++++++++++++++++- packages/config/src/index.ts | 6 ++ .../template-acheng-campus-food/template.json | 8 +++ packages/template-contract/src/index.ts | 24 +++++++ .../template-linjing-editorial/template.json | 8 +++ 12 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 apps/api/prisma/migrations/20260927100000_normalize_trust_content_types/migration.sql diff --git a/.codex-tasks/trust-items-content-migration/PROGRESS.md b/.codex-tasks/trust-items-content-migration/PROGRESS.md index 67f89f5..68b9163 100644 --- a/.codex-tasks/trust-items-content-migration/PROGRESS.md +++ b/.codex-tasks/trust-items-content-migration/PROGRESS.md @@ -8,6 +8,8 @@ - 阿成首页、出摊服务、主理人页面消费 `trustItems`;无对应类型时不渲染区块。 - `AGENTS.md` 固化模板 package 与品牌数据库的边界,禁止用全局 seed 承载模板集合。 - Admin 信任内容页面改用通用中文类型和逐行填写说明,不再出现餐饮专属管理术语;演示 seed 与模板 sampleContent 已移除旧 `profile/portfolio` 类型。 +- 模板 manifest 现在可以声明信任类型的行业化 label、help 和 placeholder;Admin 通过 workspace contract 消费这些声明,平台不再硬编码行业文案。 +- 新增迁移,将历史 `profile/experience/portfolio/testimonial` 数据归一化到 `credential/case`。 ## 验证 @@ -15,3 +17,4 @@ - miniapp fixture、visual fixture、template compiler:通过。 - typecheck、lint:通过。 - Admin typecheck、production build、template catalog validation:通过。 +- API integration:37/37 通过,包含模板化信任类型声明和历史类型迁移。 diff --git a/apps/admin/src/features/trust-content/TrustContentPage.tsx b/apps/admin/src/features/trust-content/TrustContentPage.tsx index 10f69e1..5364123 100644 --- a/apps/admin/src/features/trust-content/TrustContentPage.tsx +++ b/apps/admin/src/features/trust-content/TrustContentPage.tsx @@ -51,6 +51,17 @@ const types = [ help: "说明回复时间、交付承诺、售后方式或合作预期。", }, ]; +type TrustTypeOption = { + type: string; + label: string; + help?: string; + placeholder?: string; +}; +const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({ + type: value, + label, + help, +})); export function TrustContentPage() { const client = createApiClient(); @@ -58,10 +69,20 @@ export function TrustContentPage() { const [editing, setEditing] = useState(null); const [open, setOpen] = useState(false); const [form] = Form.useForm(); + const selectedType = Form.useWatch("type", form); const query = useQuery({ queryKey: ["trust-content"], queryFn: () => client.listAdminTrustContent(), }); + const workspace = useQuery({ + queryKey: ["admin-workspace-trust-types"], + queryFn: () => client.getAdminWorkspace(), + }); + const availableTypes: TrustTypeOption[] = workspace.data?.templateContent?.trustContentTypes + ?.length + ? workspace.data.templateContent.trustContentTypes + : fallbackTypes; + const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType); const save = useMutation({ mutationFn: (values: TrustContentInput) => editing @@ -99,7 +120,11 @@ export function TrustContentPage() { ); }; return ( - void query.refetch()}> + void Promise.all([query.refetch(), workspace.refetch()])} + >
save.mutate(values)}> - ({ value: item.type, label: item.label }))} + /> @@ -182,14 +209,16 @@ export function TrustContentPage() { Schema {runtimeQuery.data?.schemaVersion ?? "-"} - 模块 {runtimeQuery.data?.runtimeModules?.length ?? 0} - 能力 {runtimeQuery.data?.runtimeCapabilities?.length ?? 0} - - 公开业务{" "} - {runtimeQuery.data?.runtimeOfferings?.length ?? - runtimeQuery.data?.offerings?.length ?? - 0} - + 能力 {runtimeQuery.data?.capabilities?.length ?? 0} + 公开业务 {runtimeQuery.data?.offerings?.length ?? 0} 插件 {runtimeQuery.data?.plugins?.length ?? 0} diff --git a/apps/api/prisma/migrations/20260927100000_normalize_trust_content_types/migration.sql b/apps/api/prisma/migrations/20260927100000_normalize_trust_content_types/migration.sql new file mode 100644 index 0000000..1fb416a --- /dev/null +++ b/apps/api/prisma/migrations/20260927100000_normalize_trust_content_types/migration.sql @@ -0,0 +1,2 @@ +UPDATE "TrustContent" SET "type" = 'credential' WHERE "type" IN ('profile', 'experience'); +UPDATE "TrustContent" SET "type" = 'case' WHERE "type" IN ('portfolio', 'testimonial'); diff --git a/apps/api/src/admin-workspace.controller.ts b/apps/api/src/admin-workspace.controller.ts index cfddd7d..24b4c01 100644 --- a/apps/api/src/admin-workspace.controller.ts +++ b/apps/api/src/admin-workspace.controller.ts @@ -184,6 +184,7 @@ class AdminWorkspaceController { displayName: manifest.displayName, admin: manifest.admin, assetSlots: manifest.assetSlots, + trustContentTypes: manifest.trustContentTypes ?? [], } : null, }; diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 31e9923..3d11e70 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -826,6 +826,8 @@ test("admin can install a template and public workspace exposes enabled configur assert.equal(JSON.parse(workspace.body).fields.length, 5); const templateContent = JSON.parse(workspace.body).templateContent; assert.equal(templateContent.displayName, "阿成校园餐"); + assert.ok(templateContent.trustContentTypes.some((item) => item.type === "schedule")); + assert.ok(templateContent.trustContentTypes.some((item) => item.label === "出摊与营业安排")); assert.ok(templateContent.admin.sections.some((section) => section.title === "首页出摊信息")); assert.ok( templateContent.admin.sections diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index f0523f0..7af8bb8 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -87,6 +87,7 @@ export interface TemplateAdminSection { export interface AdminTemplateContent { displayName: string; admin: { sections: TemplateAdminSection[] }; + trustContentTypes?: Array<{ type: string; label: string; help?: string; placeholder?: string }>; assetSlots: Array<{ key: string; binding: string; diff --git a/packages/config/src/generated-template-packages.js b/packages/config/src/generated-template-packages.js index 423376b..3b0bf83 100644 --- a/packages/config/src/generated-template-packages.js +++ b/packages/config/src/generated-template-packages.js @@ -288,6 +288,41 @@ export const generatedTemplatePackageRegistry = [ } ] }, + "trustContentTypes": [ + { + "type": "schedule", + "label": "出摊与营业安排", + "help": "说明固定出摊时间、临时营业安排或接受预订的时段。", + "placeholder": "例如:周一至周五 17:00 - 22:30" + }, + { + "type": "coverage", + "label": "取餐与配送范围", + "help": "说明服务地点、取餐方式和可配送范围。", + "placeholder": "例如:支持校内宿舍楼下配送" + }, + { + "type": "process", + "label": "定制餐品流程", + "help": "每行写一步,从提出需求到完成交付。", + "placeholder": "例如:提交需求\n确认菜单\n制作交付" + }, + { + "type": "credential", + "label": "食品安全与制作标准", + "help": "填写让顾客放心的资质、卫生或制作标准。" + }, + { + "type": "case", + "label": "客户案例与反馈", + "help": "填写代表性订单、活动案例或客户评价。" + }, + { + "type": "promise", + "label": "回复与服务承诺", + "help": "说明回复时间、退改规则或服务承诺。" + } + ], "sampleContent": { "food": { "templateKey": "food", @@ -681,6 +716,39 @@ export const generatedTemplatePackageRegistry = [ } ] }, + "trustContentTypes": [ + { + "type": "schedule", + "label": "服务与合作安排", + "help": "说明可预约时间、服务周期或项目排期。" + }, + { + "type": "coverage", + "label": "服务范围与适用对象", + "help": "说明服务地区、项目类型或合作边界。" + }, + { + "type": "process", + "label": "合作流程", + "help": "每行写一步,从初次沟通到交付完成。", + "placeholder": "例如:需求沟通\n方案确认\n落地交付" + }, + { + "type": "credential", + "label": "专业资历与方法", + "help": "填写经验、资质、专业标准或工作方法。" + }, + { + "type": "case", + "label": "项目案例与客户反馈", + "help": "填写代表性项目、成果或客户评价。" + }, + { + "type": "promise", + "label": "合作预期与响应承诺", + "help": "说明回复时间、合作边界和后续跟进方式。" + } + ], "sampleContent": { "doors": { "templateKey": "doors", @@ -912,4 +980,4 @@ export const generatedTemplatePackageRegistry = [ } ]; export const generatedTemplatePackageRegistryHash = - "ebcac61077ff8d4097065555e86c651b93f99f91196b55b9503a13c6dcb9631a"; + "afbd1045ccdc7eda85bd9707ce27083ba699899f115a26a3c60459a88a5e5148"; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index f6261ba..37f9d1d 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -225,6 +225,12 @@ export interface TemplatePackageManifest { fields: readonly { key: string; binding: string; label: string; required?: boolean }[]; }[]; }; + trustContentTypes?: readonly { + type: string; + label: string; + help?: string; + placeholder?: string; + }[]; sampleContent?: Partial>; } diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json index 63ce1ef..bb92bae 100644 --- a/packages/template-acheng-campus-food/template.json +++ b/packages/template-acheng-campus-food/template.json @@ -281,6 +281,14 @@ } ] }, + "trustContentTypes": [ + { "type": "schedule", "label": "出摊与营业安排", "help": "说明固定出摊时间、临时营业安排或接受预订的时段。", "placeholder": "例如:周一至周五 17:00 - 22:30" }, + { "type": "coverage", "label": "取餐与配送范围", "help": "说明服务地点、取餐方式和可配送范围。", "placeholder": "例如:支持校内宿舍楼下配送" }, + { "type": "process", "label": "定制餐品流程", "help": "每行写一步,从提出需求到完成交付。", "placeholder": "例如:提交需求\n确认菜单\n制作交付" }, + { "type": "credential", "label": "食品安全与制作标准", "help": "填写让顾客放心的资质、卫生或制作标准。" }, + { "type": "case", "label": "客户案例与反馈", "help": "填写代表性订单、活动案例或客户评价。" }, + { "type": "promise", "label": "回复与服务承诺", "help": "说明回复时间、退改规则或服务承诺。" } + ], "sampleContent": { "food": { "templateKey": "food", diff --git a/packages/template-contract/src/index.ts b/packages/template-contract/src/index.ts index b9b7ed1..27b77a6 100644 --- a/packages/template-contract/src/index.ts +++ b/packages/template-contract/src/index.ts @@ -64,6 +64,13 @@ export type TemplateAdminManifest = { sections: TemplateAdminSection[]; }; +export type TemplateTrustContentType = { + type: "schedule" | "coverage" | "process" | "credential" | "case" | "promise" | (string & {}); + label: string; + help?: string; + placeholder?: string; +}; + export type TemplateSampleContent = { templateKey: string; offerings: Array>; @@ -96,6 +103,7 @@ export type TemplatePackageManifest = { dataSlots: TemplateDataSlot[]; assetSlots: TemplateAssetSlot[]; admin: TemplateAdminManifest; + trustContentTypes?: TemplateTrustContentType[]; sampleContent?: Record; }; @@ -125,6 +133,22 @@ export function validateTemplatePackageManifest(value: unknown): string[] { errors.push("data slot source is invalid"); } } + if (manifest.trustContentTypes !== undefined) { + if (!Array.isArray(manifest.trustContentTypes)) + errors.push("trustContentTypes must be an array"); + else { + for (const [index, item] of manifest.trustContentTypes.entries()) { + if (!item || typeof item !== "object") { + errors.push(`trustContentTypes.${index} must be an object`); + continue; + } + if (typeof item.type !== "string" || !item.type.trim()) + errors.push(`trustContentTypes.${index}.type is required`); + if (typeof item.label !== "string" || !item.label.trim()) + errors.push(`trustContentTypes.${index}.label is required`); + } + } + } if (!Array.isArray(manifest.assetSlots)) errors.push("assetSlots must be an array"); else { for (const slot of manifest.assetSlots) { diff --git a/packages/template-linjing-editorial/template.json b/packages/template-linjing-editorial/template.json index 7e82a24..d5769b7 100644 --- a/packages/template-linjing-editorial/template.json +++ b/packages/template-linjing-editorial/template.json @@ -269,6 +269,14 @@ } ] }, + "trustContentTypes": [ + { "type": "schedule", "label": "服务与合作安排", "help": "说明可预约时间、服务周期或项目排期。" }, + { "type": "coverage", "label": "服务范围与适用对象", "help": "说明服务地区、项目类型或合作边界。" }, + { "type": "process", "label": "合作流程", "help": "每行写一步,从初次沟通到交付完成。", "placeholder": "例如:需求沟通\n方案确认\n落地交付" }, + { "type": "credential", "label": "专业资历与方法", "help": "填写经验、资质、专业标准或工作方法。" }, + { "type": "case", "label": "项目案例与客户反馈", "help": "填写代表性项目、成果或客户评价。" }, + { "type": "promise", "label": "合作预期与响应承诺", "help": "说明回复时间、合作边界和后续跟进方式。" } + ], "sampleContent": { "doors": { "templateKey": "doors",