feat: 支持后台配置业务提供项详情内容
This commit is contained in:
1 parent
09841aed05
commit
7f0830567e
1 file changed
+54
-2
@@ -77,7 +77,35 @@ export function ServicesPage() {
|
||||
const beginOffering = (item?: Offering) => {
|
||||
setEditingOffering(item ?? null);
|
||||
setOfferingOpen(true);
|
||||
offeringForm.setFieldsValue(item ?? { kind: "service", isEnabled: true, sortOrder: 0 });
|
||||
offeringForm.setFieldsValue(
|
||||
item
|
||||
? {
|
||||
...item,
|
||||
sections: JSON.stringify(item.sections ?? [], null, 2),
|
||||
media: JSON.stringify(item.media ?? [], null, 2),
|
||||
cta: JSON.stringify(item.cta ?? null, null, 2),
|
||||
}
|
||||
: {
|
||||
kind: "service",
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
sections: "[]",
|
||||
media: "[]",
|
||||
cta: "null",
|
||||
},
|
||||
);
|
||||
};
|
||||
const parseOfferingValues = (values: Record<string, unknown>) => {
|
||||
for (const key of ["sections", "media", "cta"]) {
|
||||
if (typeof values[key] === "string") {
|
||||
try {
|
||||
values[key] = JSON.parse(values[key] as string);
|
||||
} catch {
|
||||
throw new Error(`${key} 必须是合法 JSON`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return values;
|
||||
};
|
||||
return (
|
||||
<Card
|
||||
@@ -163,7 +191,13 @@ export function ServicesPage() {
|
||||
<Form
|
||||
form={offeringForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => saveOffering.mutate(values)}
|
||||
onFinish={(values) => {
|
||||
try {
|
||||
saveOffering.mutate(parseOfferingValues(values));
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "详情配置格式错误");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
@@ -190,6 +224,24 @@ export function ServicesPage() {
|
||||
<Form.Item name="coverUrl" label="封面图片 URL">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="sections" label="内容分区 JSON">
|
||||
<Input.TextArea
|
||||
rows={6}
|
||||
placeholder='例如:[ { "type": "text", "title": "服务内容", "content": "..." } ]'
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="media" label="媒体列表 JSON">
|
||||
<Input.TextArea
|
||||
rows={4}
|
||||
placeholder='例如:[ { "url": "https://...", "type": "image", "alt": "封面" } ]'
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="cta" label="行动按钮 JSON">
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
placeholder='例如:{ "type": "inquiry", "label": "立即咨询" }'
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="isEnabled" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
|
||||
Reference in new issue
Block a user