feat: 完善模板内容后台配置能力
This commit is contained in:
1 parent
2bc2193b44
commit
9266ec824a
37 files changed
+2273
-63
No files matched your search
@@ -16,6 +16,7 @@ import { useEffect, useMemo } from "react";
|
||||
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
@@ -62,7 +63,16 @@ export function PresentationEditor({
|
||||
}: PresentationEditorProps) {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const sections = templateContent?.admin.sections ?? [];
|
||||
const sections = useMemo(
|
||||
() =>
|
||||
(templateContent?.admin.sections ?? [])
|
||||
.map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter((field) => field.binding.startsWith("brand.config.")),
|
||||
}))
|
||||
.filter((section) => section.fields.length > 0),
|
||||
[templateContent],
|
||||
);
|
||||
const initialValues = useMemo(() => {
|
||||
const values: PresentationValues = {};
|
||||
for (const section of sections) {
|
||||
@@ -70,6 +80,7 @@ export function PresentationEditor({
|
||||
values[presentationFieldName(section.key, field.key)] = readPresentationValue(
|
||||
config,
|
||||
field.binding,
|
||||
field,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +93,7 @@ export function PresentationEditor({
|
||||
return createApiClient().updateAdminBrand({ config: nextConfig });
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("页面内容已保存,小程序将使用最新内容");
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||
@@ -125,17 +136,28 @@ export function PresentationEditor({
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col key={field.key} xs={24} md={field.input === "textarea" ? 24 : 12}>
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
Reference in new issue
Block a user