From 569156c977ac57b3807d1b769c0ae42455517b04 Mon Sep 17 00:00:00 2001 From: que01 Date: Sat, 10 Oct 2026 17:21:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=9A=E5=8A=A1=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=8E=A5=E5=85=A5=E9=A2=84=E8=A7=88=E7=94=BB?= =?UTF-8?q?=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/features/services/ServicesPage.css | 38 +++ .../src/features/services/ServicesPage.tsx | 219 ++++++++++++------ 2 files changed, 182 insertions(+), 75 deletions(-) create mode 100644 apps/admin/src/features/services/ServicesPage.css diff --git a/apps/admin/src/features/services/ServicesPage.css b/apps/admin/src/features/services/ServicesPage.css new file mode 100644 index 0000000..4707a50 --- /dev/null +++ b/apps/admin/src/features/services/ServicesPage.css @@ -0,0 +1,38 @@ +.service-offering-editor { + display: grid; + grid-template-columns: minmax(320px, 1fr) minmax(340px, 440px); + gap: 20px; + max-height: 76vh; + overflow: hidden; +} + +.service-offering-editor__preview { + min-width: 0; + height: 72vh; + border: 1px solid #e5e7eb; + border-radius: 12px; + overflow: hidden; +} + +.service-offering-editor__form { + min-width: 0; + max-height: 72vh; + overflow-y: auto; + padding-right: 4px; +} + +@media (max-width: 860px) { + .service-offering-editor { + grid-template-columns: minmax(0, 1fr); + max-height: none; + overflow: visible; + } + + .service-offering-editor__preview { + height: 560px; + } + + .service-offering-editor__form { + max-height: none; + } +} diff --git a/apps/admin/src/features/services/ServicesPage.tsx b/apps/admin/src/features/services/ServicesPage.tsx index 083666b..19b08a7 100644 --- a/apps/admin/src/features/services/ServicesPage.tsx +++ b/apps/admin/src/features/services/ServicesPage.tsx @@ -14,14 +14,18 @@ import { import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import type { Offering, + RuntimeWorkspace, TemplateAdminField, TemplateAdminSection, } from "@personal-brand/api-client"; import { useMemo, useState } from "react"; +import { projectBrandAliases } from "@personal-brand/api-client"; import { createApiClient } from "../../lib/api.js"; import { AdminPageHeader } from "../../components/AdminPageHeader.js"; import { ImageUrlField } from "../../components/ImageUrlField.js"; import { RecordContentFields } from "../../components/RecordContentEditor.js"; +import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js"; +import type { PreviewTarget } from "../brand/preview-selection.js"; import { applyPresentationValues, presentationFieldName, @@ -29,6 +33,7 @@ import { } from "../brand/presentation-bindings.js"; import { MutationError, QueryState } from "../../components/QueryState.js"; import { useNavigate } from "react-router-dom"; +import "./ServicesPage.css"; export function ServicesPage() { const navigate = useNavigate(); @@ -45,6 +50,10 @@ export function ServicesPage() { queryKey: ["admin-workspace-offering-fields"], queryFn: () => client.getAdminWorkspace(), }); + const previewWorkspace = useQuery({ + queryKey: ["admin-preview-workspace-services"], + queryFn: () => client.getAdminPreviewWorkspace(), + }); const templateFields: TemplateAdminField[] = ( workspace.data?.templateContent?.admin.sections ?? [] ) @@ -82,6 +91,51 @@ export function ServicesPage() { const hasTemplateDetailCopy = templateFields.some( (field) => field.binding === "offering.config.details.background", ); + const previewTargets = useMemo( + () => + (workspace.data?.templateContent?.admin.sections ?? []) + .filter((section) => section.page === "offerings") + .flatMap((section) => + (section.previewTargets ?? []).map((target) => ({ + ...target, + page: section.page, + source: section.fields.some( + (field) => + field.binding.startsWith("offering.") && field.previewTarget === target.key, + ) + ? "offering" + : section.target, + })), + ), + [workspace.data?.templateContent], + ); + const previewPageWorkspace = useMemo(() => { + if (!previewWorkspace.data || !editingOffering) return undefined; + const config = editingOffering.config ?? {}; + return { + ...previewWorkspace.data, + offerings: previewWorkspace.data.offerings.map((item) => + item.id === editingOffering.id + ? { + ...item, + config, + presentation: { + ...item.presentation, + ...config, + ...(config.presentation && typeof config.presentation === "object" + ? (config.presentation as Record) + : {}), + heroImage: + typeof config.detailHero === "string" + ? config.detailHero + : (editingOffering.coverUrl ?? null), + }, + } + : item, + ), + brand: projectBrandAliases(previewWorkspace.data.brand, config), + }; + }, [previewWorkspace.data, editingOffering]); const saveOffering = useMutation({ mutationFn: (values: Record) => { const fields = Object.fromEntries( @@ -263,6 +317,7 @@ export function ServicesPage() { { setOfferingOpen(false); setEditingOffering(null); @@ -271,82 +326,96 @@ export function ServicesPage() { onOk={() => offeringForm.submit()} confirmLoading={saveOffering.isPending} > -
saveOffering.mutate(values as Record)} - > - - - - - - - {!hasTemplateDetailCopy ? ( - - +
+ {editingOffering && previewPageWorkspace ? ( +
+ {}} + /> +
+ ) : null} + saveOffering.mutate(values as Record)} + > + + - - - - - - - - - + + + + + {!hasTemplateDetailCopy ? ( + + + + ) : null} + + + + + + + + + + +