Răsfoiți Sursa

[Feat 0000]预警指标接口对接以及页面展示

bobo04052021@163.com 1 lună în urmă
părinte
comite
6de254649d

+ 21 - 2
src/views/vent/deviceManager/comment/warningTabel/BaseModal1Leather.vue

@@ -137,18 +137,37 @@ async function onSubmit() {
     const baseForm = await getFieldsValue();
     await validate();
     setModalProps({ confirmLoading: true });
+    // 1. 获取警告表单值 + 追加 monitorType:2 + 过滤空 deviceType
     const warnValues = await Promise.all(unref(warnFormRefs).map((formRef) => formRef.getFieldsValue()));
+    //添加类型 + 过滤
+    const processedWarn = warnValues
+      .map((item) => ({
+        ...item,
+        monitorType: 2,
+      }))
+      .filter((item) => item.deviceType !== '');
+
+    // 2. 获取控制表单值 + 追加 monitorType:1 + 过滤空 deviceType
     const controlValues = await Promise.all(unref(controlFormRefs).map((formRef) => formRef.getFieldsValue()));
+    const processedControl = controlValues
+      .map((item) => ({
+        ...item,
+        monitorType: 1,
+      }))
+      .filter((item) => item.deviceType !== '');
+    console.log(processedControl, '控制设备处理后');
+    console.log(processedWarn, '警告设备处理后');
+    // 最终提交数据
     const submitData = {
       ...baseForm,
-      // 合并数据
-      alarmList: [...warnValues, ...controlValues],
+      alarmList: [...processedWarn, ...processedControl],
     };
     if (!isUpdate.value) {
       emit('add', 'add', submitData);
     } else {
       emit('update', 'update', submitData);
     }
+
     closeModal();
   } catch (error) {
     console.error('表单验证失败:', error);

+ 63 - 55
src/views/vent/home/configurable/belt/belt-new.vue

@@ -111,64 +111,65 @@ function goToHistory() {
 }
 // 预警等级映射
 const warnTypeMap = {
-  '102': '蓝色预警(一般风险)',
-  '103': '黄色预警(较大风险)',
-  '104': '橙色预警(重大风险)',
-  '201': '红色预警(特别重大风险)',
+  '102': '黄色预警(较大风险)',
+  '103': '橙色预警(重大风险)',
+  '104': '红色预警(特别重大风险)',
 };
-const deviceRuleMap = {
-  modelsensor_co: { label: 'CO浓度', useFminMax: true },
-  modelsensor_temperature: { label: '温度传感器', useFminMax: true },
-  modelsensor_hcl: { label: 'HCL浓度', useFminMax: true },
-  fiber_v1: { label: '光纤测温', useFminMax: false },
-  modelsensor_fire: { label: '火焰传感器', useFminMax: false },
-  modelsensor_smoke: { label: '烟雾传感器', useFminMax: false },
-};
-// 刷新数据
-async function refresh() {
-  // await fetchConfigs('sys_Leather');
+// 处理接口返回数据
+interface WarnResult {
+  warnName: string;
+  coRange?: string;
+  coTrend?: string;
+  tempRange?: string;
+  tempTrend?: string;
+  hclRange?: string;
+}
+function groupWarnByType(data: any) {
+  const result: WarnResult[] = [];
 
-  //   if (pageType.value === 'fire_risk_warn') {
-  //     configs.value = testBeltNew;
-  //     const res = await getMonitorAndAlertBelt({
-  //       sysId: '2028657172566073346',
-  //       dataList: 'fire_risk_warn,warn_result,vehicle_co_correlate',
-  //     });
-  //     updateData(res);
-  //   } else if (pageType.value === 'emergencyControl') {
-  //     configs.value = testYjkf;
-  //     const res = await getSystem({
-  //       devicetype: 'sys',
-  //       systemID: '2028657172566073346',
-  //       type: 'ventS',
-  //     });
-  //     updateData(res);
-  //   } else if (pageType.value === 'sprayControl') {
-  //     const params = {
-  //       devicetype: 'sys',
-  //       systemID: '2028657172566073346',
-  //     };
-  //     Promise.resolve(getDevice(params)).then((originalData) => {
-  //       updateData(originalData);
-  //       const sprayData: any[] = [];
-  //       if (data.value?.msgTxt) {
-  //         data.value.msgTxt.forEach((item) => {
-  //           const hasSprayAuto = item.type && item.type.toLowerCase().includes('spray_auto');
-  //           if (hasSprayAuto) {
-  //             sprayData.push({
-  //               ...item,
-  //               ...item.readData,
-  //             });
-  //           }
-  //         });
-  //       }
-  //       data.value.sprayData = sprayData;
-  //       updateData(data.value);
-  //     });
-  //     configs.value = testSpary;
-  //   }
-  //   if (isFirst) initialized.value = true;
+  // 遍历 102、103、104...
+  Object.keys(data).forEach((warnKey) => {
+    const list = data[warnKey] || [];
+    const warnName = warnTypeMap[warnKey as keyof typeof warnTypeMap];
+
+    // 构建当前预警对象
+    const warnObj: WarnResult = { warnName };
+
+    list.forEach((item: any) => {
+      const { deviceType, fmin, fmax, trendMin, trendMax, trendCxTimeUnit } = item;
+      // CO
+      if (deviceType === 'modelsensor_co') {
+        if (fmin != null && fmax != null) {
+          warnObj.coRange = `${fmin} - ${fmax}`;
+        } else if (trendMin != null && trendMax != null) {
+          warnObj.coTrend = `${trendMin} - ${trendMax}`;
+        }
+      }
+      // 温度(带单位)
+      else if (deviceType === 'modelsensor_temperature') {
+        if (fmin != null && fmax != null) {
+          warnObj.tempRange = `${fmin} - ${fmax}℃`;
+        } else if (trendMin != null) {
+          let unit = '';
+          if (trendCxTimeUnit === 0) unit = '分钟';
+          if (trendCxTimeUnit === 1) unit = '小时';
+          warnObj.tempTrend = `>${trendMin}℃ +${unit}`;
+        }
+      }
+      // HCL
+      else if (deviceType === 'modelsensor_hcl') {
+        if (fmin != null && fmax != null) {
+          warnObj.hclRange = `${fmin} - ${fmax}`;
+        }
+      }
+    });
+    result.push(warnObj);
+  });
 
+  return result;
+}
+// 刷新数据
+async function refresh() {
   // 由于模型中需要用到风门的监测数据,这里进行公共调用(后期精确调用风门)
   const modalRes = {};
   const systemParams = {
@@ -176,6 +177,11 @@ async function refresh() {
     systemID: optionValue.value,
   };
   const resSys = await getSystem(systemParams);
+  const params = {
+    sysId: optionValue.value,
+    monitorType: 2,
+  };
+  const warnInfo = await getWarnInfo(params);
   Object.assign(modalRes, resSys);
   if (pageType.value == 'fire_risk_warn') {
     configs.value = [...testBeltNew];
@@ -198,6 +204,8 @@ async function refresh() {
     if (alarmRes.warn_result) {
       data.value.warn_result = alarmRes.warn_result;
     }
+    data.value.warnInfo = groupWarnByType(warnInfo);
+    console.log(data.value, '11111111');
     updateData(data.value);
   } else if (pageType.value == 'sprayControl') {
     updateData(resSys);

+ 1 - 0
src/views/vent/home/configurable/belt/belt.vue

@@ -100,6 +100,7 @@ function refresh() {
         showData = filterDataById(res, currentSelectedId.value);
       } else {
         const firstId = res.monitor_alert?.[0]?.sysId;
+        const warnVal = res.monitor_alert?.[0]?.value;
         if (firstId) {
           currentSelectedId.value = firstId;
           showData = filterDataById(res, firstId);

+ 7 - 11
src/views/vent/home/configurable/belt/configurable.data.ts

@@ -1516,32 +1516,32 @@ export const testYjkf: Config[] = [
           columns: [
             {
               name: '级别名称',
-              prop: 'warnType',
+              prop: 'warnName',
               width: '180px',
             },
             {
               name: 'CO浓度(ppm)',
-              prop: 'fmin fmax',
+              prop: 'coRange',
               width: '180px',
             },
             {
               name: '温度(环境)',
-              prop: 'status',
+              prop: 'tempRange',
               width: '180px',
             },
             {
               name: 'CO变化率(ppm/min)',
-              prop: 'trendMmin trendMax',
+              prop: 'coTrend',
               width: '220px',
             },
             {
               name: 'HCL浓度(ppm)',
-              prop: 'trendMmin trendMax',
+              prop: 'hclRange',
               width: '180px',
             },
             {
               name: '设备升温(△T/△t)',
-              prop: 'trendMmin trendMax',
+              prop: 'tempTrend',
               width: '180px',
             },
             {
@@ -1551,14 +1551,10 @@ export const testYjkf: Config[] = [
             },
             {
               name: '操作',
-              prop: 'warnType',
+              prop: '',
               width: '180px',
             },
           ],
-          otherProps: {
-            title: '火灾风险预警',
-            prop: 'status',
-          },
         },
       ],
     },

+ 15 - 6
src/views/vent/home/configurable/components/belt/WarningResultList.vue

@@ -12,7 +12,7 @@
         </thead>
         <tbody>
           <!-- 给 tr 绑定行样式 -->
-          <tr v-for="(row, index) in data[config.tableReadFrom]" :key="index" class="table-row" :class="getRowStatusClass(row.status)">
+          <tr v-for="(row, index) in data[config.tableReadFrom]" :key="index" class="table-row" :class="getRowStatusClass(row)">
             <td v-for="col in config.columns" :key="col.prop" class="table-cell">
               <span v-if="col.render" v-html="col.render(row, index)"></span>
               <span v-else-if="col.prop === 'status'">
@@ -49,11 +49,20 @@ const props = defineProps<{
 }>();
 
 // 给整行添加颜色样式
-function getRowStatusClass(status: string) {
-  if (!status) return '';
-  if (status.includes('黄色预警')) return 'row-status-yellow';
-  if (status.includes('橙色预警')) return 'row-status-orange';
-  if (status.includes('红色预警')) return 'row-status-red';
+function getRowStatusClass(row: any) {
+  const status = row?.status || '';
+  const warnName = row?.warnName || '';
+
+  // 只要任意一个字段包含对应文字,就返回对应 class
+  if (status.includes('黄色预警') || warnName.includes('黄色预警')) {
+    return 'row-status-yellow';
+  }
+  if (status.includes('橙色预警') || warnName.includes('橙色预警')) {
+    return 'row-status-orange';
+  }
+  if (status.includes('红色预警') || warnName.includes('红色预警')) {
+    return 'row-status-red';
+  }
   return '';
 }