refactor: 抽取业务与信任内容公共编辑器

This commit is contained in:
que01 committed 2026-10-10 17:03:41 +08:00
1 parent d2ce2d2a84
commit d0ef25cfb3
3 files changed
+221 -137

No files matched your search

@@ -12,12 +12,16 @@ import {
message,
} from "antd";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { Offering, TemplateAdminField } from "@personal-brand/api-client";
import { useState } from "react";
import type {
Offering,
TemplateAdminField,
TemplateAdminSection,
} from "@personal-brand/api-client";
import { useMemo, useState } from "react";
import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { ImageUrlField } from "../../components/ImageUrlField.js";
import { TemplateListField } from "../../components/TemplateListField.js";
import { RecordContentFields } from "../../components/RecordContentEditor.js";
import {
applyPresentationValues,
presentationFieldName,
@@ -46,6 +50,17 @@ export function ServicesPage() {
.flatMap((section) =>
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
);
const templateFieldSection = useMemo<TemplateAdminSection>(
() => ({
key: "offering",
title: "模板内容",
description: "",
page: "detail",
target: "offering",
fields: templateFields,
}),
[templateFields],
);
const offeringPageLabel =
workspace.data?.templateContent?.navigation.find((item) => item.page === "offerings")?.label ??
"业务展示页";
@@ -299,30 +314,14 @@ export function ServicesPage() {
]}
/>
</Form.Item>
{templateFields.map((field) =>
field.input === "list" ? (
<TemplateListField
key={field.key}
field={field}
name={presentationFieldName("offering", field.key)}
/>
) : (
<Form.Item
key={field.key}
name={presentationFieldName("offering", field.key)}
label={field.label}
help={field.help}
>
{field.input === "textarea" ? (
<Input.TextArea rows={3} />
) : field.input === "image" ? (
<ImageUrlField />
) : (
<Input />
)}
</Form.Item>
),
)}
{templateFields.length ? (
<>
<Typography.Paragraph type="secondary">
以下模板字段与小程序页面编辑的是同一份业务数据;可在此集中修改,也可到页面编辑中点选对应卡片。
</Typography.Paragraph>
<RecordContentFields section={templateFieldSection} />
</>
) : null}
</Form>
</Modal>
</QueryState>