feat: 完善模板字段编辑与分类治理
This commit is contained in:
1 parent
91322fa9a0
commit
26bcb2b66e
23 files changed
+631
-250
No files matched your search
@@ -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}
|
||||
|
||||
Reference in new issue
Block a user