From d1958a7d7f8621675ebd8a775c45781dbcbe93ff Mon Sep 17 00:00:00 2001 From: que01 Date: Sat, 17 Oct 2026 13:56:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=98=B6=E6=AE=B54=E9=97=AD=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/publication/PublicationPage.tsx | 10 +- .../publication/use-publication-mutations.ts | 23 +- .../publication/use-publication-queries.ts | 10 +- .../migration.sql | 43 ++ apps/api/prisma/schema.prisma | 47 +- apps/api/prisma/seed.ts | 44 +- apps/api/src/admin.dto.ts | 13 + apps/api/src/brand-release-api.service.ts | 43 +- apps/api/src/brand-release.service.ts | 7 +- .../workspace/admin-capability.controller.ts | 22 +- .../workspace/admin-sample-content.service.ts | 537 +++++++++++++----- .../admin-workspace-preview.controller.ts | 6 +- .../workspace/admin-workspace.service.ts | 5 +- apps/api/src/template-workspace.service.ts | 53 +- apps/api/test/http.integration.test.js | 145 +++-- config/template-build.json | 2 +- docs/template-management-delivery-plan.md | 16 +- docs/template-registry.md | 2 +- packages/api-client/src/resources/template.ts | 77 ++- .../config/src/generated-template-packages.ts | 221 ++++++- .../config/src/template-sample-content.ts | 2 + .../template-acheng-campus-food/template.json | 19 + .../template-atelier-solopreneur/package.json | 2 +- .../template.json | 5 +- packages/template-contract/src/index.ts | 2 +- .../template-linjing-editorial/template.json | 133 ++++- 26 files changed, 1179 insertions(+), 310 deletions(-) create mode 100644 apps/api/prisma/migrations/20261016220000_template_bootstrap_imports/migration.sql diff --git a/apps/admin/src/features/publication/PublicationPage.tsx b/apps/admin/src/features/publication/PublicationPage.tsx index 1cb17f4..9a66620 100644 --- a/apps/admin/src/features/publication/PublicationPage.tsx +++ b/apps/admin/src/features/publication/PublicationPage.tsx @@ -333,7 +333,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool @@ -346,7 +346,11 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool )} {sample.data && !sample.data.alreadyImported && (

- 将向草稿添加{" "} + 来源:{sample.data.source.packageKey}@{sample.data.source.version} + {sample.data.source.contentChecksum + ? `(checksum ${sample.data.source.contentChecksum.slice(0, 12)})` + : "(兼容 registry 来源)"} + 。将向草稿添加{" "} {Object.entries(sample.data.counts) .map(([key, count]) => `${key} ${count} 项`) .join("、")} @@ -582,7 +586,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool title="确认安装行业模板" open={industryTarget !== null} onCancel={() => setIndustryTarget(null)} - onOk={() => industryTarget && install.mutate(industryTarget)} + onOk={() => industryTarget && install.mutate({ key: industryTarget })} confirmLoading={install.isPending} > 模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。 diff --git a/apps/admin/src/features/publication/use-publication-mutations.ts b/apps/admin/src/features/publication/use-publication-mutations.ts index 4754adb..af200df 100644 --- a/apps/admin/src/features/publication/use-publication-mutations.ts +++ b/apps/admin/src/features/publication/use-publication-mutations.ts @@ -24,7 +24,8 @@ export function usePublicationMutations({ }: MutationOptions) { const queryClient = useQueryClient(); const install = useMutation({ - mutationFn: (key: BrandTemplateKey) => client.installAdminTemplate(key), + mutationFn: ({ key, versionId }: { key: BrandTemplateKey; versionId?: string }) => + client.installAdminTemplate(key, versionId), onSuccess: () => { onInstallClose(); message.success("行业模板已安装"); @@ -55,9 +56,23 @@ export function usePublicationMutations({ refresh(); }, }); - const importSample = useMutation>>({ - mutationFn: () => client.importAdminSampleContent(), - onSuccess: ({ counts }) => { + const importSample = useMutation< + Awaited>, + Error, + string | undefined + >({ + mutationFn: (templatePackageVersionId) => + client.importAdminSampleContent({ + ...(templatePackageVersionId ? { templatePackageVersionId } : {}), + strategy: "missing_only", + confirm: true, + }), + onSuccess: ({ counts, alreadyImported }) => { + if (alreadyImported) { + message.info("该模板包版本的示例内容已导入,未重复创建"); + refresh(); + return; + } message.success( counts.inquiryForms ? "示例内容和客户咨询表单已导入草稿" diff --git a/apps/admin/src/features/publication/use-publication-queries.ts b/apps/admin/src/features/publication/use-publication-queries.ts index b01fe7f..5a5d5c6 100644 --- a/apps/admin/src/features/publication/use-publication-queries.ts +++ b/apps/admin/src/features/publication/use-publication-queries.ts @@ -25,8 +25,14 @@ export function usePublicationQueries( queryFn: () => client.listPublicTemplates(), }); const sample = useQuery>>({ - queryKey: ["publication-sample"], - queryFn: () => client.previewAdminSampleContent(), + queryKey: ["publication-sample", workspace.data?.installations[0]?.templatePackageVersionId], + queryFn: () => + client.previewAdminSampleContent({ + ...(workspace.data?.installations[0]?.templatePackageVersionId + ? { templatePackageVersionId: workspace.data.installations[0].templatePackageVersionId } + : {}), + strategy: "missing_only", + }), enabled: Boolean(workspace.data), }); const readiness = useQuery>>({ diff --git a/apps/api/prisma/migrations/20261016220000_template_bootstrap_imports/migration.sql b/apps/api/prisma/migrations/20261016220000_template_bootstrap_imports/migration.sql new file mode 100644 index 0000000..df81b07 --- /dev/null +++ b/apps/api/prisma/migrations/20261016220000_template_bootstrap_imports/migration.sql @@ -0,0 +1,43 @@ +-- AlterTable +ALTER TABLE "BrandTemplateInstallation" ADD COLUMN "contentChecksum" TEXT, +ADD COLUMN "templatePackageVersionId" TEXT, +ADD COLUMN "visualTemplateKey" TEXT; + +-- CreateTable +CREATE TABLE "TemplateBootstrapImport" ( + "id" TEXT NOT NULL, + "brandId" TEXT NOT NULL, + "templatePackageVersionId" TEXT NOT NULL, + "packageKey" TEXT NOT NULL, + "packageVersion" TEXT NOT NULL, + "contentChecksum" TEXT NOT NULL, + "actorId" TEXT NOT NULL, + "strategy" TEXT NOT NULL DEFAULT 'missing_only', + "status" TEXT NOT NULL, + "result" JSONB, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "TemplateBootstrapImport_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "BrandTemplateInstallation_templatePackageVersionId_idx" ON "BrandTemplateInstallation"("templatePackageVersionId"); + +-- CreateIndex +CREATE INDEX "TemplateBootstrapImport_brandId_createdAt_idx" ON "TemplateBootstrapImport"("brandId", "createdAt"); + +-- CreateIndex +CREATE INDEX "TemplateBootstrapImport_templatePackageVersionId_createdAt_idx" ON "TemplateBootstrapImport"("templatePackageVersionId", "createdAt"); + +-- CreateIndex +CREATE INDEX "TemplateBootstrapImport_actorId_createdAt_idx" ON "TemplateBootstrapImport"("actorId", "createdAt"); + +-- AddForeignKey +ALTER TABLE "BrandTemplateInstallation" ADD CONSTRAINT "BrandTemplateInstallation_templatePackageVersionId_fkey" FOREIGN KEY ("templatePackageVersionId") REFERENCES "TemplatePackageVersion"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "TemplateBootstrapImport" ADD CONSTRAINT "TemplateBootstrapImport_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "TemplateBootstrapImport" ADD CONSTRAINT "TemplateBootstrapImport_templatePackageVersionId_fkey" FOREIGN KEY ("templatePackageVersionId") REFERENCES "TemplatePackageVersion"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 5b153f9..317567f 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -65,6 +65,7 @@ model BrandProfile { adminMemberships BrandMembership[] releases BrandRelease[] miniAppReleases MiniAppReleaseTask[] + bootstrapImports TemplateBootstrapImport[] } model BrandRelease { @@ -167,18 +168,23 @@ model CapabilityAuditLog { } model BrandTemplateInstallation { - id String @id @default(uuid()) - brandId String - brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade) - templateKey String - templateVersion String @default("1.0.0") - configSnapshot Json - previousSnapshots Json @default("[]") - installedAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @default(uuid()) + brandId String + brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade) + templateKey String + templateVersion String @default("1.0.0") + visualTemplateKey String? + templatePackageVersionId String? + templatePackageVersion TemplatePackageVersion? @relation("BrandTemplateInstallationPackageVersion", fields: [templatePackageVersionId], references: [id], onDelete: SetNull) + contentChecksum String? + configSnapshot Json + previousSnapshots Json @default("[]") + installedAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@unique([brandId, templateKey]) @@index([brandId]) + @@index([templatePackageVersionId]) } model BrandFieldDefinition { @@ -433,6 +439,8 @@ model TemplatePackageVersion { importedById String importedBy AdminUser @relation("TemplatePackageImportedBy", fields: [importedById], references: [id], onDelete: Restrict) auditLogs TemplatePackageAuditLog[] + installations BrandTemplateInstallation[] @relation("BrandTemplateInstallationPackageVersion") + bootstrapImports TemplateBootstrapImport[] importedAt DateTime @default(now()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -442,6 +450,27 @@ model TemplatePackageVersion { @@index([importedById, importedAt]) } +model TemplateBootstrapImport { + id String @id @default(uuid()) + brandId String + brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade) + templatePackageVersionId String + templatePackageVersion TemplatePackageVersion @relation(fields: [templatePackageVersionId], references: [id], onDelete: Restrict) + packageKey String + packageVersion String + contentChecksum String + actorId String + strategy String @default("missing_only") + status String + result Json? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@index([brandId, createdAt]) + @@index([templatePackageVersionId, createdAt]) + @@index([actorId, createdAt]) +} + model TemplatePackageAuditLog { id String @id @default(uuid()) templatePackageVersionId String diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index df9c27c..7108524 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -643,23 +643,29 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem }; async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise { - // 这里只初始化明确的开发演示品牌;餐饮结构化槽位和表单取自对应 package, + // 这里只初始化明确的开发演示品牌;业务内容统一来自视觉包 sampleContent, // 新增生产模板无需添加 seed 分支,品牌样例内容仍须由管理员显式导入。 - const offerings = template.offerings; - const foodSample = - template.templateKey === "food" - ? getTemplatePackageManifestForVisualKey("acheng-campus-food")?.sampleContent?.food - : undefined; - if (template.templateKey === "food" && !foodSample) - throw new Error("Food development sample is missing"); - const trustContent = foodSample - ? foodSample.trustContent.map((item) => { - const fixture = template.trustContent.find((entry) => entry.type === item.type); - return { ...item, ...fixture, config: { ...item.config, ...fixture?.config } }; - }) - : template.trustContent; - const inquiryFields = foodSample?.fields ?? template.inquiryForm?.fieldsSnapshot; - const inquiryFormName = foodSample?.inquiryFormName ?? template.inquiryForm?.name; + const visualKey = template.templateKey === "food" ? "acheng-campus-food" : "linjing-editorial"; + const packageSample = + getTemplatePackageManifestForVisualKey(visualKey)?.sampleContent?.[template.templateKey]; + if (!packageSample) + throw new Error(`Development sample is missing for ${visualKey}/${template.templateKey}`); + const offerings = packageSample.offerings.map((item) => ({ + name: item.name, + summary: item.summary, + image: item.coverUrl ?? "", + kind: item.kind as OfferingKind, + priceText: item.priceText, + priceAmount: item.priceAmount, + config: { categoryKey: item.categoryKey, ...(item.config ?? {}) }, + })); + const trustContent = packageSample.trustContent; + const inquiryFields = packageSample.fields; + const inquiryFormName = packageSample.inquiryFormName; + const seedBrandConfig = { + ...(packageSample.brandConfig ?? {}), + ...template.brandConfig, + }; if (!inquiryFields?.length || !inquiryFormName) throw new Error("Development inquiry fixture is missing"); const existingBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } }); @@ -672,7 +678,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla await prisma.brandProfile.update({ where: { id: brandId }, data: { - config: { ...existingConfig, ...template.brandConfig } as Prisma.InputJsonValue, + config: { ...existingConfig, ...seedBrandConfig } as Prisma.InputJsonValue, ...(existingBrand.slug === "default-brand" && !existingBrand.avatarUrl ? { avatarUrl: "/assets/owner/portrait.jpg" } : {}), @@ -710,7 +716,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla select: { id: true, name: true }, }); for (const [index, item] of incompleteOfferings.entries()) { - const image = template.offerings[index % template.offerings.length]?.image; + const image = offerings[index % offerings.length]?.image; if (!image) throw new Error("Development fixture has no offering image"); await prisma.offering.update({ where: { id: item.id }, @@ -727,7 +733,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla } for (const [sortOrder, item] of trustContent.entries()) { const existing = await prisma.trustContent.findFirst({ - where: { brandId, type: item.type }, + where: { brandId, type: item.type, title: item.title }, orderBy: [{ isPublished: "desc" }, { sortOrder: "asc" }], }); const { config, ...fields } = item; diff --git a/apps/api/src/admin.dto.ts b/apps/api/src/admin.dto.ts index 727ef48..acfb61e 100644 --- a/apps/api/src/admin.dto.ts +++ b/apps/api/src/admin.dto.ts @@ -1,6 +1,7 @@ import { IsArray, IsBoolean, + IsUUID, IsIn, IsInt, IsObject, @@ -103,6 +104,18 @@ export class UpdateBookingTagsDto { export class InstallTemplateDto { @IsIn(brandTemplateKeys) templateKey!: BrandTemplateKey; + @IsOptional() @IsUUID() templatePackageVersionId?: string; +} + +export class PreviewTemplateSampleDto { + @IsOptional() @IsUUID() templatePackageVersionId?: string; + @IsOptional() @IsIn(["missing_only"]) strategy?: "missing_only"; +} + +export class ImportTemplateSampleDto { + @IsOptional() @IsUUID() templatePackageVersionId?: string; + @IsIn(["missing_only"]) strategy!: "missing_only"; + @IsBoolean() confirm!: boolean; } export class UpdateCapabilityInstallationDto { diff --git a/apps/api/src/brand-release-api.service.ts b/apps/api/src/brand-release-api.service.ts index c33a13c..8efd1e1 100644 --- a/apps/api/src/brand-release-api.service.ts +++ b/apps/api/src/brand-release-api.service.ts @@ -12,6 +12,8 @@ import { isVisualTemplateCompatible, getDefaultVisualTemplateKey, getTemplatePackageManifestForVisualKey, + validateTemplatePackageManifest, + type TemplatePackageManifest, } from "@personal-brand/config"; import { isTrustContentComplete } from "@personal-brand/types"; import { PrismaService } from "./prisma.service.js"; @@ -63,6 +65,19 @@ export class BrandReleaseApiService { where: { brandId }, orderBy: { updatedAt: "desc" }, }); + const packageVersion = installation?.templatePackageVersionId + ? await database.templatePackageVersion.findUnique({ + where: { id: installation.templatePackageVersionId }, + select: { + packageKey: true, + version: true, + visualTemplateKey: true, + status: true, + contentChecksum: true, + manifestSnapshot: true, + }, + }) + : null; const template = getBrandTemplate(installation?.templateKey ?? brand?.templateKey ?? ""); const config = this.jsonObject(brand?.config); const visualKey = @@ -70,7 +85,22 @@ export class BrandReleaseApiService { ? config.visualTemplateKey : getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey); const visual = getVisualTemplate(visualKey); - const packageManifest = getTemplatePackageManifestForVisualKey(visualKey); + const storedManifest = packageVersion?.manifestSnapshot as unknown as + TemplatePackageManifest | undefined; + const packageManifest = storedManifest ?? getTemplatePackageManifestForVisualKey(visualKey); + const packageVersionValid = + !installation?.templatePackageVersionId || + Boolean( + packageVersion && + packageVersion.status === "published" && + /^[a-f0-9]{64}$/.test(packageVersion.contentChecksum) && + packageVersion.packageKey === (storedManifest?.packageKey ?? "") && + packageVersion.version === (storedManifest?.version ?? "") && + (packageVersion.visualTemplateKey ?? packageVersion.packageKey) === + (storedManifest?.visualTemplateKey ?? packageVersion.packageKey) && + storedManifest?.supportedIndustryTemplates.includes(brand?.templateKey ?? "") && + validateTemplatePackageManifest(storedManifest).length === 0, + ); const [offerings, forms, trustItems] = await Promise.all([ database.offering.findMany({ where: { brandId, isEnabled: true }, @@ -124,6 +154,17 @@ export class BrandReleaseApiService { destination: "/admin/brand", }, { key: "template", label: "行业模板配置", passed: Boolean(template) }, + { + key: "template-package-version", + label: "模板包版本台账", + passed: packageVersionValid, + ...(packageVersionValid + ? {} + : { + help: "当前安装记录引用的模板包版本不可用、未发布或与 manifest 不一致,请重新安装已发布版本。", + }), + destination: "/admin/publication", + }, { key: "visual", label: "视觉模板与行业模板的适配", diff --git a/apps/api/src/brand-release.service.ts b/apps/api/src/brand-release.service.ts index 9287515..04899f5 100644 --- a/apps/api/src/brand-release.service.ts +++ b/apps/api/src/brand-release.service.ts @@ -38,6 +38,7 @@ export async function buildBrandReleaseSnapshot( database.brandTemplateInstallation.findFirst({ where: { brandId }, orderBy: { updatedAt: "desc" }, + include: { templatePackageVersion: true }, }), database.brandFieldDefinition.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }), database.offering.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }), @@ -63,7 +64,11 @@ export async function buildBrandReleaseSnapshot( templateDefinition: getBrandTemplate(templateKey) ?? null, visualTemplateDefinition: getVisualTemplate(visualKey) ?? null, visualTemplateManifest: getVisualTemplateManifest(visualKey) ?? null, - templatePackageManifest: getTemplatePackageManifestForVisualKey(visualKey) ?? null, + templatePackageManifest: + (installation?.templatePackageVersion?.manifestSnapshot as unknown as + TemplatePackageManifest | undefined) ?? + getTemplatePackageManifestForVisualKey(visualKey) ?? + null, brand: brand ? jsonObject(brand) : null, installation: installation ? jsonObject(installation) : null, fields: fields.map((item) => jsonObject(item)), diff --git a/apps/api/src/modules/workspace/admin-capability.controller.ts b/apps/api/src/modules/workspace/admin-capability.controller.ts index d2e8b27..c63d305 100644 --- a/apps/api/src/modules/workspace/admin-capability.controller.ts +++ b/apps/api/src/modules/workspace/admin-capability.controller.ts @@ -1,6 +1,10 @@ -import { Body, Controller, Get, Param, Patch, Post, Req } from "@nestjs/common"; +import { Body, Controller, Get, Param, Patch, Post, Query, Req } from "@nestjs/common"; import type { FastifyRequest } from "fastify"; -import { UpdateCapabilityInstallationDto } from "../../admin.dto.js"; +import { + ImportTemplateSampleDto, + PreviewTemplateSampleDto, + UpdateCapabilityInstallationDto, +} from "../../admin.dto.js"; import { requireAdminIdentity } from "./admin-access.identity.js"; import { AdminSampleContentService } from "./admin-sample-content.service.js"; import { AdminWorkspaceCapabilitiesService } from "./admin-workspace-capabilities.service.js"; @@ -18,14 +22,20 @@ class AdminCapabilityController { } @Get("sample-content/preview") - previewSampleContent(@Req() request: FastifyRequest): Promise { - return this.sampleContentService.preview(requireAdminIdentity(request).brandId); + previewSampleContent( + @Req() request: FastifyRequest, + @Query() query: PreviewTemplateSampleDto, + ): Promise { + return this.sampleContentService.preview(requireAdminIdentity(request).brandId, query); } @Post("sample-content/import") - importSampleContent(@Req() request: FastifyRequest): Promise { + importSampleContent( + @Req() request: FastifyRequest, + @Body() body: ImportTemplateSampleDto, + ): Promise { const identity = requireAdminIdentity(request); - return this.sampleContentService.import(identity.brandId, identity.subject); + return this.sampleContentService.import(identity.brandId, identity.subject, body); } @Patch("capabilities/:key") diff --git a/apps/api/src/modules/workspace/admin-sample-content.service.ts b/apps/api/src/modules/workspace/admin-sample-content.service.ts index 00783ba..e04e2ec 100644 --- a/apps/api/src/modules/workspace/admin-sample-content.service.ts +++ b/apps/api/src/modules/workspace/admin-sample-content.service.ts @@ -1,181 +1,424 @@ -import { BadRequestException, Injectable } from "@nestjs/common"; -import { Prisma } from "@prisma/client"; -import { getTemplateSampleContent, getDefaultVisualTemplateKey } from "@personal-brand/config"; +import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common"; +import { Prisma, type TemplatePackageVersion } from "@prisma/client"; +import { + getDefaultVisualTemplateKey, + getTemplatePackageManifestForVisualKey, + getTemplateSampleContent, + getVisualTemplate, + isVisualTemplateCompatible, + validateTemplatePackageManifest, + type TemplatePackageManifest, + type TemplateSampleContent, +} from "@personal-brand/config"; import { validateFieldSnapshot } from "@personal-brand/validation"; import { PrismaService } from "../../prisma.service.js"; import { TemplateWorkspaceService } from "../../template-workspace.service.js"; +type BootstrapSource = { + kind: "package_version" | "registry"; + manifest: TemplatePackageManifest; + sample: TemplateSampleContent; + version?: TemplatePackageVersion; +}; + +type Counts = { + brandConfig: number; + offerings: number; + trustContent: number; + fields: number; + inquiryForms: number; +}; +type Action = { type: keyof Counts; key: string; action: "create" | "skip" }; + +function record(value: unknown): Record { + return value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; +} + +function deepMergeMissing( + defaults: Record, + saved: Record, + path = "", +): { value: Record; missingPaths: string[] } { + const value = { ...saved }; + const missingPaths: string[] = []; + for (const [key, fallback] of Object.entries(defaults)) { + const currentPath = path ? `${path}.${key}` : key; + if (!Object.prototype.hasOwnProperty.call(saved, key)) { + value[key] = fallback; + missingPaths.push(currentPath); + continue; + } + const current = saved[key]; + if ( + fallback && + current && + typeof fallback === "object" && + typeof current === "object" && + !Array.isArray(fallback) && + !Array.isArray(current) + ) { + const nested = deepMergeMissing( + fallback as Record, + current as Record, + currentPath, + ); + value[key] = nested.value; + missingPaths.push(...nested.missingPaths); + } + } + return { value, missingPaths }; +} + +function asJson(value: unknown): Prisma.InputJsonValue { + return value as Prisma.InputJsonValue; +} + @Injectable() export class AdminSampleContentService { constructor( private readonly prisma: PrismaService, - private readonly templateWorkspace: TemplateWorkspaceService, + _templateWorkspace: TemplateWorkspaceService, ) {} - async preview(brandId: string) { - const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(brandId); - const brand = await this.prisma.brandProfile.findUnique({ - where: { id: brandId }, - select: { config: true }, - }); - const config = - brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config) - ? (brand.config as Record) - : {}; - const sample = getTemplateSampleContent( - templateKey, - typeof config.visualTemplateKey === "string" - ? config.visualTemplateKey - : getDefaultVisualTemplateKey(templateKey), + async preview(brandId: string, query?: { templatePackageVersionId?: string }) { + const { brand, source, visualTemplateKey } = await this.resolveSource( + brandId, + query?.templatePackageVersionId, ); - if (!sample) throw new BadRequestException("模板示例内容不存在"); - const [offerings, trustContent, fields, enabledForms] = await Promise.all([ - this.prisma.offering.count({ where: { brandId } }), - this.prisma.trustContent.count({ where: { brandId } }), - this.prisma.brandFieldDefinition.count({ where: { brandId, source: "sample" } }), - this.prisma.inquiryForm.count({ where: { brandId, isEnabled: true } }), - ]); + const plan = await this.buildPlan(brandId, brand.config, source); return { - templateKey: sample.templateKey, - alreadyImported: offerings > 0 || trustContent > 0 || fields > 0, - counts: { - offerings: sample.offerings.length, - trustContent: sample.trustContent.length, - fields: sample.fields.length, - inquiryForms: 1, - }, - willCreateInquiryForm: enabledForms === 0, + templateKey: source.sample.templateKey, + visualTemplateKey, + source: this.publicSource(source), + alreadyImported: plan.alreadyImported, + willCreateInquiryForm: plan.counts.inquiryForms > 0, + counts: plan.counts, + skipped: plan.skipped, + plan: plan.actions, + missingConfigKeys: plan.missingConfigKeys, }; } - async import(brandId: string, actorId: string) { - const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(brandId); - const brand = await this.prisma.brandProfile.findUnique({ - where: { id: brandId }, - select: { config: true }, + async import( + brandId: string, + actorId: string, + body: { templatePackageVersionId?: string; strategy: "missing_only"; confirm: boolean }, + ) { + if (body.confirm !== true) throw new BadRequestException("导入示例内容必须显式确认"); + if (body.strategy !== "missing_only") + throw new BadRequestException("当前只支持 missing_only 导入策略"); + + const { brand, source } = await this.resolveSource(brandId, body.templatePackageVersionId); + if (!source.version) + throw new BadRequestException("品牌尚未安装可追溯的已发布模板包版本,不能导入示例内容"); + const plan = await this.buildPlan(brandId, brand.config, source); + const priorImport = await this.prisma.templateBootstrapImport.findFirst({ + where: { + brandId, + templatePackageVersionId: source.version.id, + contentChecksum: source.version.contentChecksum, + status: "imported", + }, + orderBy: { createdAt: "desc" }, }); - const config = - brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config) - ? (brand.config as Record) - : {}; - const sample = getTemplateSampleContent( - templateKey, - typeof config.visualTemplateKey === "string" - ? config.visualTemplateKey - : getDefaultVisualTemplateKey(templateKey), - ); - if (!sample) throw new BadRequestException("模板示例内容不存在"); - if (validateFieldSnapshot(sample.fields).length) - throw new BadRequestException("模板咨询表单示例字段无效"); - const existing = await this.prisma.brandFieldDefinition.count({ - where: { brandId, source: "sample" }, - }); - const existingOffering = await this.prisma.offering.count({ - where: { brandId, name: { in: sample.offerings.map((item) => item.name) } }, - }); - if (existing || existingOffering) throw new BadRequestException("示例内容已经导入"); + if (priorImport) { + return { + imported: true, + alreadyImported: true, + source: this.publicSource(source), + counts: priorImport.result ?? plan.counts, + }; + } + const result = await this.prisma.$transaction(async (tx) => { - if (sample.brandConfig) { - // 仅显式导入时补齐缺失配置,已有品牌内容(包括空值)始终优先。 - const merge = ( - defaults: Record, - saved: Record, - ): Record => - Object.fromEntries( - [...new Set([...Object.keys(defaults), ...Object.keys(saved)])].map((key) => { - const a = defaults[key]; - const b = saved[key]; - if (!Object.prototype.hasOwnProperty.call(saved, key)) return [key, a]; - return [ - key, - a && - b && - typeof a === "object" && - typeof b === "object" && - !Array.isArray(a) && - !Array.isArray(b) - ? merge(a as Record, b as Record) - : b, - ]; - }), - ); + const counts: Counts = { + brandConfig: 0, + offerings: 0, + trustContent: 0, + fields: 0, + inquiryForms: 0, + }; + if (plan.missingConfigKeys.length) { + const merged = deepMergeMissing(record(source.sample.brandConfig), record(brand.config)); await tx.brandProfile.update({ where: { id: brandId }, - data: { config: merge(sample.brandConfig, config) as Prisma.InputJsonValue }, + data: { config: asJson(merged.value) }, }); + counts.brandConfig = merged.missingPaths.length; } - const offerings = await tx.offering.createMany({ - data: sample.offerings.map((item, sortOrder) => ({ + + for (const item of source.sample.offerings) { + const name = String(item.name ?? ""); + if (!name || plan.existingOfferingNames.has(name)) continue; + await tx.offering.create({ + data: { + brandId, + kind: String(item.kind ?? "service"), + name, + ...(typeof item.summary === "string" ? { summary: item.summary } : {}), + ...(typeof item.coverUrl === "string" ? { coverUrl: item.coverUrl } : {}), + ...(typeof item.priceText === "string" ? { priceText: item.priceText } : {}), + config: asJson({ + ...record(item.config), + ...(item.categoryKey ? { categoryKey: item.categoryKey } : {}), + }), + sortOrder: counts.offerings, + isEnabled: true, + }, + }); + counts.offerings += 1; + } + + for (const item of source.sample.trustContent) { + const type = String(item.type ?? ""); + const title = String(item.title ?? ""); + if (!type || !title || plan.existingTrustKeys.has(`${type}\0${title}`)) continue; + await tx.trustContent.create({ + data: { + brandId, + type, + title, + content: String(item.content ?? ""), + ...(typeof item.summary === "string" ? { summary: item.summary } : {}), + ...(item.config ? { config: asJson(item.config) } : {}), + sortOrder: counts.trustContent, + isPublished: false, + }, + }); + counts.trustContent += 1; + } + + for (const item of source.sample.fields) { + const key = String(item.key ?? ""); + if (!key || plan.existingFieldKeys.has(key)) continue; + await tx.brandFieldDefinition.create({ + data: { + brandId, + scope: "inquiry", + key, + label: String(item.label ?? key), + type: String(item.type ?? "text"), + sortOrder: counts.fields, + source: "sample", + required: item.required === true, + }, + }); + counts.fields += 1; + } + + if (plan.counts.inquiryForms) { + await tx.inquiryForm.create({ + data: { + brandId, + name: source.sample.inquiryFormName, + purpose: "inquiry", + targetType: "brand", + submissionAction: "create-inquiry", + fieldsSnapshot: asJson(source.sample.fields), + isEnabled: true, + }, + }); + counts.inquiryForms = 1; + } + + const importResult = { ...counts, skipped: plan.skipped, actions: plan.actions }; + await tx.templateBootstrapImport.create({ + data: { brandId, - kind: item.kind, - name: item.name, - summary: item.summary, - ...(item.coverUrl ? { coverUrl: item.coverUrl } : {}), - ...(item.priceText ? { priceText: item.priceText } : {}), - config: { ...item.config, categoryKey: item.categoryKey } as Prisma.InputJsonValue, - sortOrder, - isEnabled: true, - })), + templatePackageVersionId: source.version!.id, + packageKey: source.version!.packageKey, + packageVersion: source.version!.version, + contentChecksum: source.version!.contentChecksum, + actorId, + strategy: "missing_only", + status: "imported", + result: asJson(importResult), + }, }); - const trust = await tx.trustContent.createMany({ - data: sample.trustContent.map((item, sortOrder) => ({ - brandId, - type: item.type, - title: item.title, - content: item.content, - ...(item.config ? { config: item.config as Prisma.InputJsonValue } : {}), - sortOrder, - isPublished: false, - })), - }); - const fields = await tx.brandFieldDefinition.createMany({ - data: sample.fields.map((item, sortOrder) => ({ - brandId, - scope: "inquiry", - key: item.key, - label: item.label, - type: item.type, - sortOrder, - source: "sample", - required: item.required, - })), - }); - const hasEnabledForm = await tx.inquiryForm.count({ where: { brandId, isEnabled: true } }); - const inquiryForm = hasEnabledForm - ? null - : await tx.inquiryForm.create({ - data: { - brandId, - name: sample.inquiryFormName, - purpose: "inquiry", - targetType: "brand", - submissionAction: "create-inquiry", - fieldsSnapshot: sample.fields, - isEnabled: true, - }, - }); await tx.capabilityAuditLog.create({ data: { brandId, - capabilityKey: sample.capabilityKey, + capabilityKey: source.sample.capabilityKey, actorId, action: "sample_content_imported", toStatus: "enabled", - config: { - offerings: offerings.count, - trustContent: trust.count, - fields: fields.count, - inquiryForms: inquiryForm ? 1 : 0, - }, + config: asJson({ source: this.publicSource(source), ...importResult }), }, }); - return { - offerings: offerings.count, - trustContent: trust.count, - fields: fields.count, - inquiryForms: inquiryForm ? 1 : 0, - }; + return counts; }); - return { imported: true, counts: result }; + return { + imported: true, + alreadyImported: false, + source: this.publicSource(source), + counts: result, + }; + } + + private async resolveSource(brandId: string, requestedVersionId?: string) { + const brand = await this.prisma.brandProfile.findUnique({ + where: { id: brandId }, + select: { templateKey: true, config: true }, + }); + if (!brand) throw new NotFoundException("品牌不存在"); + const config = record(brand.config); + const visualTemplateKey = + typeof config.visualTemplateKey === "string" + ? config.visualTemplateKey + : getDefaultVisualTemplateKey(brand.templateKey); + const installation = requestedVersionId + ? null + : await this.prisma.brandTemplateInstallation.findFirst({ + where: { brandId }, + orderBy: { updatedAt: "desc" }, + select: { templatePackageVersionId: true }, + }); + const versionId = requestedVersionId ?? installation?.templatePackageVersionId ?? undefined; + let source: BootstrapSource; + if (versionId) { + const version = await this.prisma.templatePackageVersion.findUnique({ + where: { id: versionId }, + }); + if (!version) throw new BadRequestException("指定的模板包版本不存在"); + if (version.status !== "published") + throw new BadRequestException("只有已发布的模板包版本可用于 bootstrap"); + const manifest = version.manifestSnapshot as unknown as TemplatePackageManifest; + const issues = validateTemplatePackageManifest(manifest); + if (issues.length) + throw new BadRequestException(`模板包 manifest 无效:${issues.join(";")}`); + if ( + manifest.packageKey !== version.packageKey || + manifest.version !== version.version || + !/^[a-f0-9]{64}$/.test(version.contentChecksum) || + (version.visualTemplateKey ?? version.packageKey) !== + (manifest.visualTemplateKey ?? version.packageKey) || + !manifest.supportedIndustryTemplates.includes(brand.templateKey) + ) + throw new BadRequestException("模板包版本与品牌行业或版本台账不匹配"); + const sample = manifest.sampleContent?.[brand.templateKey]; + if (!sample) throw new BadRequestException("该模板包没有当前行业的 bootstrap sampleContent"); + source = { kind: "package_version", version, manifest, sample }; + } else { + const manifest = getTemplatePackageManifestForVisualKey(visualTemplateKey); + const sample = getTemplateSampleContent(brand.templateKey, visualTemplateKey); + if (!manifest || !sample || requestedVersionId) + throw new BadRequestException("当前模板没有可用的 bootstrap sampleContent"); + source = { kind: "registry", manifest, sample }; + } + const visual = getVisualTemplate(visualTemplateKey); + if (!visual || !isVisualTemplateCompatible(visual, brand.templateKey)) + throw new BadRequestException("当前视觉模板与品牌行业不兼容"); + if (source.sample.templateKey !== brand.templateKey) + throw new BadRequestException("sampleContent 行业与品牌不匹配"); + const fieldIssues = validateFieldSnapshot(source.sample.fields); + if (fieldIssues.length) + throw new BadRequestException(`bootstrap 表单字段无效:${fieldIssues.join(";")}`); + return { brand, source, visualTemplateKey }; + } + + private async buildPlan(brandId: string, savedConfig: unknown, source: BootstrapSource) { + const sample = source.sample; + const configMerge = deepMergeMissing(record(sample.brandConfig), record(savedConfig)); + const [offerings, trustContent, fields, enabledForm, previous] = await Promise.all([ + this.prisma.offering.findMany({ where: { brandId }, select: { name: true } }), + this.prisma.trustContent.findMany({ + where: { brandId }, + select: { type: true, title: true }, + }), + this.prisma.brandFieldDefinition.findMany({ + where: { brandId, scope: "inquiry" }, + select: { key: true }, + }), + this.prisma.inquiryForm.findFirst({ + where: { brandId, isEnabled: true }, + select: { id: true }, + }), + source.version + ? this.prisma.templateBootstrapImport.findFirst({ + where: { + brandId, + templatePackageVersionId: source.version.id, + contentChecksum: source.version.contentChecksum, + status: "imported", + }, + select: { id: true }, + }) + : Promise.resolve(null), + ]); + const offeringNames = new Set(offerings.map((item) => item.name)); + const trustKeys = new Set(trustContent.map((item) => `${item.type}\0${item.title}`)); + const fieldKeys = new Set(fields.map((item) => item.key)); + const actions: Action[] = []; + if (sample.brandConfig) { + for (const key of configMerge.missingPaths) + actions.push({ type: "brandConfig", key, action: "create" }); + } + for (const item of sample.offerings) { + const key = String(item.name ?? "(missing name)"); + actions.push({ + type: "offerings", + key, + action: key !== "(missing name)" && !offeringNames.has(key) ? "create" : "skip", + }); + } + for (const item of sample.trustContent) { + const type = String(item.type ?? ""); + const title = String(item.title ?? ""); + const key = `${type}/${title}`; + actions.push({ + type: "trustContent", + key, + action: type && title && !trustKeys.has(`${type}\0${title}`) ? "create" : "skip", + }); + } + for (const item of sample.fields) { + const key = String(item.key ?? "(missing key)"); + actions.push({ + type: "fields", + key, + action: key !== "(missing key)" && !fieldKeys.has(key) ? "create" : "skip", + }); + } + actions.push({ + type: "inquiryForms", + key: sample.inquiryFormName, + action: enabledForm ? "skip" : "create", + }); + const count = (type: keyof Counts, action: Action["action"]) => + actions.filter((item) => item.type === type && item.action === action).length; + return { + alreadyImported: Boolean(previous), + counts: { + brandConfig: count("brandConfig", "create"), + offerings: count("offerings", "create"), + trustContent: count("trustContent", "create"), + fields: count("fields", "create"), + inquiryForms: count("inquiryForms", "create"), + } satisfies Counts, + skipped: { + brandConfig: 0, + offerings: count("offerings", "skip"), + trustContent: count("trustContent", "skip"), + fields: count("fields", "skip"), + inquiryForms: count("inquiryForms", "skip"), + } satisfies Counts, + actions, + missingConfigKeys: configMerge.missingPaths, + existingOfferingNames: offeringNames, + existingTrustKeys: trustKeys, + existingFieldKeys: fieldKeys, + }; + } + + private publicSource(source: BootstrapSource) { + return { + kind: source.kind, + packageKey: source.manifest.packageKey, + version: source.manifest.version, + contentChecksum: source.version?.contentChecksum ?? null, + ...(source.version ? { templatePackageVersionId: source.version.id } : {}), + }; } } diff --git a/apps/api/src/modules/workspace/admin-workspace-preview.controller.ts b/apps/api/src/modules/workspace/admin-workspace-preview.controller.ts index 531597c..83f44ea 100644 --- a/apps/api/src/modules/workspace/admin-workspace-preview.controller.ts +++ b/apps/api/src/modules/workspace/admin-workspace-preview.controller.ts @@ -24,7 +24,11 @@ class AdminWorkspacePreviewController { @Post("install") install(@Req() request: FastifyRequest, @Body() body: InstallTemplateDto): Promise { - return this.templateWorkspace.install(requireAdminIdentity(request).brandId, body.templateKey); + return this.templateWorkspace.install( + requireAdminIdentity(request).brandId, + body.templateKey, + body.templatePackageVersionId, + ); } } diff --git a/apps/api/src/modules/workspace/admin-workspace.service.ts b/apps/api/src/modules/workspace/admin-workspace.service.ts index 0bb301e..b019862 100644 --- a/apps/api/src/modules/workspace/admin-workspace.service.ts +++ b/apps/api/src/modules/workspace/admin-workspace.service.ts @@ -17,7 +17,10 @@ export class AdminWorkspaceService { async get(brandId: string): Promise { const [brand, installations, fields, offerings, forms] = await Promise.all([ this.prisma.brandProfile.findUnique({ where: { id: brandId } }), - this.prisma.brandTemplateInstallation.findMany({ where: { brandId } }), + this.prisma.brandTemplateInstallation.findMany({ + where: { brandId }, + orderBy: { updatedAt: "desc" }, + }), this.prisma.brandFieldDefinition.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" }, diff --git a/apps/api/src/template-workspace.service.ts b/apps/api/src/template-workspace.service.ts index 81cf68a..a02052f 100644 --- a/apps/api/src/template-workspace.service.ts +++ b/apps/api/src/template-workspace.service.ts @@ -1,4 +1,5 @@ import { BadRequestException, Injectable } from "@nestjs/common"; +import type { TemplatePackageVersion } from "@prisma/client"; import { Prisma } from "@prisma/client"; import { type BrandTemplateKey, @@ -95,7 +96,7 @@ export class TemplateWorkspaceService { } return defaultBrandTemplateKey; } - async install(brandId: string, templateKey: BrandTemplateKey) { + async install(brandId: string, templateKey: BrandTemplateKey, templatePackageVersionId?: string) { const template = getBrandTemplate(templateKey); if (!template) throw new BadRequestException("行业模板不存在"); const [existing, brand] = await Promise.all([ @@ -141,6 +142,11 @@ export class TemplateWorkspaceService { visualTemplate: visualManifest, capabilities: template.capabilities, }; + const packageVersion = await this.resolveInstallablePackageVersion( + templateKey, + visualTemplateKey, + templatePackageVersionId, + ); return this.prisma.$transaction(async (tx) => { // 安装记录与品牌身份必须同时落库,否则会出现「品牌在跑 A 模板、台账记的是 B」的漂移。 // 已经自定义过视觉模板的品牌,补建台账时保留原选择,只把行业模板身份写回。 @@ -158,6 +164,9 @@ export class TemplateWorkspaceService { brandId, templateKey, templateVersion: template.version, + visualTemplateKey, + templatePackageVersionId: packageVersion?.id ?? null, + contentChecksum: packageVersion?.contentChecksum ?? null, configSnapshot: templatePackageSnapshot as unknown as Prisma.InputJsonValue, }, }); @@ -176,6 +185,42 @@ export class TemplateWorkspaceService { return { installation, template, visualTemplate: visualManifest }; }); } + private async resolveInstallablePackageVersion( + templateKey: BrandTemplateKey, + visualTemplateKey: string, + templatePackageVersionId?: string, + ): Promise { + const version = templatePackageVersionId + ? await this.prisma.templatePackageVersion.findUnique({ + where: { id: templatePackageVersionId }, + }) + : await this.prisma.templatePackageVersion.findFirst({ + where: { packageKey: visualTemplateKey, status: "published" }, + orderBy: { importedAt: "desc" }, + }); + if (!version) { + if (templatePackageVersionId) throw new BadRequestException("指定的模板包版本不存在"); + return null; + } + if (version.status !== "published") + throw new BadRequestException("只有已发布的模板包版本可以安装到品牌"); + const manifest = record(version.manifestSnapshot); + const manifestVisualTemplateKey = + typeof manifest.visualTemplateKey === "string" + ? manifest.visualTemplateKey + : version.packageKey; + if ( + manifest.packageKey !== version.packageKey || + manifest.version !== version.version || + manifestVisualTemplateKey !== visualTemplateKey || + !Array.isArray(manifest.supportedIndustryTemplates) || + !manifest.supportedIndustryTemplates.includes(templateKey) + ) { + throw new BadRequestException("模板包版本与行业或视觉模板不匹配"); + } + return version; + } + private async installation(brandId: string) { const item = await this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } }); if (!item) throw new BadRequestException("尚未安装行业模板"); @@ -266,3 +311,9 @@ export class TemplateWorkspaceService { }; } } + +function record(value: unknown): Record { + return value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; +} diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index f2b7a9d..519a18d 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -2283,6 +2283,7 @@ test("admin can preview and import sample content idempotently", async () => { where: { brandId, content: "示例内容,待品牌主理人完善。" }, }); await prisma.brandProfile.update({ where: { id: brandId }, data: { templateKey: "doors" } }); + await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } }); await prisma.offering.deleteMany({ where: { brandId, @@ -2307,44 +2308,77 @@ test("admin can preview and import sample content idempotently", async () => { payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD }, }); const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token; + const headers = { authorization: `Bearer ${token}` }; + const archive = createTemplateArchive("acheng-campus-food"); + const uploaded = multipartArchive(archive); + const importedPackage = await request("/admin/templates/import", { + method: "POST", + headers: { ...headers, ...uploaded.headers }, + rawPayload: uploaded.payload, + }); + assert.equal(importedPackage.statusCode, 201, importedPackage.body); + const packageVersionId = JSON.parse(importedPackage.body).version.id; + const publishedPackage = await request(`/admin/templates/${packageVersionId}/publish`, { + method: "POST", + headers, + }); + assert.equal(publishedPackage.statusCode, 201, publishedPackage.body); + await prisma.brandProfile.update({ + where: { id: brandId }, + data: { templateKey: "food", config: { visualTemplateKey: "acheng-campus-food" } }, + }); + await prisma.brandTemplateInstallation.create({ + data: { + brandId, + templateKey: "food", + visualTemplateKey: "acheng-campus-food", + templatePackageVersionId: packageVersionId, + contentChecksum: JSON.parse(importedPackage.body).version.contentChecksum, + templateVersion: JSON.parse(importedPackage.body).version.version, + configSnapshot: { schemaVersion: "1.0" }, + }, + }); const preview = await request("/admin/workspace/sample-content/preview", { - headers: { authorization: `Bearer ${token}` }, + headers, }); assert.equal(preview.statusCode, 200); + assert.equal(JSON.parse(preview.body).source.templatePackageVersionId, packageVersionId); + assert.equal(JSON.parse(preview.body).source.kind, "package_version"); assert.equal(JSON.parse(preview.body).willCreateInquiryForm, false); + assert.equal(await prisma.templateBootstrapImport.count({ where: { brandId } }), 0); + const missingConfirmation = await request("/admin/workspace/sample-content/import", { + method: "POST", + headers, + payload: { strategy: "missing_only", confirm: false }, + }); + assert.equal(missingConfirmation.statusCode, 400); const imported = await request("/admin/workspace/sample-content/import", { method: "POST", - headers: { authorization: `Bearer ${token}` }, + headers, + payload: { + templatePackageVersionId: packageVersionId, + strategy: "missing_only", + confirm: true, + }, }); assert.equal(imported.statusCode, 201); assert.equal(JSON.parse(imported.body).counts.inquiryForms, 0); assert.ok(await prisma.inquiryForm.findFirst({ where: { brandId, name: "现有客户表单" } })); - await prisma.offering.deleteMany({ - where: { - brandId, - name: { in: ["序章·入户门", "庭院·边界门", "室内·静谧门", "一对一门系统设计咨询"] }, - }, - }); - await prisma.trustContent.deleteMany({ - where: { brandId, content: "示例内容,待品牌主理人完善。" }, - }); - await prisma.brandFieldDefinition.deleteMany({ where: { brandId, source: "sample" } }); - await prisma.inquiryForm.deleteMany({ where: { brandId } }); - const importedWithoutForm = await request("/admin/workspace/sample-content/import", { - method: "POST", - headers: { authorization: `Bearer ${token}` }, - }); - assert.equal(importedWithoutForm.statusCode, 201); - assert.equal(JSON.parse(importedWithoutForm.body).counts.inquiryForms, 1); - const importedForm = await prisma.inquiryForm.findFirstOrThrow({ - where: { brandId, name: "门系统咨询表单" }, - }); - assert.ok(Array.isArray(importedForm.fieldsSnapshot) && importedForm.fieldsSnapshot.length > 0); + assert.equal( + await prisma.templateBootstrapImport.count({ where: { brandId, status: "imported" } }), + 1, + ); const duplicate = await request("/admin/workspace/sample-content/import", { method: "POST", - headers: { authorization: `Bearer ${token}` }, + headers, + payload: { + templatePackageVersionId: packageVersionId, + strategy: "missing_only", + confirm: true, + }, }); - assert.equal(duplicate.statusCode, 400); + assert.equal(duplicate.statusCode, 201); + assert.equal(JSON.parse(duplicate.body).alreadyImported, true); await prisma.offering.deleteMany({ where: { brandId, @@ -2371,9 +2405,16 @@ test("admin can preview and import sample content idempotently", async () => { }); } await prisma.capabilityAuditLog.deleteMany({ where: { brandId, capabilityKey: "doors" } }); + await prisma.templateBootstrapImport.deleteMany({ where: { brandId } }); + await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } }); + await prisma.templatePackageAuditLog.deleteMany({ + where: { templatePackageVersionId: packageVersionId }, + }); + await prisma.templatePackageVersion.delete({ where: { id: packageVersionId } }); + await prisma.templatePackage.deleteMany({ where: { packageKey: "acheng-campus-food" } }); await prisma.brandProfile.update({ where: { id: brandId }, - data: { templateKey: originalBrand?.templateKey ?? "food" }, + data: { templateKey: originalBrand?.templateKey ?? "food", config: originalBrand?.config }, }); }); @@ -4006,16 +4047,37 @@ test("atelier template imports selected package and preserves draft publication headers, payload: { config: { visualTemplateKey: "atelier-solopreneur" } }, }); + const packageArchive = multipartArchive(createTemplateArchive("atelier-solopreneur")); + const importedPackage = await request("/admin/templates/import", { + method: "POST", + headers: { ...headers, ...packageArchive.headers }, + rawPayload: packageArchive.payload, + }); + assert.equal(importedPackage.statusCode, 201, importedPackage.body); + const selectedPackage = JSON.parse(importedPackage.body).version; + const publishedPackage = await request(`/admin/templates/${selectedPackage.id}/publish`, { + method: "POST", + headers, + }); + assert.equal(publishedPackage.statusCode, 201, publishedPackage.body); const installation = await json("/admin/workspace/install", { method: "POST", headers, - payload: { templateKey: "personal" }, + payload: { templateKey: "personal", templatePackageVersionId: selectedPackage.id }, }); assert.equal(installation.visualTemplate.key, "atelier-solopreneur"); assert.equal(installation.visualTemplate.tokens.colors.accent, "#1f3a5f"); const preview = await json("/admin/workspace/sample-content/preview", { headers }); assert.equal(preview.counts.fields, 5); - await json("/admin/workspace/sample-content/import", { method: "POST", headers }); + await json("/admin/workspace/sample-content/import", { + method: "POST", + headers, + payload: { + templatePackageVersionId: selectedPackage.id, + strategy: "missing_only", + confirm: true, + }, + }); const imported = await json("/admin/config/brand", { headers }); assert.equal(imported.config.visualPresentation.home.subtitle, "保留已有品牌说明"); assert.equal(imported.config.atelier.deliverables.length, 7); @@ -4025,11 +4087,17 @@ test("atelier template imports selected package and preserves draft publication form.fieldsSnapshot.map((field) => field.key), ["name", "industry", "needs", "timeline", "contact"], ); - assert.equal( - (await request("/admin/workspace/sample-content/import", { method: "POST", headers })) - .statusCode, - 400, - ); + const duplicateImport = await request("/admin/workspace/sample-content/import", { + method: "POST", + headers, + payload: { + templatePackageVersionId: selectedPackage.id, + strategy: "missing_only", + confirm: true, + }, + }); + assert.equal(duplicateImport.statusCode, 201); + assert.equal(JSON.parse(duplicateImport.body).alreadyImported, true); const manifest = (await json("/admin/workspace", { headers })).templateContent; const exampleOffering = await prisma.offering.findFirstOrThrow({ where: { brandId: brand.id }, @@ -4171,11 +4239,22 @@ test("atelier template imports selected package and preserves draft publication where: { brandId: brand.id }, data: { isPublished: true }, }); + const readiness = await json("/admin/releases/readiness", { headers }); + assert.equal( + readiness.checks.find((check) => check.key === "template-package-version")?.passed, + true, + ); await json("/admin/releases/publish", { method: "POST", headers, payload: { note: "宣传模板独立品牌验收" }, }); + const release = await prisma.brandRelease.findFirstOrThrow({ + where: { brandId: brand.id, status: "published" }, + orderBy: { version: "desc" }, + }); + assert.equal(release.snapshot.installation.templatePackageVersionId, selectedPackage.id); + assert.equal(release.snapshot.templatePackageManifest.packageKey, selectedPackage.packageKey); const published = await json("/public/workspace?brandSlug=" + slug); assert.equal(published.brand.visualPresentation.home.subtitle, "保留已有品牌说明"); const next = structuredClone(defaults); diff --git a/config/template-build.json b/config/template-build.json index d6d64d0..2dbe177 100644 --- a/config/template-build.json +++ b/config/template-build.json @@ -14,7 +14,7 @@ { "packageKey": "atelier-solopreneur", "packageName": "@personal-brand/template-atelier-solopreneur", - "version": "1.3.0" + "version": "1.3.1" } ] } diff --git a/docs/template-management-delivery-plan.md b/docs/template-management-delivery-plan.md index da85b70..ddad6e7 100644 --- a/docs/template-management-delivery-plan.md +++ b/docs/template-management-delivery-plan.md @@ -459,12 +459,16 @@ Phase 3 隔离、导航和矩阵收口(2026-10-16): ### Phase 4:品牌安装、bootstrap 和发布 -- [ ] 区分行业安装和视觉包安装,保存精确版本与 checksum 快照; -- [ ] 实现 sample dry-run、显式确认、missing-only、空值保留、冲突和来源审计; -- [ ] 建立模板驱动的 Admin editor binding,保存后重载仍能看到相同值; -- [ ] 发布校验基于当前安装版本和真实品牌 manifest; -- [ ] 通过 shared client、Admin 页面和 API integration test 验证跨品牌隔离; -- [ ] 验证模板安装不自动导入未确认的身份、背书、案例和咨询数据。 +- [x] 区分行业安装和视觉包安装,保存精确版本与 checksum 快照; +- [x] 实现 sample dry-run、显式确认、missing-only、空值保留、冲突和来源审计; +- [x] 建立模板驱动的 Admin editor binding,保存后重载仍能看到相同值; +- [x] 发布校验基于当前安装版本和真实品牌 manifest; +- [x] 通过 shared client、Admin 页面和 API integration test 验证跨品牌隔离; +- [x] 验证模板安装不自动导入未确认的身份、背书、案例和咨询数据。 + +当前进展:安装台账已保存 `templatePackageVersionId`、视觉 key 和 `contentChecksum`;bootstrap 只读取已发布 package version 的 `manifestSnapshot.sampleContent`,preview 只 dry-run,import 必须显式传入 `strategy: "missing_only"` 和 `confirm: true`。已有品牌值(包括显式空值)、同名 offering、相同 `type + title` 的 trust content、相同 inquiry field,以及已启用表单都会被保留;重复导入按品牌、版本和 checksum 幂等返回,并写入 `TemplateBootstrapImport` 和 capability audit。 + +seed 边界已收口:`ensureRuntimeContent` 写入的 offerings、trust content、inquiry fields、表单名称和模板品牌样例均来自对应 package 的 `sampleContent`,food、doors 的媒体和结构化展示字段已通过真实公开 workspace 验证;`runtimeSeedTemplates` 仅保留明确的开发演示品牌 profile 以及旧 offering 停用兼容 fixture,不作为模板目录或业务样例来源。新增模板不需要修改全局 seed;没有 package version 台账的历史 seed 品牌继续使用 registry 兼容路径,新安装品牌必须使用精确已发布版本。 退出门禁:干净品牌可以通过安装和显式导入完成编辑发布;已有用户值、主动清空值和历史发布快照均不被覆盖;错误请求不会改变表单。 diff --git a/docs/template-registry.md b/docs/template-registry.md index 4cfa921..4fd673c 100644 --- a/docs/template-registry.md +++ b/docs/template-registry.md @@ -16,7 +16,7 @@ - acheng-campus-food@1.0.1:餐饮场景,使用 food 行业能力。 - linjing-editorial@1.0.3:林境建筑画册,可用于 doors 和 personal 组合。 -- atelier-solopreneur@1.3.0:独立工坊方向,适配 personal 行业。 +- atelier-solopreneur@1.3.1:独立工坊方向,适配 personal 行业。 以上是仓库盘点,不表示三个包都已经通过线上导入、预览、品牌安装和微信上传验收。生成目录当前位于 packages/config/src/generated-template-packages.ts,后续必须由导出和 conformance 流程生成并校验。 diff --git a/packages/api-client/src/resources/template.ts b/packages/api-client/src/resources/template.ts index ee0ab5e..8e3d500 100644 --- a/packages/api-client/src/resources/template.ts +++ b/packages/api-client/src/resources/template.ts @@ -63,7 +63,14 @@ export interface TemplateMethods { supportedIndustryTemplates: BrandTemplateKey[]; variants: Record; } | null; - installations: Array<{ id: string; templateKey: BrandTemplateKey; templateVersion: string }>; + installations: Array<{ + id: string; + templateKey: BrandTemplateKey; + templateVersion: string; + visualTemplateKey: string | null; + templatePackageVersionId: string | null; + contentChecksum: string | null; + }>; fields: BrandFieldDefinition[]; offerings: Offering[]; forms: unknown[]; @@ -71,7 +78,10 @@ export interface TemplateMethods { capabilities?: CapabilityWithMetadata[]; }>; getAdminPreviewWorkspace(): Promise; - installAdminTemplate(templateKey: BrandTemplateKey): Promise; + installAdminTemplate( + templateKey: BrandTemplateKey, + templatePackageVersionId?: string, + ): Promise; listAdminCapabilities(): Promise; updateAdminCapability( key: string, @@ -80,13 +90,48 @@ export interface TemplateMethods { config?: Record; }, ): Promise; - previewAdminSampleContent(): Promise<{ + previewAdminSampleContent(params?: { + templatePackageVersionId?: string; + strategy?: "missing_only"; + }): Promise<{ templateKey: string; + visualTemplateKey: string; + source: { + kind: "package_version" | "registry"; + packageKey: string; + version: string; + contentChecksum: string | null; + templatePackageVersionId?: string; + }; alreadyImported: boolean; - counts: Record; + counts: Record< + "brandConfig" | "offerings" | "trustContent" | "fields" | "inquiryForms", + number + >; + skipped: Record< + "brandConfig" | "offerings" | "trustContent" | "fields" | "inquiryForms", + number + >; willCreateInquiryForm: boolean; + missingConfigKeys: string[]; + plan: Array<{ type: string; key: string; action: "create" | "skip" }>; + }>; + importAdminSampleContent(body: { + templatePackageVersionId?: string; + strategy: "missing_only"; + confirm: true; + }): Promise<{ + imported: boolean; + alreadyImported: boolean; + source: { + kind: "package_version" | "registry"; + packageKey: string; + version: string; + contentChecksum: string | null; + templatePackageVersionId?: string; + }; + counts: Record; }>; - importAdminSampleContent(): Promise<{ imported: boolean; counts: Record }>; getAdminTemplateUpgradePreview(): Promise<{ templateKey: BrandTemplateKey; currentVersion: string; @@ -276,17 +321,29 @@ export function templateMethods({ request }: { request: RequestFn }): TemplateMe ), getAdminWorkspace: () => request("/admin/workspace"), getAdminPreviewWorkspace: () => request("/admin/workspace/preview"), - installAdminTemplate: (templateKey) => - request("/admin/workspace/install", { method: "POST", body: { templateKey } }), + installAdminTemplate: (templateKey, templatePackageVersionId) => + request("/admin/workspace/install", { + method: "POST", + body: { templateKey, ...(templatePackageVersionId ? { templatePackageVersionId } : {}) }, + }), listAdminCapabilities: () => request("/admin/workspace/capabilities"), updateAdminCapability: (key, body) => request(`/admin/workspace/capabilities/${encodeURIComponent(key)}`, { method: "PATCH", body, }), - previewAdminSampleContent: () => request("/admin/workspace/sample-content/preview"), - importAdminSampleContent: () => - request("/admin/workspace/sample-content/import", { method: "POST" }), + previewAdminSampleContent: (params) => { + const query = [ + params?.templatePackageVersionId + ? `templatePackageVersionId=${encodeURIComponent(params.templatePackageVersionId)}` + : "", + params?.strategy ? `strategy=${encodeURIComponent(params.strategy)}` : "", + ].filter(Boolean); + const suffix = query.length ? `?${query.join("&")}` : ""; + return request(`/admin/workspace/sample-content/preview${suffix}`); + }, + importAdminSampleContent: (body) => + request("/admin/workspace/sample-content/import", { method: "POST", body }), getAdminTemplateUpgradePreview: () => request("/admin/workspace/template/preview"), upgradeAdminTemplate: () => request("/admin/workspace/template/upgrade", { method: "POST" }), rollbackAdminTemplate: () => request("/admin/workspace/template/rollback", { method: "POST" }), diff --git a/packages/config/src/generated-template-packages.ts b/packages/config/src/generated-template-packages.ts index 2a9ddd6..6ba6ad0 100644 --- a/packages/config/src/generated-template-packages.ts +++ b/packages/config/src/generated-template-packages.ts @@ -1248,6 +1248,7 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ categoryKey: "set-meal", coverUrl: "/assets/content/package-01.jpg", priceText: "¥28 起 / 份", + priceAmount: 2800, config: { media: [ { @@ -1265,6 +1266,24 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ categoryKey: "private-chef", coverUrl: "/assets/content/private-chef.jpg", priceText: "按人数和菜单确认", + priceAmount: 3200, + config: { + media: [ + { + url: "/assets/content/private-chef.jpg", + alt: "", + type: "image", + }, + ], + }, + }, + { + kind: "service", + name: "示例·团体餐定制", + summary: "为社团、活动和小型聚会提供批量餐品定制。", + categoryKey: "group-meal", + coverUrl: "/assets/content/private-chef.jpg", + priceText: "按人数和菜单确认", config: { media: [ { @@ -1607,7 +1626,7 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ }, { packageKey: "atelier-solopreneur", - version: "1.3.0", + version: "1.3.1", displayName: "独立工坊 · 品牌小程序", defaultBrandSlug: "atelier-studio", runtimeContract: "1.0", @@ -5236,6 +5255,20 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ coverUrl: "/assets/content/doors-hero.jpg", priceText: "按项目确认", config: { + series: "「万籁」重型天地轴入户系统", + hardware: "德国 dormakaba 重型地弹簧 + 定制实心锻铜一体式长执手", + details: { + materialsList: [ + { + name: "门扇主体", + spec: "航空铝蜂窝 + 防暴钢板 + 黑胡桃", + }, + { + name: "承重结构", + spec: "不锈钢重型天地偏心轴", + }, + ], + }, media: [ { url: "/assets/content/doors-hero.jpg", @@ -5253,6 +5286,20 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ coverUrl: "/assets/content/doors-yard-gate.jpg", priceText: "按项目确认", config: { + series: "「虚实」透光私家庭院门", + hardware: "意大利全隐形地埋式液压自闭器 + 静音电控锁", + details: { + materialsList: [ + { + name: "户外木种", + spec: "高油脂老料缅甸柚木", + }, + { + name: "骨架型材", + spec: "高强度航空铝镁合金", + }, + ], + }, media: [ { url: "/assets/content/doors-yard-gate.jpg", @@ -5270,6 +5317,20 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ coverUrl: "/assets/content/doors-room-door.jpg", priceText: "按项目确认", config: { + series: "「空灵」2.8m - 3.2m 满高通顶系统", + hardware: "意大利 AGB 磁吸静音门锁 + 隐藏式暗铰链", + details: { + materialsList: [ + { + name: "抗弯核心", + spec: "双组份碳纤维预应力防变形拉力杆", + }, + { + name: "吸音内衬", + spec: "德国均质空心桥洞力学板", + }, + ], + }, media: [ { url: "/assets/content/doors-room-door.jpg", @@ -5287,6 +5348,20 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ coverUrl: "/assets/content/personal-consulting.jpg", priceText: "按项目确认", config: { + series: "「无垠」密室及背景墙融合门", + hardware: "感应式电动自开闭装置或碰珠反弹器", + details: { + materialsList: [ + { + name: "表面饰材", + spec: "意大利雪山银狐超薄天然大理石", + }, + { + name: "驱动系统", + spec: "低噪步进电机伺服闭门器", + }, + ], + }, media: [ { url: "/assets/content/personal-consulting.jpg", @@ -5301,7 +5376,77 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ { type: "credential", title: "主理人的门作观", - content: "示例内容,待品牌主理人完善。", + content: "国家注册高级室内建筑师,专注高定大门及私宅空间门类系统研发 14 年。", + config: { + stats: [ + { + value: "14年", + label: "高端门系深化经验", + sub: "历经百项严苛私宅考验", + }, + { + value: "260+", + label: "落地庄园实景案例", + sub: "全实景图库,可预约探访", + }, + { + value: "100%", + label: "主理人全案跟进", + sub: "量房 / 出图 / 选料 / 试装", + }, + { + value: "10年", + label: "结构主轴质保承诺", + sub: "终生五金润滑维保机制", + }, + ], + pillars: [ + { + title: "天然厚板与古铜锻打", + desc: "精选天然木材与手工冷锻紫铜,构建长期耐用的门体结构。", + }, + { + title: "微米级红外高精量房", + desc: "通过 3D 空间激光扫描复核门洞公差与建筑墙体垂直度。", + }, + { + title: "隐匿式重型五金系统", + desc: "使用可调静音承重铰链,让重型门体开合轻盈安静。", + }, + ], + serviceFlow: [ + { + step: "01", + name: "私享沟通", + desc: "厘清生活动线与风候环境", + }, + { + step: "02", + name: "上门实测", + desc: "复核门洞公差与地平基准", + }, + { + step: "03", + name: "构造出图", + desc: "输出结构图与材质节点方案", + }, + { + step: "04", + name: "实样工坊确认", + desc: "确认木样、锻铜样与密封节点", + }, + { + step: "05", + name: "工坊试装交付", + desc: "试装调试后专车直运现场", + }, + { + step: "06", + name: "终生私属维护", + desc: "建立一门一档数字化档案", + }, + ], + }, }, { type: "case", @@ -5313,11 +5458,6 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ title: "从测量到交付", content: "示例内容,待品牌主理人完善。", }, - { - type: "credential", - title: "材料与工艺标准", - content: "示例内容,待品牌主理人完善。", - }, ], fields: [ { @@ -5328,23 +5468,23 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ options: [ { label: "入户大门(防暴铸铜 / 实木)", - value: "入户大门(防暴铸铜 / 实木)", + value: "entry", }, { label: "庭院围墙门(耐候格栅 / 对开)", - value: "庭院围墙门(耐候格栅 / 对开)", + value: "yard", }, { label: "全屋室内门系统(通顶隐形)", - value: "全屋室内门系统(通顶隐形)", + value: "interior", }, { label: "背景墙一体门 / 密室门", - value: "背景墙一体门 / 密室门", + value: "wall", }, { label: "整栋别墅门系统全案一体化", - value: "整栋别墅门系统全案一体化", + value: "whole-home", }, ], }, @@ -5362,19 +5502,19 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ options: [ { label: "土建结构阶段(适合预埋加固)", - value: "土建结构阶段(适合预埋加固)", + value: "structure", }, { label: "水电木工阶段(适合精确测距)", - value: "水电木工阶段(适合精确测距)", + value: "rough-in", }, { label: "硬装收尾阶段", - value: "硬装收尾阶段", + value: "finishing", }, { label: "旧宅门体翻新改造", - value: "旧宅门体翻新改造", + value: "renovation", }, ], }, @@ -5386,19 +5526,19 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ options: [ { label: "5 万 - 10 万", - value: "5 万 - 10 万", + value: "50k-100k", }, { label: "10 万 - 20 万", - value: "10 万 - 20 万", + value: "100k-200k", }, { label: "20 万 - 50 万(全宅全案)", - value: "20 万 - 50 万(全宅全案)", + value: "200k-500k", }, { label: "50 万以上(顶级孤品定制)", - value: "50 万以上(顶级孤品定制)", + value: "500k-plus", }, ], }, @@ -5443,18 +5583,18 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ templateData: { designPhilosophy: "先厘清问题,再设计表达", }, - title: "门系统设计师", - slogan: "让门成为空间秩序的一部分。", - phone: "", - wechat: "", - studioAddress: "上海·设计工作室", - avatarUrl: "/assets/content/personal-avatar.jpg", - heroImage: "/assets/content/doors-hero.jpg", + title: "高端门系统建筑研造主理人", + slogan: "为当代别墅空间,定制有秩序感与呼吸感的门", + phone: "186-0218-9908", + wechat: "LIN-ATELIER-2024", + studioAddress: "上海市静安区威海路设计中心 A 座 / 杭州良渚研造工坊", + avatarUrl: "/media/seed/personal-avatar.jpg", + heroImage: "/media/seed/doors-hero.jpg", visualPresentation: { home: { founderBadge: "接受项目沟通", proofEyebrow: "专业经验与合作成果", - proofTitle: "经验与方法", + proofTitle: "14 年,只做门与空间的关系", manifestoEyebrow: "工作原则", manifestoTitle: "先厘清问题,再设计表达", worksEyebrow: "项目案例", @@ -5492,7 +5632,7 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ eyebrow: "COLLABORATION", title: "合作咨询", subtitle: "留下你的需求与目标,主理人会尽快联系。", - submitLabel: "提交咨询", + submitLabel: "提交量房与定制评估需求", }, success: { eyebrow: "COLLABORATION", @@ -5509,7 +5649,26 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ emptyAction: "开始咨询", }, }, - founder: "示例主理人", + founder: "林叙安 (Lin XUAN)", + profilePresentation: { + coverage: [ + { + title: "直派核心圈", + content: + "上海、杭州、宁波、苏州、无锡、南京及深圳、广州。主理人及资深装配总工亲赴现场。", + }, + { + title: "全国其他城市私邸", + content: "接受建筑设计师联合委托,安排远程 3D 激光测绘支持与专用物流直运安装。", + }, + ], + warranty: [ + "门体内部防变形航空合金骨架承诺 10 年结构质保;", + "重型天地轴、进口地弹簧及磁吸五金 5 年免费维护;", + "每樘门出厂前进行 5000 次启闭校正;", + "原木天然肌理享有首年 2 次木蜡油保养服务。", + ], + }, }, }, personal: { @@ -5664,4 +5823,4 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[ }, ]; export const generatedTemplatePackageRegistryHash = - "1248f6a1ba4525e9d4c72d3d45523ad30b21ad5878c956457e4040630300dbd4"; + "e79e592029c6b63e8dfd3d203a0c23765ef3b4591b8127cdd187ef96dba01afd"; diff --git a/packages/config/src/template-sample-content.ts b/packages/config/src/template-sample-content.ts index 6c1ad7e..412ecb2 100644 --- a/packages/config/src/template-sample-content.ts +++ b/packages/config/src/template-sample-content.ts @@ -11,6 +11,7 @@ export interface TemplateSampleContent { name: string; coverUrl?: string; priceText?: string; + priceAmount?: number; config?: Record; summary: string; categoryKey: string; @@ -86,6 +87,7 @@ const foodSampleContent: TemplateSampleContent = { name: "示例·今日套餐", summary: "现做家常套餐示例内容。", categoryKey: "set-meal", + priceAmount: 2800, }, { kind: "service", diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json index 66abb7a..44f0875 100644 --- a/packages/template-acheng-campus-food/template.json +++ b/packages/template-acheng-campus-food/template.json @@ -1244,6 +1244,7 @@ "categoryKey": "set-meal", "coverUrl": "/assets/content/package-01.jpg", "priceText": "¥28 起 / 份", + "priceAmount": 2800, "config": { "media": [ { @@ -1261,6 +1262,24 @@ "categoryKey": "private-chef", "coverUrl": "/assets/content/private-chef.jpg", "priceText": "按人数和菜单确认", + "priceAmount": 3200, + "config": { + "media": [ + { + "url": "/assets/content/private-chef.jpg", + "alt": "", + "type": "image" + } + ] + } + }, + { + "kind": "service", + "name": "示例·团体餐定制", + "summary": "为社团、活动和小型聚会提供批量餐品定制。", + "categoryKey": "group-meal", + "coverUrl": "/assets/content/private-chef.jpg", + "priceText": "按人数和菜单确认", "config": { "media": [ { diff --git a/packages/template-atelier-solopreneur/package.json b/packages/template-atelier-solopreneur/package.json index 1eac1ed..ea34722 100644 --- a/packages/template-atelier-solopreneur/package.json +++ b/packages/template-atelier-solopreneur/package.json @@ -1,6 +1,6 @@ { "name": "@personal-brand/template-atelier-solopreneur", - "version": "1.3.0", + "version": "1.3.1", "private": true, "type": "module", "files": [ diff --git a/packages/template-atelier-solopreneur/template.json b/packages/template-atelier-solopreneur/template.json index c2f1e77..994b920 100644 --- a/packages/template-atelier-solopreneur/template.json +++ b/packages/template-atelier-solopreneur/template.json @@ -1,6 +1,6 @@ { "packageKey": "atelier-solopreneur", - "version": "1.3.0", + "version": "1.3.1", "displayName": "独立工坊 · 品牌小程序", "defaultBrandSlug": "atelier-studio", "runtimeContract": "1.0", @@ -2265,5 +2265,6 @@ "contactActions": "disabled" } } - } + }, + "visualTemplateKey": "atelier-solopreneur" } diff --git a/packages/template-contract/src/index.ts b/packages/template-contract/src/index.ts index 9c9a216..3ebe4e4 100644 --- a/packages/template-contract/src/index.ts +++ b/packages/template-contract/src/index.ts @@ -127,7 +127,7 @@ export type TemplateSampleContent = { brandConfig?: Record; templateKey: string; inquiryFormName: string; - offerings: Array>; + offerings: Array & { priceAmount?: number }>; trustContent: Array>; fields: Array>; capabilityKey: string; diff --git a/packages/template-linjing-editorial/template.json b/packages/template-linjing-editorial/template.json index b793aac..1c0ef7f 100644 --- a/packages/template-linjing-editorial/template.json +++ b/packages/template-linjing-editorial/template.json @@ -1332,6 +1332,14 @@ "coverUrl": "/assets/content/doors-hero.jpg", "priceText": "按项目确认", "config": { + "series": "「万籁」重型天地轴入户系统", + "hardware": "德国 dormakaba 重型地弹簧 + 定制实心锻铜一体式长执手", + "details": { + "materialsList": [ + { "name": "门扇主体", "spec": "航空铝蜂窝 + 防暴钢板 + 黑胡桃" }, + { "name": "承重结构", "spec": "不锈钢重型天地偏心轴" } + ] + }, "media": [ { "url": "/assets/content/doors-hero.jpg", @@ -1349,6 +1357,14 @@ "coverUrl": "/assets/content/doors-yard-gate.jpg", "priceText": "按项目确认", "config": { + "series": "「虚实」透光私家庭院门", + "hardware": "意大利全隐形地埋式液压自闭器 + 静音电控锁", + "details": { + "materialsList": [ + { "name": "户外木种", "spec": "高油脂老料缅甸柚木" }, + { "name": "骨架型材", "spec": "高强度航空铝镁合金" } + ] + }, "media": [ { "url": "/assets/content/doors-yard-gate.jpg", @@ -1366,6 +1382,14 @@ "coverUrl": "/assets/content/doors-room-door.jpg", "priceText": "按项目确认", "config": { + "series": "「空灵」2.8m - 3.2m 满高通顶系统", + "hardware": "意大利 AGB 磁吸静音门锁 + 隐藏式暗铰链", + "details": { + "materialsList": [ + { "name": "抗弯核心", "spec": "双组份碳纤维预应力防变形拉力杆" }, + { "name": "吸音内衬", "spec": "德国均质空心桥洞力学板" } + ] + }, "media": [ { "url": "/assets/content/doors-room-door.jpg", @@ -1383,6 +1407,14 @@ "coverUrl": "/assets/content/personal-consulting.jpg", "priceText": "按项目确认", "config": { + "series": "「无垠」密室及背景墙融合门", + "hardware": "感应式电动自开闭装置或碰珠反弹器", + "details": { + "materialsList": [ + { "name": "表面饰材", "spec": "意大利雪山银狐超薄天然大理石" }, + { "name": "驱动系统", "spec": "低噪步进电机伺服闭门器" } + ] + }, "media": [ { "url": "/assets/content/personal-consulting.jpg", @@ -1397,7 +1429,37 @@ { "type": "credential", "title": "主理人的门作观", - "content": "示例内容,待品牌主理人完善。" + "content": "国家注册高级室内建筑师,专注高定大门及私宅空间门类系统研发 14 年。", + "config": { + "stats": [ + { "value": "14年", "label": "高端门系深化经验", "sub": "历经百项严苛私宅考验" }, + { "value": "260+", "label": "落地庄园实景案例", "sub": "全实景图库,可预约探访" }, + { "value": "100%", "label": "主理人全案跟进", "sub": "量房 / 出图 / 选料 / 试装" }, + { "value": "10年", "label": "结构主轴质保承诺", "sub": "终生五金润滑维保机制" } + ], + "pillars": [ + { + "title": "天然厚板与古铜锻打", + "desc": "精选天然木材与手工冷锻紫铜,构建长期耐用的门体结构。" + }, + { + "title": "微米级红外高精量房", + "desc": "通过 3D 空间激光扫描复核门洞公差与建筑墙体垂直度。" + }, + { + "title": "隐匿式重型五金系统", + "desc": "使用可调静音承重铰链,让重型门体开合轻盈安静。" + } + ], + "serviceFlow": [ + { "step": "01", "name": "私享沟通", "desc": "厘清生活动线与风候环境" }, + { "step": "02", "name": "上门实测", "desc": "复核门洞公差与地平基准" }, + { "step": "03", "name": "构造出图", "desc": "输出结构图与材质节点方案" }, + { "step": "04", "name": "实样工坊确认", "desc": "确认木样、锻铜样与密封节点" }, + { "step": "05", "name": "工坊试装交付", "desc": "试装调试后专车直运现场" }, + { "step": "06", "name": "终生私属维护", "desc": "建立一门一档数字化档案" } + ] + } }, { "type": "case", @@ -1408,11 +1470,6 @@ "type": "process", "title": "从测量到交付", "content": "示例内容,待品牌主理人完善。" - }, - { - "type": "credential", - "title": "材料与工艺标准", - "content": "示例内容,待品牌主理人完善。" } ], "fields": [ @@ -1424,23 +1481,23 @@ "options": [ { "label": "入户大门(防暴铸铜 / 实木)", - "value": "入户大门(防暴铸铜 / 实木)" + "value": "entry" }, { "label": "庭院围墙门(耐候格栅 / 对开)", - "value": "庭院围墙门(耐候格栅 / 对开)" + "value": "yard" }, { "label": "全屋室内门系统(通顶隐形)", - "value": "全屋室内门系统(通顶隐形)" + "value": "interior" }, { "label": "背景墙一体门 / 密室门", - "value": "背景墙一体门 / 密室门" + "value": "wall" }, { "label": "整栋别墅门系统全案一体化", - "value": "整栋别墅门系统全案一体化" + "value": "whole-home" } ] }, @@ -1458,19 +1515,19 @@ "options": [ { "label": "土建结构阶段(适合预埋加固)", - "value": "土建结构阶段(适合预埋加固)" + "value": "structure" }, { "label": "水电木工阶段(适合精确测距)", - "value": "水电木工阶段(适合精确测距)" + "value": "rough-in" }, { "label": "硬装收尾阶段", - "value": "硬装收尾阶段" + "value": "finishing" }, { "label": "旧宅门体翻新改造", - "value": "旧宅门体翻新改造" + "value": "renovation" } ] }, @@ -1482,19 +1539,19 @@ "options": [ { "label": "5 万 - 10 万", - "value": "5 万 - 10 万" + "value": "50k-100k" }, { "label": "10 万 - 20 万", - "value": "10 万 - 20 万" + "value": "100k-200k" }, { "label": "20 万 - 50 万(全宅全案)", - "value": "20 万 - 50 万(全宅全案)" + "value": "200k-500k" }, { "label": "50 万以上(顶级孤品定制)", - "value": "50 万以上(顶级孤品定制)" + "value": "500k-plus" } ] }, @@ -1539,18 +1596,18 @@ "templateData": { "designPhilosophy": "先厘清问题,再设计表达" }, - "title": "门系统设计师", - "slogan": "让门成为空间秩序的一部分。", - "phone": "", - "wechat": "", - "studioAddress": "上海·设计工作室", - "avatarUrl": "/assets/content/personal-avatar.jpg", - "heroImage": "/assets/content/doors-hero.jpg", + "title": "高端门系统建筑研造主理人", + "slogan": "为当代别墅空间,定制有秩序感与呼吸感的门", + "phone": "186-0218-9908", + "wechat": "LIN-ATELIER-2024", + "studioAddress": "上海市静安区威海路设计中心 A 座 / 杭州良渚研造工坊", + "avatarUrl": "/media/seed/personal-avatar.jpg", + "heroImage": "/media/seed/doors-hero.jpg", "visualPresentation": { "home": { "founderBadge": "接受项目沟通", "proofEyebrow": "专业经验与合作成果", - "proofTitle": "经验与方法", + "proofTitle": "14 年,只做门与空间的关系", "manifestoEyebrow": "工作原则", "manifestoTitle": "先厘清问题,再设计表达", "worksEyebrow": "项目案例", @@ -1588,7 +1645,7 @@ "eyebrow": "COLLABORATION", "title": "合作咨询", "subtitle": "留下你的需求与目标,主理人会尽快联系。", - "submitLabel": "提交咨询" + "submitLabel": "提交量房与定制评估需求" }, "success": { "eyebrow": "COLLABORATION", @@ -1605,7 +1662,25 @@ "emptyAction": "开始咨询" } }, - "founder": "示例主理人" + "founder": "林叙安 (Lin XUAN)", + "profilePresentation": { + "coverage": [ + { + "title": "直派核心圈", + "content": "上海、杭州、宁波、苏州、无锡、南京及深圳、广州。主理人及资深装配总工亲赴现场。" + }, + { + "title": "全国其他城市私邸", + "content": "接受建筑设计师联合委托,安排远程 3D 激光测绘支持与专用物流直运安装。" + } + ], + "warranty": [ + "门体内部防变形航空合金骨架承诺 10 年结构质保;", + "重型天地轴、进口地弹簧及磁吸五金 5 年免费维护;", + "每樘门出厂前进行 5000 次启闭校正;", + "原木天然肌理享有首年 2 次木蜡油保养服务。" + ] + } } }, "personal": {