Commit c54f3162 by chenwq1

refactor: 优化表单验证与保存逻辑

- 移除 `validate` 和 `saveData` 函数中的调试日志。
- 更新 `CustomizeFormValidateResult` 接口,简化数据结构,新增 `CustomizeFormValidateNode` 接口以更好地描述验证节点。
- 修改 `leafRecordFromValidateData` 函数为 `leafRecordFromValidateNode`,以适应新的数据结构。
1 parent d61218e2
Pipeline #98 for c54f3162 failed in 0 seconds
......@@ -95,7 +95,6 @@ function setSubmitData() {
async function validate(): Promise<CustomizeFormValidateResult> {
const nodesData = setSubmitData();
console.log('validate', nodesData);
let success = true;
let message = '';
columnsList.value.forEach((item: any) => {
......@@ -114,7 +113,6 @@ async function validate(): Promise<CustomizeFormValidateResult> {
/** 与 `validate` 相同返回结构,不校验必填,用于静默保存 / 上一步等场景 */
async function saveData(): Promise<CustomizeFormValidateResult> {
const nodesData = setSubmitData();
console.log('saveData', nodesData);
return {
data: nodesData,
message: "操作成功",
......
......@@ -42,15 +42,18 @@ export interface CustomizeFormValidateFieldItem {
valueText?: string;
}
/** 中间表单 validate / saveData 返回体 */
/** 中间表单 validate / saveData 下单个叶子节点(与 `setSubmitData` 一项一致) */
export interface CustomizeFormValidateNode {
nodeId: number | string;
nodeName: string;
resultStatus: number;
remark: string;
data: CustomizeFormValidateFieldItem[];
}
/** 中间表单 validate / saveData 返回体;`data` 为当前二级下多列叶子节点数组 */
export interface CustomizeFormValidateResult {
success: boolean;
message?: string;
data?: {
data: CustomizeFormValidateFieldItem[];
nodeId: number | string;
nodeName: string;
remark: string;
resultStatus: number;
};
data?: CustomizeFormValidateNode[];
}
......@@ -155,7 +155,11 @@
</template>
<script setup lang="ts">
import type { BigModule, CustomizeFormValidateResult } from "@/types/views/car-detail";
import type {
BigModule,
CustomizeFormValidateNode,
CustomizeFormValidateResult,
} from "@/types/views/car-detail";
import type {
CompleteInspectionResultData,
InspectionNode,
......@@ -466,8 +470,7 @@ function advanceInspectionStep() {
}
}
function leafRecordFromValidateData(raw: CustomizeFormValidateResult["data"]): LeafNodeRecord | null {
if (!raw) return null;
function leafRecordFromValidateNode(raw: CustomizeFormValidateNode): LeafNodeRecord {
return {
data: (raw.data ?? []).map((item) => ({
interactionType: item.interactionType ?? "",
......@@ -486,9 +489,10 @@ function leafRecordFromValidateData(raw: CustomizeFormValidateResult["data"]): L
/** `saveData` → 转叶子记录 → `saveInspectionRecord`;无有效数据时不请求接口 */
async function saveCurrentLeafInspectionRecord(nextFlag: boolean): Promise<boolean> {
const saved = (await customizeFormRef.value?.saveData?.()) as CustomizeFormValidateResult | undefined;
const record = saved?.data ? leafRecordFromValidateData(saved.data) : null;
if (!record) return false;
await saveInspectionRecord(buildInspectionSavePayload([record], nextFlag));
const rows = saved?.data;
if (!rows?.length) return false;
const leafNodes = rows.map((row) => leafRecordFromValidateNode(row));
await saveInspectionRecord(buildInspectionSavePayload(leafNodes, nextFlag));
return true;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!