feat: 业务编辑弹窗接入预览画布

This commit is contained in:
que01 committed 2026-10-10 17:21:00 +08:00
1 parent 20e7e8bb81
commit 569156c977
2 files changed
+182 -75

No files matched your search

@@ -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;
}
}
+144 -75
View File
@@ -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<PreviewTarget[]>(
() =>
(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<RuntimeWorkspace | undefined>(() => {
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<string, unknown>)
: {}),
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<string, unknown>) => {
const fields = Object.fromEntries(
@@ -263,6 +317,7 @@ export function ServicesPage() {
<Modal
open={offeringOpen}
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
width={960}
onCancel={() => {
setOfferingOpen(false);
setEditingOffering(null);
@@ -271,82 +326,96 @@ export function ServicesPage() {
onOk={() => offeringForm.submit()}
confirmLoading={saveOffering.isPending}
>
<Form
form={offeringForm}
layout="vertical"
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
>
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
<Select
options={[
{ value: "service", label: "服务" },
{ value: "product", label: "定制产品" },
{ value: "package", label: "套餐" },
{ value: "subscription", label: "订阅" },
]}
/>
</Form.Item>
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
<Input />
</Form.Item>
<Form.Item name="summary" label="一句话说明">
<Input />
</Form.Item>
{!hasTemplateDetailCopy ? (
<Form.Item name="description" label="详细介绍">
<Input.TextArea rows={5} />
<div className="service-offering-editor">
{editingOffering && previewPageWorkspace ? (
<div className="service-offering-editor__preview">
<ComponentTemplatePreview
workspace={previewPageWorkspace}
page="offerings"
targets={previewTargets}
selection={{ targetKey: visualOfferingTarget.key, recordId: editingOffering.id }}
onTargetSelected={() => {}}
/>
</div>
) : null}
<Form
className="service-offering-editor__form"
form={offeringForm}
layout="vertical"
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
>
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
<Select
options={[
{ value: "service", label: "服务" },
{ value: "product", label: "定制产品" },
{ value: "package", label: "套餐" },
{ value: "subscription", label: "订阅" },
]}
/>
</Form.Item>
) : null}
<Form.Item name="priceText" label="价格展示">
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
</Form.Item>
<Form.Item
name="coverUrl"
label="封面图片地址"
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
>
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
</Form.Item>
<Form.Item
name="sortOrder"
label="展示顺序"
help="数字越小越靠前,不确定时填写 0。"
rules={[{ type: "number", min: 0, max: 9999 }]}
>
<Input type="number" min={0} max={9999} />
</Form.Item>
<Form.Item name="isEnabled" label="公开状态">
<Select
options={[
{ value: true, label: "已启用" },
{ value: false, label: "已停用" },
]}
/>
</Form.Item>
{templateFields.length ? (
<>
<Typography.Paragraph type="secondary">
以下模板字段与小程序页面编辑的是同一份业务数据;可在此集中修改,也可到页面编辑中点选对应卡片。
</Typography.Paragraph>
<RecordContentFields section={templateFieldSection} />
{editingOffering ? (
<Button
htmlType="button"
onClick={() =>
navigate("/admin/brand", {
state: {
targetKey: visualOfferingTarget.key,
recordId: editingOffering.id,
},
})
}
>
在小程序页面编辑
</Button>
) : null}
</>
) : null}
</Form>
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
<Input />
</Form.Item>
<Form.Item name="summary" label="一句话说明">
<Input />
</Form.Item>
{!hasTemplateDetailCopy ? (
<Form.Item name="description" label="详细介绍">
<Input.TextArea rows={5} />
</Form.Item>
) : null}
<Form.Item name="priceText" label="价格展示">
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
</Form.Item>
<Form.Item
name="coverUrl"
label="封面图片地址"
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
>
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
</Form.Item>
<Form.Item
name="sortOrder"
label="展示顺序"
help="数字越小越靠前,不确定时填写 0。"
rules={[{ type: "number", min: 0, max: 9999 }]}
>
<Input type="number" min={0} max={9999} />
</Form.Item>
<Form.Item name="isEnabled" label="公开状态">
<Select
options={[
{ value: true, label: "已启用" },
{ value: false, label: "已停用" },
]}
/>
</Form.Item>
{templateFields.length ? (
<>
<Typography.Paragraph type="secondary">
以下模板字段与左侧预览及小程序页面编辑的是同一份业务数据。
</Typography.Paragraph>
<RecordContentFields section={templateFieldSection} />
{editingOffering ? (
<Button
htmlType="button"
onClick={() =>
navigate("/admin/brand", {
state: {
targetKey: visualOfferingTarget.key,
recordId: editingOffering.id,
},
})
}
>
在小程序页面编辑
</Button>
) : null}
</>
) : null}
</Form>
</div>
</Modal>
</QueryState>
);