feat: 业务视图切换联动字段分组

This commit is contained in:
que01 committed 2026-10-10 17:37:12 +08:00
1 parent 46b1690f6c
commit bfbcee45bb
2 files changed
+87 -50

No files matched your search

@@ -28,11 +28,22 @@
.service-offering-editor__form { .service-offering-editor__form {
min-width: 0; min-width: 0;
display: flex;
flex-direction: column;
max-height: 72vh; max-height: 72vh;
overflow-y: auto; overflow-y: auto;
padding-right: 4px; padding-right: 4px;
} }
.service-offering-editor__form-scroll {
flex: 1;
min-height: 0;
}
.service-offering-editor__preview .ant-alert {
margin-bottom: 10px;
}
@media (max-width: 860px) { @media (max-width: 860px) {
.service-offering-editor { .service-offering-editor {
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
@@ -1,4 +1,5 @@
import { import {
Alert,
Button, Button,
Form, Form,
Input, Input,
@@ -20,6 +21,7 @@ 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 { useEffect, useRef } from "react";
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";
@@ -43,6 +45,9 @@ export function ServicesPage() {
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 [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
const listFieldsRef = useRef<HTMLDivElement | null>(null);
const detailFieldsRef = useRef<HTMLDivElement | null>(null);
const formScrollRef = useRef<HTMLDivElement | null>(null);
const offerings = useQuery({ const offerings = useQuery({
queryKey: ["admin-offerings"], queryKey: ["admin-offerings"],
queryFn: () => client.listAdminOfferings(), queryFn: () => client.listAdminOfferings(),
@@ -129,6 +134,14 @@ export function ServicesPage() {
), ),
[templateFields, listFields, detailFields], [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 previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => { const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
if (!previewWorkspace.data || !editingOffering) return undefined; if (!previewWorkspace.data || !editingOffering) return undefined;
const values = offeringForm.getFieldsValue(true) as Record<string, unknown>; const values = offeringForm.getFieldsValue(true) as Record<string, unknown>;
@@ -386,6 +399,16 @@ export function ServicesPage() {
]} ]}
onChange={(value) => setPreviewPage(value as "offerings" | "detail")} onChange={(value) => setPreviewPage(value as "offerings" | "detail")}
/> />
<Alert
type="info"
showIcon
message={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
description={
previewPage === "offerings"
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
}
/>
<ComponentTemplatePreview <ComponentTemplatePreview
workspace={previewWorkspaceDraft} workspace={previewWorkspaceDraft}
page={previewPage} page={previewPage}
@@ -407,60 +430,63 @@ export function ServicesPage() {
layout="vertical" layout="vertical"
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)} onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
> >
<Form.Item name="kind" label="类型" rules={[{ required: true }]}> <div ref={formScrollRef} className="service-offering-editor__form-scroll">
<Select <Typography.Title level={5}>基础信息</Typography.Title>
options={[ <Form.Item name="kind" label="类型" rules={[{ required: true }]}>
{ value: "service", label: "服务" }, <Select
{ value: "product", label: "定制产品" }, options={[
{ value: "package", label: "套餐" }, { value: "service", label: "服务" },
{ value: "subscription", 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} />
</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> >
<Input type="number" min={0} max={9999} />
</Form.Item>
<Form.Item name="isEnabled" label="公开状态">
<Select
options={[
{ value: true, label: "已启用" },
{ value: false, label: "已停用" },
]}
/>
</Form.Item>
</div>
{templateFields.length ? ( {templateFields.length ? (
<> <>
<Typography.Paragraph type="secondary"> <Typography.Paragraph type="secondary">
以下模板字段与左侧预览及小程序页面编辑的是同一份业务数据。 以下模板字段与左侧预览及小程序页面编辑的是同一份业务数据。
</Typography.Paragraph> </Typography.Paragraph>
{listFields.length ? ( {listFields.length ? (
<> <div ref={listFieldsRef}>
<Typography.Title level={5}>列表展示</Typography.Title> <Typography.Title level={5}>列表展示</Typography.Title>
<RecordContentFields <RecordContentFields
section={{ section={{
@@ -468,10 +494,10 @@ export function ServicesPage() {
fields: listFields, fields: listFields,
}} }}
/> />
</> </div>
) : null} ) : null}
{detailFields.length ? ( {detailFields.length ? (
<> <div ref={detailFieldsRef}>
<Typography.Title level={5}>详情展示</Typography.Title> <Typography.Title level={5}>详情展示</Typography.Title>
<RecordContentFields <RecordContentFields
section={{ section={{
@@ -479,7 +505,7 @@ export function ServicesPage() {
fields: detailFields, fields: detailFields,
}} }}
/> />
</> </div>
) : null} ) : null}
{otherFields.length ? ( {otherFields.length ? (
<> <>