Procházet zdrojové kódy

监控设置阈值不允许设置为空

Zimo před 19 hodinami
rodič
revize
e2c6afc60c
1 změnil soubory, kde provedl 23 přidání a 2 odebrání
  1. 23 2
      src/views/oli-connection/monitoring/detail.vue

+ 23 - 2
src/views/oli-connection/monitoring/detail.vue

@@ -720,9 +720,30 @@ const { toggle, isFullscreen } = useFullscreen(targetArea)
 const message = useMessage()
 
 async function handleSave(item: Dimensions) {
+  const { minValue, maxValue } = item
+
+  // 1. 判断是否为空 (包括空字符串、null、undefined)
+  if (!minValue || !maxValue) {
+    return message.warning('最大值和最小值不能为空')
+  }
+
+  // 2. 判断是否为有效的数字
+  // Number() 处理字符串数字,isNaN 排除非数字字符
+  const min = Number(minValue)
+  const max = Number(maxValue)
+
+  if (isNaN(min) || isNaN(max)) {
+    return message.warning('请输入有效的数字')
+  }
+
+  // 3. (附加逻辑) 比较大小
+  if (min > max) {
+    return message.warning('最小值不能大于最大值')
+  }
+
   const body = {
-    minValue: item.minValue,
-    maxValue: item.maxValue,
+    minValue: min,
+    maxValue: max,
     deviceId: query.id,
     propertyCode: item.identifier,
     alarmProperty: item.name,