Merge pull request 'refactor: 抽取共享 getFullFormValues 表单读取工具' (#16) from refactor/form-values-helper into main
CI / Browser smoke (push) Has been skipped
CI / Static checks (push) Successful in 48s
CI / API integration (push) Successful in 1m9s
CI / Production build (push) Successful in 1m26s

Reviewed-on: #16
This commit was merged in pull request #16.
This commit is contained in:
que01 committed 2026-10-29 06:32:31 +00:00
commit b0265f3be3
7 files changed
+20 -8

No files matched your search

@@ -1,7 +1,7 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"scope": "模板完成证据登记,保留命令、日志与产物哈希", "scope": "模板完成证据登记,保留命令、日志与产物哈希",
"generatedAt": "2026-10-29T05:47:32.979Z", "generatedAt": "2026-10-29T06:24:26.667Z",
"templates": { "templates": {
"acheng-campus-food": { "acheng-campus-food": {
"real-manifest-interaction": { "real-manifest-interaction": {
@@ -256,5 +256,5 @@
} }
} }
}, },
"sourceTreeHash": "3f8f7d8b0063a1d21d4cf757d7c1b5ea83c3b3a162fd390183b1cb8e76879907" "sourceTreeHash": "5d81aec11fe39aa90095a7855b1cef41d7d48efc92aa19f7c9fd9a2c0b872b11"
} }
@@ -12,6 +12,7 @@ import {
type PresentationValues, type PresentationValues,
} from "../../lib/presentation/presentation-bindings.js"; } from "../../lib/presentation/presentation-bindings.js";
import type { RecordContentSource } from "./types.js"; import type { RecordContentSource } from "./types.js";
import { getFullFormValues } from "../../lib/form-values.js";
function createInitialValues( function createInitialValues(
record: Offering | TrustContent, record: Offering | TrustContent,
@@ -96,12 +97,12 @@ export function useRecordContentEditorState({
}); });
const submit = (values: PresentationValues) => { const submit = (values: PresentationValues) => {
const currentValues = form.getFieldsValue(true) as PresentationValues; const currentValues = getFullFormValues<PresentationValues>(form);
save.mutate({ ...draftValues, ...values, ...currentValues }); save.mutate({ ...draftValues, ...values, ...currentValues });
}; };
const handleValuesChange = (_values: PresentationValues) => { const handleValuesChange = (_values: PresentationValues) => {
const currentValues = form.getFieldsValue(true) as PresentationValues; const currentValues = getFullFormValues<PresentationValues>(form);
const next = { ...draftValues, ..._values, ...currentValues }; const next = { ...draftValues, ..._values, ...currentValues };
setDraftValues(next); setDraftValues(next);
onDraft?.(next); onDraft?.(next);
@@ -11,6 +11,7 @@ import {
} from "../../lib/presentation/presentation-bindings.js"; } from "../../lib/presentation/presentation-bindings.js";
import { fieldTargetTitle } from "./presentation-editor-helpers.js"; import { fieldTargetTitle } from "./presentation-editor-helpers.js";
import type { PreviewTarget } from "./preview-selection.js"; import type { PreviewTarget } from "./preview-selection.js";
import { getFullFormValues } from "../../lib/form-values.js";
interface PresentationFormPanelProps { interface PresentationFormPanelProps {
form: FormInstance<PresentationValues>; form: FormInstance<PresentationValues>;
@@ -44,7 +45,7 @@ export function PresentationFormPanel({
layout="vertical" layout="vertical"
initialValues={initialValues} initialValues={initialValues}
onValuesChange={onValuesChange} onValuesChange={onValuesChange}
onFinish={() => save.mutate(form.getFieldsValue(true) as PresentationValues)} onFinish={() => save.mutate(getFullFormValues<PresentationValues>(form))}
className="presentation-editor__form" className="presentation-editor__form"
> >
<div className="presentation-editor__form-body"> <div className="presentation-editor__form-body">
@@ -11,6 +11,7 @@ import type {
TrustContent, TrustContent,
} from "@personal-brand/api-client"; } from "@personal-brand/api-client";
import { createApiClient } from "../../lib/api.js"; import { createApiClient } from "../../lib/api.js";
import { getFullFormValues } from "../../lib/form-values.js";
import { import {
applyBrandPreviewValues, applyBrandPreviewValues,
applyPresentationValues, applyPresentationValues,
@@ -161,7 +162,7 @@ export function useBrandPreviewDraft({
const handleValuesChange = (changed: PresentationValues, allValues: PresentationValues) => { const handleValuesChange = (changed: PresentationValues, allValues: PresentationValues) => {
onDirty(); onDirty();
const synchronized: PresentationValues = { const synchronized: PresentationValues = {
...(form.getFieldsValue(true) as PresentationValues), ...getFullFormValues<PresentationValues>(form),
...allValues, ...allValues,
}; };
for (const section of sections) { for (const section of sections) {
@@ -12,6 +12,7 @@ import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
import type { PreviewSelection, PreviewTarget } from "../brand/preview-selection.js"; import type { PreviewSelection, PreviewTarget } from "../brand/preview-selection.js";
import type { FormInstance } from "antd"; import type { FormInstance } from "antd";
import "./ServicesPage.css"; import "./ServicesPage.css";
import { getFullFormValues } from "../../lib/form-values.js";
type OfferingEditorModalProps = { type OfferingEditorModalProps = {
open: boolean; open: boolean;
@@ -140,7 +141,7 @@ export function OfferingEditorModal({
onValuesChange={(_, allValues) => onValuesChange(allValues)} onValuesChange={(_, allValues) => onValuesChange(allValues)}
// 动态隐藏的字段会被卸载,onFinish 默认只返回仍挂载的字段。 // 动态隐藏的字段会被卸载,onFinish 默认只返回仍挂载的字段。
// 提交时读取完整表单存储,避免切换区块后隐藏字段的修改丢失。 // 提交时读取完整表单存储,避免切换区块后隐藏字段的修改丢失。
onFinish={() => onFinish(form.getFieldsValue(true) as Record<string, unknown>)} onFinish={() => onFinish(getFullFormValues(form))}
> >
<div ref={formScroll} className="service-offering-editor__form-scroll"> <div ref={formScroll} className="service-offering-editor__form-scroll">
{selectedTarget ? ( {selectedTarget ? (
@@ -6,6 +6,7 @@ import type {
TemplateAdminSection, TemplateAdminSection,
} from "@personal-brand/api-client"; } from "@personal-brand/api-client";
import { offeringDefaultFormValues, offeringEditFormValues } from "./offering-form.js"; import { offeringDefaultFormValues, offeringEditFormValues } from "./offering-form.js";
import { getFullFormValues } from "../../lib/form-values.js";
export type OfferingPreviewPage = "offerings" | "detail"; export type OfferingPreviewPage = "offerings" | "detail";
@@ -40,7 +41,7 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
? offeringEditFormValues(item, templateFields) ? offeringEditFormValues(item, templateFields)
: offeringDefaultFormValues(templateFields), : offeringDefaultFormValues(templateFields),
); );
setFormValues(offeringForm.getFieldsValue(true) as Record<string, unknown>); setFormValues(getFullFormValues(offeringForm));
}; };
const closeOffering = () => { const closeOffering = () => {
+7
View File
@@ -0,0 +1,7 @@
import type { FormInstance } from "antd";
// 动态隐藏的字段会被 Ant Design Form 卸载,onFinish 默认只返回仍挂载的字段。
// 提交时读取完整表单存储,避免切换区块后隐藏字段的修改丢失。
export function getFullFormValues<T = Record<string, unknown>>(form: FormInstance): T {
return form.getFieldsValue(true) as T;
}