From 8e46c2c2931064e21a2a74c9178ef089d59462c7 Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 20 Sep 2026 09:04:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E9=A1=B9=E8=AF=A6=E6=83=85=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=A5=91=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/admin.dto.ts | 16 ++++++++++++++++ apps/api/src/main.ts | 33 +++++++++++++++++++++++++++----- packages/api-client/src/index.ts | 19 ++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/apps/api/src/admin.dto.ts b/apps/api/src/admin.dto.ts index 734270a..7eb61ad 100644 --- a/apps/api/src/admin.dto.ts +++ b/apps/api/src/admin.dto.ts @@ -98,6 +98,14 @@ export class CreateOfferingDto { @IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number; @IsOptional() @IsBoolean() isEnabled?: boolean; @IsOptional() config?: Record; + @IsOptional() sections?: Array<{ + type: string; + title: string; + content?: string; + items?: unknown[]; + }>; + @IsOptional() media?: Array<{ url: string; alt?: string; type?: string }>; + @IsOptional() cta?: { type: string; label: string; config?: Record }; } export class UpdateOfferingDto { @@ -111,4 +119,12 @@ export class UpdateOfferingDto { @IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number; @IsOptional() @IsBoolean() isEnabled?: boolean; @IsOptional() config?: Record; + @IsOptional() sections?: Array<{ + type: string; + title: string; + content?: string; + items?: unknown[]; + }>; + @IsOptional() media?: Array<{ url: string; alt?: string; type?: string }>; + @IsOptional() cta?: { type: string; label: string; config?: Record }; } diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index f8b142f..3c29637 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -161,7 +161,13 @@ export class PublicOfferingController { }, }); if (!item) throw new BadRequestException("业务提供项不存在"); - return item; + const config = (item.config ?? {}) as Record; + return { + ...item, + sections: config.sections ?? [], + media: config.media ?? [], + cta: config.cta ?? null, + }; } } @@ -187,12 +193,17 @@ export class AdminWorkspaceController { @Body() body: CreateOfferingDto, ): Promise { this.requireAdmin(request); - const { config, ...fields } = body; + const { config, sections, media, cta, ...fields } = body; return this.prisma.offering.create({ data: { ...fields, brandId: this.brandId(), - ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }), + config: { + ...(config ?? {}), + ...(sections === undefined ? {} : { sections }), + ...(media === undefined ? {} : { media }), + ...(cta === undefined ? {} : { cta }), + } as Prisma.InputJsonValue, }, }); } @@ -206,12 +217,24 @@ export class AdminWorkspaceController { this.requireAdmin(request); const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } }); if (!item) throw new BadRequestException("业务提供项不存在"); - const { config, ...fields } = body; + const { config, sections, media, cta, ...fields } = body; return this.prisma.offering.update({ where: { id }, data: { ...fields, - ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }), + ...(config === undefined && + sections === undefined && + media === undefined && + cta === undefined + ? {} + : { + config: { + ...(config ?? {}), + ...(sections === undefined ? {} : { sections }), + ...(media === undefined ? {} : { media }), + ...(cta === undefined ? {} : { cta }), + } as Prisma.InputJsonValue, + }), }, }); } diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index c9169ef..aaa320c 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -108,6 +108,22 @@ export interface BrandTemplateDefinition { serviceCategories: string[]; trustContentTypes: string[]; } +export interface OfferingSection { + type: "text" | "image-list" | "timeline" | "faq"; + title: string; + content?: string; + items?: unknown[]; +} +export interface OfferingMedia { + url: string; + alt?: string; + type?: "image" | "video"; +} +export interface OfferingCta { + type: "inquiry" | "booking" | "contact" | "external-link"; + label: string; + config?: Record; +} export interface Offering { id: string; brandId?: string; @@ -121,6 +137,9 @@ export interface Offering { isEnabled: boolean; sortOrder: number; config?: Record | null; + sections?: OfferingSection[]; + media?: OfferingMedia[]; + cta?: OfferingCta; } export class ApiClientError extends Error {