feat: 业务编辑弹窗接入预览画布
This commit is contained in:
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,14 +14,18 @@ import {
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import type {
|
import type {
|
||||||
Offering,
|
Offering,
|
||||||
|
RuntimeWorkspace,
|
||||||
TemplateAdminField,
|
TemplateAdminField,
|
||||||
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";
|
||||||
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
||||||
|
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||||
|
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||||
import {
|
import {
|
||||||
applyPresentationValues,
|
applyPresentationValues,
|
||||||
presentationFieldName,
|
presentationFieldName,
|
||||||
@@ -29,6 +33,7 @@ import {
|
|||||||
} from "../brand/presentation-bindings.js";
|
} from "../brand/presentation-bindings.js";
|
||||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import "./ServicesPage.css";
|
||||||
|
|
||||||
export function ServicesPage() {
|
export function ServicesPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -45,6 +50,10 @@ export function ServicesPage() {
|
|||||||
queryKey: ["admin-workspace-offering-fields"],
|
queryKey: ["admin-workspace-offering-fields"],
|
||||||
queryFn: () => client.getAdminWorkspace(),
|
queryFn: () => client.getAdminWorkspace(),
|
||||||
});
|
});
|
||||||
|
const previewWorkspace = useQuery({
|
||||||
|
queryKey: ["admin-preview-workspace-services"],
|
||||||
|
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||||
|
});
|
||||||
const templateFields: TemplateAdminField[] = (
|
const templateFields: TemplateAdminField[] = (
|
||||||
workspace.data?.templateContent?.admin.sections ?? []
|
workspace.data?.templateContent?.admin.sections ?? []
|
||||||
)
|
)
|
||||||
@@ -82,6 +91,51 @@ export function ServicesPage() {
|
|||||||
const hasTemplateDetailCopy = templateFields.some(
|
const hasTemplateDetailCopy = templateFields.some(
|
||||||
(field) => field.binding === "offering.config.details.background",
|
(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({
|
const saveOffering = useMutation({
|
||||||
mutationFn: (values: Record<string, unknown>) => {
|
mutationFn: (values: Record<string, unknown>) => {
|
||||||
const fields = Object.fromEntries(
|
const fields = Object.fromEntries(
|
||||||
@@ -263,6 +317,7 @@ export function ServicesPage() {
|
|||||||
<Modal
|
<Modal
|
||||||
open={offeringOpen}
|
open={offeringOpen}
|
||||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||||
|
width={960}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setOfferingOpen(false);
|
setOfferingOpen(false);
|
||||||
setEditingOffering(null);
|
setEditingOffering(null);
|
||||||
@@ -271,82 +326,96 @@ export function ServicesPage() {
|
|||||||
onOk={() => offeringForm.submit()}
|
onOk={() => offeringForm.submit()}
|
||||||
confirmLoading={saveOffering.isPending}
|
confirmLoading={saveOffering.isPending}
|
||||||
>
|
>
|
||||||
<Form
|
<div className="service-offering-editor">
|
||||||
form={offeringForm}
|
{editingOffering && previewPageWorkspace ? (
|
||||||
layout="vertical"
|
<div className="service-offering-editor__preview">
|
||||||
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
|
<ComponentTemplatePreview
|
||||||
>
|
workspace={previewPageWorkspace}
|
||||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
page="offerings"
|
||||||
<Select
|
targets={previewTargets}
|
||||||
options={[
|
selection={{ targetKey: visualOfferingTarget.key, recordId: editingOffering.id }}
|
||||||
{ value: "service", label: "服务" },
|
onTargetSelected={() => {}}
|
||||||
{ value: "product", label: "定制产品" },
|
/>
|
||||||
{ value: "package", label: "套餐" },
|
</div>
|
||||||
{ value: "subscription", label: "订阅" },
|
) : null}
|
||||||
]}
|
<Form
|
||||||
/>
|
className="service-offering-editor__form"
|
||||||
</Form.Item>
|
form={offeringForm}
|
||||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
layout="vertical"
|
||||||
<Input />
|
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
|
||||||
</Form.Item>
|
>
|
||||||
<Form.Item name="summary" label="一句话说明">
|
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Select
|
||||||
</Form.Item>
|
options={[
|
||||||
{!hasTemplateDetailCopy ? (
|
{ value: "service", label: "服务" },
|
||||||
<Form.Item name="description" label="详细介绍">
|
{ value: "product", label: "定制产品" },
|
||||||
<Input.TextArea rows={5} />
|
{ value: "package", label: "套餐" },
|
||||||
|
{ value: "subscription", label: "订阅" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
) : null}
|
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||||
<Form.Item name="priceText" label="价格展示">
|
<Input />
|
||||||
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
</Form.Item>
|
||||||
</Form.Item>
|
<Form.Item name="summary" label="一句话说明">
|
||||||
<Form.Item
|
<Input />
|
||||||
name="coverUrl"
|
</Form.Item>
|
||||||
label="封面图片地址"
|
{!hasTemplateDetailCopy ? (
|
||||||
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
|
<Form.Item name="description" label="详细介绍">
|
||||||
>
|
<Input.TextArea rows={5} />
|
||||||
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
|
</Form.Item>
|
||||||
</Form.Item>
|
) : null}
|
||||||
<Form.Item
|
<Form.Item name="priceText" label="价格展示">
|
||||||
name="sortOrder"
|
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
||||||
label="展示顺序"
|
</Form.Item>
|
||||||
help="数字越小越靠前,不确定时填写 0。"
|
<Form.Item
|
||||||
rules={[{ type: "number", min: 0, max: 9999 }]}
|
name="coverUrl"
|
||||||
>
|
label="封面图片地址"
|
||||||
<Input type="number" min={0} max={9999} />
|
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
|
||||||
</Form.Item>
|
>
|
||||||
<Form.Item name="isEnabled" label="公开状态">
|
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
|
||||||
<Select
|
</Form.Item>
|
||||||
options={[
|
<Form.Item
|
||||||
{ value: true, label: "已启用" },
|
name="sortOrder"
|
||||||
{ value: false, label: "已停用" },
|
label="展示顺序"
|
||||||
]}
|
help="数字越小越靠前,不确定时填写 0。"
|
||||||
/>
|
rules={[{ type: "number", min: 0, max: 9999 }]}
|
||||||
</Form.Item>
|
>
|
||||||
{templateFields.length ? (
|
<Input type="number" min={0} max={9999} />
|
||||||
<>
|
</Form.Item>
|
||||||
<Typography.Paragraph type="secondary">
|
<Form.Item name="isEnabled" label="公开状态">
|
||||||
以下模板字段与小程序页面编辑的是同一份业务数据;可在此集中修改,也可到页面编辑中点选对应卡片。
|
<Select
|
||||||
</Typography.Paragraph>
|
options={[
|
||||||
<RecordContentFields section={templateFieldSection} />
|
{ value: true, label: "已启用" },
|
||||||
{editingOffering ? (
|
{ value: false, label: "已停用" },
|
||||||
<Button
|
]}
|
||||||
htmlType="button"
|
/>
|
||||||
onClick={() =>
|
</Form.Item>
|
||||||
navigate("/admin/brand", {
|
{templateFields.length ? (
|
||||||
state: {
|
<>
|
||||||
targetKey: visualOfferingTarget.key,
|
<Typography.Paragraph type="secondary">
|
||||||
recordId: editingOffering.id,
|
以下模板字段与左侧预览及小程序页面编辑的是同一份业务数据。
|
||||||
},
|
</Typography.Paragraph>
|
||||||
})
|
<RecordContentFields section={templateFieldSection} />
|
||||||
}
|
{editingOffering ? (
|
||||||
>
|
<Button
|
||||||
在小程序页面编辑
|
htmlType="button"
|
||||||
</Button>
|
onClick={() =>
|
||||||
) : null}
|
navigate("/admin/brand", {
|
||||||
</>
|
state: {
|
||||||
) : null}
|
targetKey: visualOfferingTarget.key,
|
||||||
</Form>
|
recordId: editingOffering.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
在小程序页面编辑
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</QueryState>
|
</QueryState>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user