From 91322fa9a0bdc76007c2c56a69d9ab13b449beac Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 11 Oct 2026 12:55:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=8F=8C=E5=85=A5=E5=8F=A3=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/RecordContentEditor.tsx | 2 + .../src/features/brand/PresentationEditor.tsx | 58 ++++- .../src/features/services/ServicesPage.css | 13 +- .../src/features/services/ServicesPage.tsx | 132 ++++++----- .../taro/test/browser/services-editor.spec.ts | 210 ++++++++++++++++++ 5 files changed, 338 insertions(+), 77 deletions(-) create mode 100644 apps/taro/test/browser/services-editor.spec.ts diff --git a/apps/admin/src/components/RecordContentEditor.tsx b/apps/admin/src/components/RecordContentEditor.tsx index ca8e85b..d01ea12 100644 --- a/apps/admin/src/components/RecordContentEditor.tsx +++ b/apps/admin/src/components/RecordContentEditor.tsx @@ -155,6 +155,8 @@ export function RecordContentEditor({ }); void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }); void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] }); + if (source === "offering") + void queryClient.invalidateQueries({ queryKey: ["admin-workspace-offering-fields"] }); }, }); return ( diff --git a/apps/admin/src/features/brand/PresentationEditor.tsx b/apps/admin/src/features/brand/PresentationEditor.tsx index 2609a1a..4712c9f 100644 --- a/apps/admin/src/features/brand/PresentationEditor.tsx +++ b/apps/admin/src/features/brand/PresentationEditor.tsx @@ -183,6 +183,7 @@ export function PresentationEditor({ const breakpoints = Grid.useBreakpoint(); const [activePage, setActivePage] = useState(); const [selection, setSelection] = useState(initialSelection); + const [hasInitializedSelection, setHasInitializedSelection] = useState(Boolean(initialSelection)); const [detailOfferingId, setDetailOfferingId] = useState(); const [recordDraft, setRecordDraft] = useState<{ source: "offering" | "trust"; @@ -292,6 +293,7 @@ export function PresentationEditor({ queryKey: ["admin-offerings"], queryFn: () => createApiClient().listAdminOfferings(), enabled: selectedRecordSource === "offering", + refetchOnMount: "always", }); const trustQuery = useQuery({ queryKey: ["trust-content"], @@ -435,10 +437,46 @@ export function PresentationEditor({ }, [form, initialValues]); useEffect(() => { - if (!pageOptions.some((item) => item.value === activePage)) - setActivePage(pageOptions[0]?.value); - }, [activePage, pageOptions]); - useEffect(() => setSelection(undefined), [selectedPage, templateContent?.displayName]); + const initialPage = + typeof initialSelection === "object" && "page" in initialSelection + ? String(initialSelection.page) + : undefined; + if (initialPage) { + setActivePage( + pageOptions.some((item) => item.value === initialPage) + ? initialPage + : pageOptions[0]?.value, + ); + return; + } + if (!activePage && pageOptions.length) setActivePage(pageOptions[0]?.value); + }, [activePage, initialSelection, pageOptions]); + useEffect(() => { + if (hasInitializedSelection) return; + if (!pageOptions.length) return; + if (!initialSelection) return; + const requestedPage = + typeof initialSelection === "object" && "page" in initialSelection + ? String(initialSelection.page) + : undefined; + const resolvedPage = + requestedPage && pageOptions.some((item) => item.value === requestedPage) + ? requestedPage + : (pageOptions[0]?.value ?? "home"); + setSelection( + resolvePreviewSelection( + initialSelection.targetKey, + initialSelection.recordId, + visibleTargets, + resolvedPage, + ), + ); + setActivePage(resolvedPage); + setHasInitializedSelection(true); + }, [hasInitializedSelection, initialSelection, pageOptions, selectedPage, visibleTargets]); + useEffect(() => { + if (!initialSelection) setSelection(undefined); + }, [initialSelection, selectedPage, templateContent?.displayName]); useEffect(() => { if (!selection?.recordId) return; const records = @@ -565,6 +603,12 @@ export function PresentationEditor({ ...(config.presentation && typeof config.presentation === "object" ? (config.presentation as Record) : {}), + ...(typeof config.categoryLabel === "string" + ? { categoryLabel: config.categoryLabel } + : {}), + ...(typeof config.area === "string" ? { area: config.area } : {}), + ...(typeof config.series === "string" ? { series: config.series } : {}), + ...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}), heroImage: typeof config.detailHero === "string" ? config.detailHero @@ -573,8 +617,10 @@ export function PresentationEditor({ : null, details: { ...item.presentation.details, - ...(config.details && typeof config.details === "object" - ? (config.details as Record) + ...(config.details && + typeof config.details === "object" && + "background" in config.details + ? (config.details as RuntimeWorkspace["offerings"][number]["presentation"]["details"]) : {}), }, }, diff --git a/apps/admin/src/features/services/ServicesPage.css b/apps/admin/src/features/services/ServicesPage.css index 7c0a5ee..4364ad5 100644 --- a/apps/admin/src/features/services/ServicesPage.css +++ b/apps/admin/src/features/services/ServicesPage.css @@ -16,13 +16,21 @@ overflow: hidden; } +.service-offering-editor__preview > * { + flex-shrink: 0; +} + .service-offering-editor__view { align-self: flex-start; margin-bottom: 10px; } .service-offering-editor__preview > .component-template-preview-shell { - flex: 1; + flex: 1 1 0; + min-height: 0; +} + +.service-offering-editor__preview .component-template-preview { min-height: 0; } @@ -31,13 +39,14 @@ display: flex; flex-direction: column; max-height: 72vh; - overflow-y: auto; padding-right: 4px; } .service-offering-editor__form-scroll { flex: 1; min-height: 0; + overflow-y: auto; + padding-right: 4px; } .service-offering-editor__preview .ant-alert { diff --git a/apps/admin/src/features/services/ServicesPage.tsx b/apps/admin/src/features/services/ServicesPage.tsx index ebcd76d..cf2ed72 100644 --- a/apps/admin/src/features/services/ServicesPage.tsx +++ b/apps/admin/src/features/services/ServicesPage.tsx @@ -21,7 +21,6 @@ import type { TemplateAdminSection, } from "@personal-brand/api-client"; import { useMemo, useState } from "react"; -import { useEffect, useRef } from "react"; import { createApiClient } from "../../lib/api.js"; import { AdminPageHeader } from "../../components/AdminPageHeader.js"; import { ImageUrlField } from "../../components/ImageUrlField.js"; @@ -44,13 +43,12 @@ export function ServicesPage() { const [offeringForm] = Form.useForm(); const [offeringOpen, setOfferingOpen] = useState(false); const [editingOffering, setEditingOffering] = useState(null); + const [offeringDraftVersion, setOfferingDraftVersion] = useState(0); const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail"); - const listFieldsRef = useRef(null); - const detailFieldsRef = useRef(null); - const formScrollRef = useRef(null); const offerings = useQuery({ queryKey: ["admin-offerings"], queryFn: () => client.listAdminOfferings(), + refetchOnMount: "always", }); const workspace = useQuery({ queryKey: ["admin-workspace-offering-fields"], @@ -59,6 +57,7 @@ export function ServicesPage() { const previewWorkspace = useQuery({ queryKey: ["admin-preview-workspace-services"], queryFn: () => client.getAdminPreviewWorkspace(), + refetchOnMount: "always", }); const templateFields: TemplateAdminField[] = ( workspace.data?.templateContent?.admin.sections ?? [] @@ -134,14 +133,10 @@ export function ServicesPage() { ), [templateFields, listFields, detailFields], ); - useEffect(() => { - const target = previewPage === "offerings" ? listFieldsRef.current : detailFieldsRef.current; - if (!target || !formScrollRef.current) return; - formScrollRef.current.scrollTo({ - top: target.offsetTop - formScrollRef.current.offsetTop - 12, - behavior: "smooth", - }); - }, [previewPage, editingOffering?.id]); + const activeTemplateFields = + previewPage === "offerings" + ? [...listFields, ...otherFields.filter((field) => field.page === "offerings")] + : [...detailFields, ...otherFields.filter((field) => field.page === "detail")]; const previewWorkspaceDraft = useMemo(() => { if (!previewWorkspace.data || !editingOffering) return undefined; const values = offeringForm.getFieldsValue(true) as Record; @@ -184,19 +179,34 @@ export function ServicesPage() { ...(config.presentation && typeof config.presentation === "object" ? (config.presentation as Record) : {}), + ...(typeof config.categoryLabel === "string" + ? { categoryLabel: config.categoryLabel } + : {}), + ...(typeof config.area === "string" ? { area: config.area } : {}), + ...(typeof config.series === "string" ? { series: config.series } : {}), + ...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}), heroImage: typeof config.detailHero === "string" ? config.detailHero : typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim() ? offeringValues.coverUrl : (item.coverUrl ?? null), + details: { + ...item.presentation.details, + ...(config.details && typeof config.details === "object" + ? { + ...item.presentation.details, + ...(config.details as Record), + } + : {}), + }, }, } : item, ), brand: previewWorkspace.data.brand, }; - }, [previewWorkspace.data, editingOffering, templateFields]); + }, [previewWorkspace.data, editingOffering, templateFields, offeringDraftVersion]); const saveOffering = useMutation({ mutationFn: (values: Record) => { const fields = Object.fromEntries( @@ -217,7 +227,10 @@ export function ServicesPage() { setOfferingOpen(false); setEditingOffering(null); offeringForm.resetFields(); + offeringForm.setFieldsValue({}); void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] }); + void queryClient.invalidateQueries({ queryKey: ["admin-workspace-offering-fields"] }); + void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace-services"] }); }, }); const deleteOffering = useMutation({ @@ -412,6 +425,7 @@ export function ServicesPage() { setOfferingDraftVersion((version) => version + 1)} onFinish={(values) => saveOffering.mutate(values as Record)} > -
+
基础信息