feat: 完善模板字段编辑与分类治理

This commit is contained in:
que01 committed 2026-10-11 23:07:53 +08:00
1 parent 91322fa9a0
commit 26bcb2b66e
23 files changed
+631 -250

No files matched your search

@@ -38,15 +38,35 @@
min-width: 0;
display: flex;
flex-direction: column;
max-height: 72vh;
padding-right: 4px;
}
.service-offering-editor__form-scroll {
flex: 1;
min-height: 0;
flex: none;
max-height: 66vh;
overflow-y: auto;
padding-right: 4px;
padding: 20px 16px 24px;
border-radius: 12px;
background: #f8fafc;
border: 1px solid #e5e7eb;
}
.service-offering-editor__form-scroll > .ant-typography:first-child {
margin-top: 0;
}
.service-offering-editor__form-scroll .ant-form-item {
margin-bottom: 20px;
}
.service-offering-editor__form-scroll .ant-typography h5.ant-typography {
margin: 28px 0 4px;
padding-bottom: 8px;
border-bottom: 1px solid #e5e7eb;
}
.service-offering-editor__form-scroll > .ant-typography-secondary {
margin-bottom: 12px;
}
.service-offering-editor__preview .ant-alert {
@@ -45,6 +45,7 @@ export function ServicesPage() {
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
const [offeringDraftVersion, setOfferingDraftVersion] = useState(0);
const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
const [formValues, setFormValues] = useState<Record<string, unknown>>({});
const offerings = useQuery({
queryKey: ["admin-offerings"],
queryFn: () => client.listAdminOfferings(),
@@ -139,7 +140,9 @@ export function ServicesPage() {
: [...detailFields, ...otherFields.filter((field) => field.page === "detail")];
const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
if (!previewWorkspace.data || !editingOffering) return undefined;
const values = offeringForm.getFieldsValue(true) as Record<string, unknown>;
const values: Record<string, unknown> = Object.keys(formValues).length
? formValues
: (offeringForm.getFieldsValue(true) as Record<string, unknown>);
const config = applyPresentationValues(
editingOffering.config,
[{ key: "offering", fields: templateFields }],
@@ -179,9 +182,6 @@ export function ServicesPage() {
...(config.presentation && typeof config.presentation === "object"
? (config.presentation as Record<string, unknown>)
: {}),
...(typeof config.categoryLabel === "string"
? { categoryLabel: config.categoryLabel }
: {}),
...(typeof config.area === "string" ? { area: config.area } : {}),
...(typeof config.series === "string" ? { series: config.series } : {}),
...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}),
@@ -206,7 +206,14 @@ export function ServicesPage() {
),
brand: previewWorkspace.data.brand,
};
}, [previewWorkspace.data, editingOffering, templateFields, offeringDraftVersion]);
}, [
previewWorkspace.data,
editingOffering,
templateFields,
formValues,
offeringDraftVersion,
offeringForm,
]);
const saveOffering = useMutation({
mutationFn: (values: Record<string, unknown>) => {
const fields = Object.fromEntries(
@@ -250,6 +257,7 @@ export function ServicesPage() {
});
const beginOffering = (item?: Offering) => {
setEditingOffering(item ?? null);
setPreviewPage("detail");
setOfferingOpen(true);
offeringForm.setFieldsValue(
item
@@ -263,10 +271,19 @@ export function ServicesPage() {
sortOrder: item.sortOrder,
isEnabled: item.isEnabled,
...Object.fromEntries(
templateFields.map((field) => [
presentationFieldName("offering", field.key),
readPresentationValue(item.config, field.binding, field),
]),
templateFields.map((field) => {
const value = readPresentationValue(item.config, field.binding, field);
return [
presentationFieldName("offering", field.key),
value === undefined || value === null || value === ""
? field.input === "select"
? field.options?.[0]?.value
: field.input === "list"
? []
: undefined
: value,
];
}),
),
}
: {
@@ -281,6 +298,7 @@ export function ServicesPage() {
),
},
);
setFormValues(offeringForm.getFieldsValue(true) as Record<string, unknown>);
};
return (
<QueryState
@@ -442,7 +460,10 @@ export function ServicesPage() {
className="service-offering-editor__form"
form={offeringForm}
layout="vertical"
onValuesChange={() => setOfferingDraftVersion((version) => version + 1)}
onValuesChange={(_, allValues) => {
setFormValues(allValues as Record<string, unknown>);
setOfferingDraftVersion((version) => version + 1);
}}
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
>
<div className="service-offering-editor__form-scroll">
@@ -507,6 +528,7 @@ export function ServicesPage() {
...templateFieldSection,
fields: activeTemplateFields,
}}
sectionKey="offering"
/>
</div>
) : null}