Kaynağa Gözat

单位初始化切换报错问题修改

lichunyang 2 hafta önce
ebeveyn
işleme
ff99dee005
1 değiştirilmiş dosya ile 5 ekleme ve 5 silme
  1. 5 5
      src/views/model/vueflow/aside/asideData.vue

+ 5 - 5
src/views/model/vueflow/aside/asideData.vue

@@ -822,9 +822,9 @@ const handleInsertSelected = () => {
 }
 
 const handleUnitChange = (row, newUnit, col = null) => {
-  // console.log('handleUnitChange row:', row, 'newUnit:', newUnit, 'col:', col);
+  console.log('handleUnitChange row:', row, 'newUnit:', newUnit, 'col:', col);
   const target = col ? row[col.code] : row;
-  // console.log('target:', target);
+  console.log('target:', target);
   if (!target || !target.value || isNaN(parseFloat(target.value))) {
     // console.log('Invalid value check failed:', { target, value: target?.value, isNaN: isNaN(parseFloat(target?.value)) });
     ElMessage.warning('请输入有效数值');
@@ -836,8 +836,8 @@ const handleUnitChange = (row, newUnit, col = null) => {
     ElMessage.error(`单位选项未定义 for ${col?.name || 'unknown'}`);
     return;
   }
-  // 使用 row[col.code].unit 作为当前单位,而不是 col.prevUnitDef
-  const currentUnit = unitOptions.find(opt => opt.value === target.unit) || unitOptions.find(opt => opt.value === col.unitDef);
+  // 使用 row[col.code].unit 作为当前单位,而不是 col.prevUnitDef 
+  const currentUnit = unitOptions.find(opt => opt.value === target.unit) || unitOptions.find(opt => opt.value === col ? col.unitDef : target.unitDef);
   // console.log('currentUnit:', currentUnit, 'row unit:', target.unit);
   if (!currentUnit) {
     console.error('未找到当前单位信息', target.unit);
@@ -853,7 +853,7 @@ const handleUnitChange = (row, newUnit, col = null) => {
   }
   const currentValue = parseFloat(target.value);
   const newValue = ((currentValue - currentUnit.utOffset) / currentUnit.factor) * targetUnit.factor + targetUnit.utOffset;
-  target.value = newValue.toFixed(6);
+  target.value = newValue.toFixed(8);
   target.unit = newUnit;
   // console.log('Updated value:', target.value, 'unit:', target.unit);
   if (col) {