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 {
|
.service-offering-editor__preview {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
height: 72vh;
|
height: 72vh;
|
||||||
border: 1px solid #e5e7eb;
|
border: 1px solid #e5e7eb;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
overflow: hidden;
|
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 {
|
.service-offering-editor__form {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
max-height: 72vh;
|
max-height: 72vh;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
Popconfirm,
|
Popconfirm,
|
||||||
|
Segmented,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
@@ -19,7 +20,6 @@ import type {
|
|||||||
TemplateAdminSection,
|
TemplateAdminSection,
|
||||||
} from "@personal-brand/api-client";
|
} from "@personal-brand/api-client";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { projectBrandAliases } from "@personal-brand/api-client";
|
|
||||||
import { createApiClient } from "../../lib/api.js";
|
import { createApiClient } from "../../lib/api.js";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||||
@@ -42,6 +42,7 @@ export function ServicesPage() {
|
|||||||
const [offeringForm] = Form.useForm();
|
const [offeringForm] = Form.useForm();
|
||||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||||
|
const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
|
||||||
const offerings = useQuery({
|
const offerings = useQuery({
|
||||||
queryKey: ["admin-offerings"],
|
queryKey: ["admin-offerings"],
|
||||||
queryFn: () => client.listAdminOfferings(),
|
queryFn: () => client.listAdminOfferings(),
|
||||||
@@ -94,7 +95,7 @@ export function ServicesPage() {
|
|||||||
const previewTargets = useMemo<PreviewTarget[]>(
|
const previewTargets = useMemo<PreviewTarget[]>(
|
||||||
() =>
|
() =>
|
||||||
(workspace.data?.templateContent?.admin.sections ?? [])
|
(workspace.data?.templateContent?.admin.sections ?? [])
|
||||||
.filter((section) => section.page === "offerings")
|
.filter((section) => section.page === previewPage)
|
||||||
.flatMap((section) =>
|
.flatMap((section) =>
|
||||||
(section.previewTargets ?? []).map((target) => ({
|
(section.previewTargets ?? []).map((target) => ({
|
||||||
...target,
|
...target,
|
||||||
@@ -109,15 +110,41 @@ export function ServicesPage() {
|
|||||||
),
|
),
|
||||||
[workspace.data?.templateContent],
|
[workspace.data?.templateContent],
|
||||||
);
|
);
|
||||||
const previewPageWorkspace = useMemo<RuntimeWorkspace | undefined>(() => {
|
const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
|
||||||
if (!previewWorkspace.data || !editingOffering) return 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 {
|
return {
|
||||||
...previewWorkspace.data,
|
...previewWorkspace.data,
|
||||||
offerings: previewWorkspace.data.offerings.map((item) =>
|
offerings: previewWorkspace.data.offerings.map((item) =>
|
||||||
item.id === editingOffering.id
|
item.id === editingOffering.id
|
||||||
? {
|
? {
|
||||||
...item,
|
...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,
|
config,
|
||||||
presentation: {
|
presentation: {
|
||||||
...item.presentation,
|
...item.presentation,
|
||||||
@@ -128,14 +155,16 @@ export function ServicesPage() {
|
|||||||
heroImage:
|
heroImage:
|
||||||
typeof config.detailHero === "string"
|
typeof config.detailHero === "string"
|
||||||
? config.detailHero
|
? config.detailHero
|
||||||
: (editingOffering.coverUrl ?? null),
|
: typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||||
|
? offeringValues.coverUrl
|
||||||
|
: (item.coverUrl ?? null),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: item,
|
: item,
|
||||||
),
|
),
|
||||||
brand: projectBrandAliases(previewWorkspace.data.brand, config),
|
brand: previewWorkspace.data.brand,
|
||||||
};
|
};
|
||||||
}, [previewWorkspace.data, editingOffering]);
|
}, [previewWorkspace.data, editingOffering, templateFields]);
|
||||||
const saveOffering = useMutation({
|
const saveOffering = useMutation({
|
||||||
mutationFn: (values: Record<string, unknown>) => {
|
mutationFn: (values: Record<string, unknown>) => {
|
||||||
const fields = Object.fromEntries(
|
const fields = Object.fromEntries(
|
||||||
@@ -327,11 +356,20 @@ export function ServicesPage() {
|
|||||||
confirmLoading={saveOffering.isPending}
|
confirmLoading={saveOffering.isPending}
|
||||||
>
|
>
|
||||||
<div className="service-offering-editor">
|
<div className="service-offering-editor">
|
||||||
{editingOffering && previewPageWorkspace ? (
|
{editingOffering && previewWorkspaceDraft ? (
|
||||||
<div className="service-offering-editor__preview">
|
<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
|
<ComponentTemplatePreview
|
||||||
workspace={previewPageWorkspace}
|
workspace={previewWorkspaceDraft}
|
||||||
page="offerings"
|
page={previewPage}
|
||||||
targets={previewTargets}
|
targets={previewTargets}
|
||||||
selection={{ targetKey: visualOfferingTarget.key, recordId: editingOffering.id }}
|
selection={{ targetKey: visualOfferingTarget.key, recordId: editingOffering.id }}
|
||||||
onTargetSelected={() => {}}
|
onTargetSelected={() => {}}
|
||||||
|
|||||||
Reference in new issue
Block a user