feat: 业务编辑支持列表与详情实时预览
This commit is contained in:
1 parent
569156c977
commit
0e0ca201a7
2 files changed
+60
-10
No files matched your search
@@ -8,12 +8,24 @@
|
||||
|
||||
.service-offering-editor__preview {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 72vh;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.service-offering-editor__view {
|
||||
align-self: flex-start;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.service-offering-editor__preview > .component-template-preview-shell {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.service-offering-editor__form {
|
||||
min-width: 0;
|
||||
max-height: 72vh;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
Input,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Segmented,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
@@ -19,7 +20,6 @@ import type {
|
||||
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";
|
||||
@@ -42,6 +42,7 @@ export function ServicesPage() {
|
||||
const [offeringForm] = Form.useForm();
|
||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||
const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
|
||||
const offerings = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => client.listAdminOfferings(),
|
||||
@@ -94,7 +95,7 @@ export function ServicesPage() {
|
||||
const previewTargets = useMemo<PreviewTarget[]>(
|
||||
() =>
|
||||
(workspace.data?.templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.page === "offerings")
|
||||
.filter((section) => section.page === previewPage)
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
@@ -109,15 +110,41 @@ export function ServicesPage() {
|
||||
),
|
||||
[workspace.data?.templateContent],
|
||||
);
|
||||
const previewPageWorkspace = useMemo<RuntimeWorkspace | undefined>(() => {
|
||||
const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
|
||||
if (!previewWorkspace.data || !editingOffering) return undefined;
|
||||
const config = editingOffering.config ?? {};
|
||||
const values = offeringForm.getFieldsValue(true) as Record<string, unknown>;
|
||||
const config = applyPresentationValues(
|
||||
editingOffering.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
);
|
||||
const offeringValues = {
|
||||
name: values.name,
|
||||
summary: values.summary,
|
||||
description: values.description,
|
||||
priceText: values.priceText,
|
||||
coverUrl: values.coverUrl,
|
||||
};
|
||||
return {
|
||||
...previewWorkspace.data,
|
||||
offerings: previewWorkspace.data.offerings.map((item) =>
|
||||
item.id === editingOffering.id
|
||||
? {
|
||||
...item,
|
||||
name:
|
||||
typeof offeringValues.name === "string" && offeringValues.name.trim()
|
||||
? offeringValues.name
|
||||
: item.name,
|
||||
summary:
|
||||
typeof offeringValues.summary === "string" ? offeringValues.summary : item.summary,
|
||||
priceText:
|
||||
typeof offeringValues.priceText === "string"
|
||||
? offeringValues.priceText
|
||||
: item.priceText,
|
||||
coverUrl:
|
||||
typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: item.coverUrl,
|
||||
config,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
@@ -128,14 +155,16 @@ export function ServicesPage() {
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: (editingOffering.coverUrl ?? null),
|
||||
: typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: (item.coverUrl ?? null),
|
||||
},
|
||||
}
|
||||
: item,
|
||||
),
|
||||
brand: projectBrandAliases(previewWorkspace.data.brand, config),
|
||||
brand: previewWorkspace.data.brand,
|
||||
};
|
||||
}, [previewWorkspace.data, editingOffering]);
|
||||
}, [previewWorkspace.data, editingOffering, templateFields]);
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) => {
|
||||
const fields = Object.fromEntries(
|
||||
@@ -327,11 +356,20 @@ export function ServicesPage() {
|
||||
confirmLoading={saveOffering.isPending}
|
||||
>
|
||||
<div className="service-offering-editor">
|
||||
{editingOffering && previewPageWorkspace ? (
|
||||
{editingOffering && previewWorkspaceDraft ? (
|
||||
<div className="service-offering-editor__preview">
|
||||
<Segmented
|
||||
className="service-offering-editor__view"
|
||||
value={previewPage}
|
||||
options={[
|
||||
{ value: "offerings", label: "列表卡片" },
|
||||
{ value: "detail", label: "详情内容" },
|
||||
]}
|
||||
onChange={(value) => setPreviewPage(value as "offerings" | "detail")}
|
||||
/>
|
||||
<ComponentTemplatePreview
|
||||
workspace={previewPageWorkspace}
|
||||
page="offerings"
|
||||
workspace={previewWorkspaceDraft}
|
||||
page={previewPage}
|
||||
targets={previewTargets}
|
||||
selection={{ targetKey: visualOfferingTarget.key, recordId: editingOffering.id }}
|
||||
onTargetSelected={() => {}}
|
||||
|
||||
Reference in new issue
Block a user