Преглед изворни кода

隔离点编辑不回显数据

pm пре 3 месеци
родитељ
комит
5d03799c29
2 измењених фајлова са 32 додато и 12 уклоњено
  1. 26 11
      src/components/SegregationPointForm.tsx
  2. 6 1
      src/components/SegregationPointManagement.tsx

+ 26 - 11
src/components/SegregationPointForm.tsx

@@ -50,24 +50,39 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
       if (id) {
         setFormLoading(true);
         try {
+          console.log('SegregationPointForm: 开始获取隔离点详情, id =', id);
           const response = await segregationPointApi.selectIsIsolationPointById(id);
-          const data = response?.data || response;
-          form.setFieldsValue({
-            pointId: data.pointId,
-            pointName: data.pointName,
-            pointIcon: data.pointIcon,
-            pointPicture: data.pointPicture,
-            pointNfc: data.pointNfc,
+          console.log('SegregationPointForm: 接口响应', response);
+          
+          // 处理响应数据格式
+          const data = (response as any)?.data || response;
+          console.log('SegregationPointForm: 处理后的数据', data);
+          
+          // 设置表单值
+          const formValues = {
+            pointId: data.pointId || data.id,
+            pointName: data.pointName || '',
+            pointIcon: data.pointIcon || '',
+            pointPicture: data.pointPicture || '',
+            pointNfc: data.pointNfc || '',
             workstationId: data.workstationId,
             lotoId: data.lotoId,
-            powerType: data.powerType,
-            pointSerialNumber: data.pointSerialNumber,
-            remark: data.remark,
-          });
+            powerType: data.powerType || '',
+            pointSerialNumber: data.pointSerialNumber || '',
+            remark: data.remark || '',
+          };
+          
+          console.log('SegregationPointForm: 设置表单值', formValues);
+          
+          // 使用 setTimeout 确保表单已渲染
+          setTimeout(() => {
+            form.setFieldsValue(formValues);
+          }, 0);
 
           // 获取隔离点图标
           await loadIsolationIcons(data.pointIcon);
         } catch (error: any) {
+          console.error('SegregationPointForm: 获取隔离点详情失败', error);
           toast.error(error.message || t('form.getSegregationPointDetailFailed'));
         } finally {
           setFormLoading(false);

+ 6 - 1
src/components/SegregationPointManagement.tsx

@@ -292,7 +292,12 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
             <UIButton
               variant="ghost"
               size="sm"
-              onClick={() => openForm('update', record.pointId)}
+              onClick={() => {
+                console.log('SegregationPointManagement: 点击编辑, record =', record);
+                const editId = record.pointId || (record as any).id;
+                console.log('SegregationPointManagement: 编辑ID =', editId);
+                openForm('update', editId);
+              }}
               className="h-8 px-2 transition-colors hover:underline"
               style={{ color: '#000000' }}
               onMouseEnter={(e) => {