Sfoglia il codice sorgente

修复隔离点NFc和序列号的传递问题

pm 3 mesi fa
parent
commit
e4f297a8d5
2 ha cambiato i file con 18 aggiunte e 8 eliminazioni
  1. 2 2
      src/api/spm/index.ts
  2. 16 6
      src/components/SegregationPointForm.tsx

+ 2 - 2
src/api/spm/index.ts

@@ -8,11 +8,11 @@ export interface SegregationPointVO {
   pointName: string;
   pointIcon?: string;
   pointPicture?: string;
-  pointNfc: string;
+  pointNfc: string | null; // pointNfc 可能为 null
   workstationId: number;
   lotoId: number | null; // lotoId 可能为 null
   powerType?: string;
-  pointSerialNumber?: string;
+  pointSerialNumber?: string | null; // pointSerialNumber 可能为 null
   remark?: string;
   createTime?: Date;
   // 扩展字段(用于显示)

+ 16 - 6
src/components/SegregationPointForm.tsx

@@ -77,13 +77,15 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
             pointName: data.pointName ?? '',
             pointIcon: data.pointIcon ?? '',
             pointPicture: data.pointPicture ?? '',
-            pointNfc: data.pointNfc ?? '',
+            // pointNfc: 如果是空字符串或 null,设置为 undefined(表单中不显示);如果有值则使用值
+            pointNfc: data.pointNfc && data.pointNfc.trim() !== '' ? data.pointNfc : undefined,
             workstationId: data.workstationId,
             // lotoId 可能为 null,需要保留 null 值(不要转换为 undefined)
             // 如果为 null 则设置为 undefined(表单 Select 组件需要 undefined 而不是 null)
             lotoId: data.lotoId !== undefined && data.lotoId !== null ? data.lotoId : undefined,
             powerType: data.powerType ?? '',
-            pointSerialNumber: data.pointSerialNumber ?? '',
+            // pointSerialNumber: 如果是空字符串或 null,设置为 undefined(表单中不显示);如果有值则使用值
+            pointSerialNumber: data.pointSerialNumber && data.pointSerialNumber.trim() !== '' ? data.pointSerialNumber : undefined,
             remark: data.remark ?? '',
           };
           
@@ -210,11 +212,13 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
               pointName: values.pointName,
               pointIcon: values.pointIcon,
               pointPicture: values.pointPicture,
-              pointNfc: values.pointNfc,
+              // pointNfc: 如果为空字符串或 undefined,设置为 null;否则使用填入的值
+              pointNfc: values.pointNfc && values.pointNfc.trim() !== '' ? values.pointNfc : null as any,
               workstationId: values.workstationId,
               lotoId: values.lotoId,
               powerType: values.powerType,
-              pointSerialNumber: values.pointSerialNumber,
+              // pointSerialNumber: 如果为空字符串或 undefined,设置为 null;否则使用填入的值
+              pointSerialNumber: values.pointSerialNumber && values.pointSerialNumber.trim() !== '' ? values.pointSerialNumber : null as any,
               remark: values.remark,
             };
             await segregationPointApi.addinsertIsIsolationPoint(data);
@@ -238,13 +242,19 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
               pointName: values.pointName !== undefined ? values.pointName : detailData.pointName,
               pointIcon: values.pointIcon !== undefined ? values.pointIcon : detailData.pointIcon,
               pointPicture: values.pointPicture !== undefined ? values.pointPicture : detailData.pointPicture,
-              pointNfc: values.pointNfc !== undefined ? values.pointNfc : detailData.pointNfc,
+              // pointNfc: 如果表单中有值且不为空字符串,使用表单值;如果为空字符串,设置为 null;如果为 undefined,使用详情数据中的原值(可能是 null)
+              pointNfc: values.pointNfc !== undefined 
+                ? (values.pointNfc && values.pointNfc.trim() !== '' ? values.pointNfc : null)
+                : detailData.pointNfc,
               workstationId: values.workstationId !== undefined ? values.workstationId : detailData.workstationId,
               // lotoId 处理:如果表单中有值(包括 null),使用表单值;否则使用详情数据中的原值(可能是 null)
               // 注意:表单 Select 清空时返回 undefined,此时应该保留详情数据中的 null
               lotoId: values.lotoId !== undefined ? values.lotoId : detailData.lotoId,
               powerType: values.powerType !== undefined ? values.powerType : detailData.powerType,
-              pointSerialNumber: values.pointSerialNumber !== undefined ? values.pointSerialNumber : detailData.pointSerialNumber,
+              // pointSerialNumber: 如果表单中有值且不为空字符串,使用表单值;如果为空字符串,设置为 null;如果为 undefined,使用详情数据中的原值(可能是 null)
+              pointSerialNumber: values.pointSerialNumber !== undefined 
+                ? (values.pointSerialNumber && values.pointSerialNumber.trim() !== '' ? values.pointSerialNumber : null)
+                : detailData.pointSerialNumber,
               remark: values.remark !== undefined ? values.remark : detailData.remark,
             };