Files
persionalBrand/apps/admin/src/features/services/OfferingEditorModal.tsx
T
que01 3ef46b0aa8 feat: 完善后台设计语言细节
- 统一说明文案层级:Typography.Paragraph 次要文案迁移到 admin-section-description
- 状态色补齐边框与中间调令牌,Alert/错误条/Descriptions 与 StatusTag 同源
- 咨询详情描述列表去表格线,改为键值展示并统一令牌
- 新增 BrandMark,侧栏与登录页标识改用品牌首字
- 信任内容改用列表行,空状态、表格骨架屏、主按钮脏检查落地
- design.md 同步令牌映射、切换控件选型与组件清单
2026-10-14 11:21:31 +08:00

182 lines
6.5 KiB
TypeScript

import { Alert, Button, Form, Input, Modal, Segmented, Select } from "antd";
import type {
Offering,
RuntimeWorkspace,
TemplateAdminField,
TemplateAdminSection,
} from "@personal-brand/api-client";
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 type { FormInstance } from "antd";
import "./ServicesPage.css";
type OfferingEditorModalProps = {
open: boolean;
editingOffering: Offering | null;
form: FormInstance<Record<string, unknown>>;
previewPage: "offerings" | "detail";
previewWorkspace: RuntimeWorkspace | undefined;
previewTargets: Record<"offerings" | "detail", PreviewTarget[]>;
activeTemplateFields: TemplateAdminField[];
templateFieldSection: TemplateAdminSection;
hasTemplateDetailCopy: boolean;
listTarget: PreviewTarget;
detailTarget: PreviewTarget | undefined;
saving: boolean;
onClose: () => void;
onPreviewPageChange: (page: "offerings" | "detail") => void;
onValuesChange: (values: Record<string, unknown>) => void;
onFinish: (values: Record<string, unknown>) => void;
onEditInBrand: () => void;
};
export function OfferingEditorModal({
open,
editingOffering,
form,
previewPage,
previewWorkspace,
previewTargets,
activeTemplateFields,
templateFieldSection,
hasTemplateDetailCopy,
listTarget,
detailTarget,
saving,
onClose,
onPreviewPageChange,
onValuesChange,
onFinish,
onEditInBrand,
}: OfferingEditorModalProps) {
return (
<Modal
open={open}
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
width={960}
onCancel={onClose}
onOk={() => form.submit()}
confirmLoading={saving}
>
<div className="service-offering-editor">
{editingOffering && previewWorkspace ? (
<div className="service-offering-editor__preview">
<Segmented
className="service-offering-editor__view"
value={previewPage}
options={[
{ value: "offerings", label: "列表卡片" },
{ value: "detail", label: "详情内容" },
]}
onChange={onPreviewPageChange}
/>
<Alert
type="info"
showIcon
message={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
description={
previewPage === "offerings"
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
}
/>
<ComponentTemplatePreview
workspace={previewWorkspace}
page={previewPage}
offeringId={editingOffering.id}
targets={previewTargets[previewPage]}
selection={{
targetKey: previewPage === "offerings" ? listTarget.key : (detailTarget?.key ?? ""),
recordId: editingOffering.id,
}}
onTargetSelected={() => {}}
/>
</div>
) : null}
<Form
className="service-offering-editor__form"
form={form}
layout="vertical"
onValuesChange={(_, allValues) => onValuesChange(allValues)}
onFinish={onFinish}
>
<div className="service-offering-editor__form-scroll">
<h4 className="admin-subhead">基础信息</h4>
<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} />
</Form.Item>
) : null}
<Form.Item name="priceText" label="价格展示">
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
</Form.Item>
<Form.Item
name="coverUrl"
label="封面图片地址"
help="点击上传,或粘贴服务/产品封面图片地址。"
>
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" scope="offering" />
</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>
{activeTemplateFields.length ? (
<div>
<h4 className="admin-subhead">
{previewPage === "offerings" ? "列表展示字段" : "详情展示字段"}
</h4>
<p className="admin-section-description admin-offset-bottom">
这里只编辑左侧预览对应的字段;它们与小程序页面编辑的是同一份业务数据。
</p>
<RecordContentFields
section={{
...templateFieldSection,
fields: activeTemplateFields,
}}
sectionKey="offering"
/>
</div>
) : null}
{editingOffering ? (
<Button htmlType="button" onClick={onEditInBrand}>
在小程序页面编辑
</Button>
) : null}
</div>
</Form>
</div>
</Modal>
);
}