ソースを参照

Merge branch 'master' of http://39.97.59.228:8013/hrx/mky-vent-base

lxh 4 ヶ月 前
コミット
a198545717

+ 371 - 289
src/components/chart/BarAndLine.vue

@@ -5,319 +5,401 @@
   <div v-if="!spinning" ref="chartRef" :style="{ height, width }"></div>
 </template>
 <script lang="ts">
-  import { defineComponent, PropType, ref, Ref, reactive, watchEffect, watch, nextTick } from 'vue';
-  import { useECharts } from '/@/hooks/web/useECharts';
-  import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
-  import EchartsUtil from '/@/utils/echartsUtil';
-  import { merge } from 'lodash-es';
-  type ChartColumn = {
-    legend: string;
-    seriesName: string;
-    ymax: number;
-    yname: string;
-    linetype: string;
-    yaxispos: string;
-    color: string;
-    sort: number;
-    xRotate: number;
-    dataIndex: string;
-  };
-  export default defineComponent({
-    name: 'BarAndLine',
-    props: {
-      chartsColumns: {
-        type: Array as PropType<ChartColumn[]>,
-        default: () => [],
-      },
-      chartsColumnsType: {
-        type: String,
-      },
-      chartsType: {
-        type: String,
-        default: '',
-      },
-      dataSource: {
-        type: Array,
-        default: () => [],
-      },
-      option: {
-        type: Object,
-        default: () => ({}),
-      },
-      xAxisPropType: {
-        type: String,
-        required: true,
-      },
-      width: {
-        type: String as PropType<string>,
-        default: '100%',
-      },
-      height: {
-        type: String as PropType<string>,
-        default: 'calc(100vh - 78px)',
-      },
+import { defineComponent, PropType, ref, Ref, reactive, watchEffect, watch, nextTick, onMounted } from 'vue';
+import { useECharts } from '/@/hooks/web/useECharts';
+import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
+import EchartsUtil from '/@/utils/echartsUtil';
+import { merge } from 'lodash-es';
+type ChartColumn = {
+  legend: string;
+  seriesName: string;
+  ymax: number;
+  yname: string;
+  linetype: string;
+  yaxispos: string;
+  color: string;
+  sort: number;
+  xRotate: number;
+  dataIndex: string;
+};
+type RegValueItem = {
+  type: string;
+  value: number | string;
+  name: string;
+  color: string;
+  lineType: 'dashed' | 'solid';
+};
+export default defineComponent({
+  name: 'BarAndLine',
+  props: {
+    chartsColumns: {
+      type: Array as PropType<ChartColumn[]>,
+      default: () => [],
+    },
+    chartsColumnsType: {
+      type: String,
+    },
+    chartsType: {
+      type: String,
+      default: '',
+    },
+    dataSource: {
+      type: Array,
+      default: () => [],
+    },
+    option: {
+      type: Object,
+      default: () => ({}),
+    },
+    xAxisPropType: {
+      type: String,
+      required: true,
     },
-    emits: ['refresh'],
-    setup(props, { emit }) {
-      const spinning = ref<boolean>(true);
-      const chartRef = ref<HTMLDivElement | null>(null);
-      const { setOptions, echarts } = useECharts(chartRef as Ref<HTMLDivElement>);
-      const chartData = props.chartsColumnsType ? getTableHeaderColumns(props.chartsColumnsType) : [];
-      let chartsColumns = (props.chartsColumns.length > 0 ? props.chartsColumns : chartData) as ChartColumn[];
-      let tempYmax: number[] = [];
-      let tempYmin: number[] = [];
-      // let groupedByColumns = {};
-      const option = reactive({
-        name: '',
-        color: ['#7B68EE', '#0000CD', '#6495ED', '#00BFFF', '#AFEEEE', '#008080', '#00FA9A', '#2E8B57', '#FAFAD2', '#DAA520'],
-        tooltip: {},
-        grid: {},
-        toolbox: {
-          feature: {
-            saveAsImage: {
-              iconStyle: {
-                borderColor: '#ffffff',
-              },
-              show: false,
+    width: {
+      type: String as PropType<string>,
+      default: '100%',
+    },
+    height: {
+      type: String as PropType<string>,
+      default: 'calc(100vh - 78px)',
+    },
+    regValues: {
+      type: Array as PropType<RegValueItem[]>,
+      default: () => [],
+    },
+  },
+  emits: ['refresh'],
+  setup(props, { emit }) {
+    const spinning = ref<boolean>(true);
+    const chartRef = ref<HTMLDivElement | null>(null);
+    const chartType = ref<string>('');
+    const { setOptions, echarts } = useECharts(chartRef as Ref<HTMLDivElement>);
+    const chartData = props.chartsColumnsType ? getTableHeaderColumns(props.chartsColumnsType) : [];
+    let chartsColumns = (props.chartsColumns.length > 0 ? props.chartsColumns : chartData) as ChartColumn[];
+    let tempYmax: number[] = [];
+    let tempYmin: number[] = [];
+    // let groupedByColumns = {};
+    const option = reactive({
+      name: '',
+      color: ['#7B68EE', '#0000CD', '#6495ED', '#00BFFF', '#AFEEEE', '#008080', '#00FA9A', '#2E8B57', '#FAFAD2', '#DAA520'],
+      tooltip: {},
+      grid: {},
+      toolbox: {
+        feature: {
+          saveAsImage: {
+            iconStyle: {
+              borderColor: '#ffffff',
             },
+            show: false,
           },
         },
-        dataZoom: {},
-        legend: {
-          textStyle: {
-            color: '#ffffff', // 字体颜色
-          },
-          top: '20',
+      },
+      dataZoom: {},
+      legend: {
+        textStyle: {
+          color: '#ffffff', // 字体颜色
         },
-        timeline: null,
-        xAxis: {},
-        yAxis: null,
-        series: null,
-      });
-      let optionUtil;
-
-      watchEffect(() => {
-        props.dataSource && props.xAxisPropType && option.series && initCharts();
-      });
-
-      watch([() => props.chartsType, () => props.chartsColumns], ([newChartsType, newChartsColumns]) => {
-        spinning.value = true;
-        chartsColumns = newChartsColumns;
-        optionUtil.initChartOption(newChartsType, newChartsColumns);
-        spinning.value = false;
+        top: '20',
+      },
+      timeline: null,
+      xAxis: {},
+      yAxis: null,
+      series: null,
+    });
+    let optionUtil;
+    onMounted(() => {
+      // 组件挂载后强制初始化一次(兜底,避免监听漏触发)
+      if (props.dataSource && props.regValues) {
         initCharts(true);
-        emit('refresh');
-      });
-
-      function initChartsOption() {
-        // debugger;
-        optionUtil = new EchartsUtil(merge(option, props.option));
-        optionUtil.initChartOption(props.chartsType, chartsColumns);
       }
-      initChartsOption();
+    });
+    watchEffect(() => {
+      props.dataSource && props.xAxisPropType && option.series && initCharts();
+    });
+    watch([() => props.chartsType, () => props.chartsColumns], ([newChartsType, newChartsColumns]) => {
+      spinning.value = true;
+      chartsColumns = newChartsColumns;
+      optionUtil.initChartOption(newChartsType, newChartsColumns);
+      spinning.value = false;
+      initCharts(true);
+      emit('refresh');
+    });
+    watch(
+      () => [props.regValues],
+      (newVal) => {
+        if (props.regValues && props.regValues.length > 0) {
+          initCharts(true);
+        }
+        // 数据变化时重新渲染图表
+      },
+      { deep: true, immediate: true }
+    );
+    function initChartsOption() {
+      // debugger;
+      optionUtil = new EchartsUtil(merge(option, props.option));
+      optionUtil.initChartOption(props.chartsType, chartsColumns);
+    }
+    initChartsOption();
 
-      function initCharts(isRefresh = false) {
-        if (props.dataSource.length < 1) return;
-        //轴数据
-        let isFresh = false;
-        if (option.series && option.series.length === chartsColumns.length) {
-          let xAxisData = props.dataSource.map((item) => item[props.xAxisPropType]);
-          chartsColumns = [...chartsColumns].filter((propType: any, index) => {
-            if (!propType) return;
-            if (props.chartsType == 'listMonitor') {
-              option.series[index].type = 'bar';
+    function initCharts(isRefresh = false) {
+      if (props.dataSource.length < 1) return;
+      //轴数据
+      let isFresh = false;
+      if (option.series && option.series.length === chartsColumns.length) {
+        let xAxisData = props.dataSource.map((item) => item[props.xAxisPropType]);
+        chartsColumns = [...chartsColumns].filter((propType: any, index) => {
+          if (!propType) return;
+          if (props.chartsType == 'listMonitor') {
+            option.series[index].type = 'bar';
+          }
+          console.log(option.series[index], '000===');
+          option.series[index].data = props.dataSource.map((item) => Number(item[propType.dataIndex]) || 0);
+          if (props.regValues && props.regValues.length > 0) {
+            // 筛选匹配的regValues
+            const matchRegValues = props.regValues
+              .filter((e) => propType.dataIndex == e.type) // 匹配当前dataIndex
+              .filter((item) => {
+                //过滤value为null
+                if (item.value === null || item.value === undefined || item.value === '') return false;
+                const numValue = Number(item.value);
+                return !isNaN(numValue); // 确保是有效数字
+              });
+            if (matchRegValues.length > 0) {
+              option.series[index].markLine = {
+                lineStyle: { width: 4 },
+                // 多个匹配项生成多条标线
+                data: matchRegValues
+                  .map((item, index) => [
+                    {
+                      yAxis: Number(item.value) ? Number(item.value) : 0,
+                      xAxis: 0,
+                      label: {
+                        show: true,
+                        position: 'end',
+                        formatter: item.name,
+                        color: '#fff',
+                        fontSize: 14,
+                        offset: [-80, 15],
+                      },
+                      lineStyle: {
+                        color: item.color,
+                        type: item.lineType,
+                      },
+                    },
+                    {
+                      yAxis: Number(item.value) ? Number(item.value) : 0,
+                      xAxis: 'max',
+                      label: {
+                        show: true,
+                        position: 'end',
+                        formatter: item.value,
+                        color: '#fff',
+                        fontSize: 14,
+                        offset: [-80, -10],
+                      },
+                      lineStyle: {
+                        color: item.color,
+                        type: item.lineType,
+                        width: 4,
+                      },
+                    },
+                  ])
+                  .flat(),
+              };
             }
-            console.log(option.series[index], '000===');
-            option.series[index].data = props.dataSource.map((item) => Number(item[propType.dataIndex]) || 0);
-            debugger;
-            // console.log('nnn', option.series[index].data);
-            // 这里动态计算echarts y轴最大值
-            const max = Math.max(...option.series[index].data);
-            const min = Math.min(...option.series[index].data);
-            const digitCount = Math.ceil(Number(max));
-            const minDigitCount = Math.floor(Number(min));
+          }
+          // console.log('nnn', option.series[index].data);
+          // 这里动态计算echarts y轴最大值
+          const regValuesNum =
+            props.regValues && props.regValues.length > 0
+              ? props.regValues.filter((e) => propType.dataIndex == e.type).map((item) => Number(item.value) || 0)
+              : [];
+          const max = Math.max(...option.series[index].data, ...regValuesNum);
+          const min = Math.min(...option.series[index].data, ...regValuesNum);
+          const digitCount = Math.ceil(Number(max));
+          const minDigitCount = Math.floor(Number(min));
 
-            // if (props.chartsType === 'history') {
-            //   const disLen = Math.abs(max - min);
-            //   propType.ymax = digitCount + disLen / 3;
-            //   propType.ymin = minDigitCount - disLen / 3 > 0 || minDigitCount < 0 ? minDigitCount - disLen / 3 : 0;
-            // } else {
-            //   let yMax = 0,
-            //     yMin = 0;
-            //   if (digitCount < 2) {
-            //     if (max < 0.5) {
-            //       yMax = 1;
-            //     } else if (max < 0.9) {
-            //       yMax = 1.5;
-            //     } else if (max < 5) {
-            //       yMax = 5;
-            //     } else if (max < 10) {
-            //       yMax = 10;
-            //     }
-            //   } else if (digitCount < 3) {
-            //     const n = Number((Number(max.toFixed(0)) / 10).toFixed(0));
-            //     if (max < n * 10 + 5) {
-            //       yMax = (n + 1) * 10;
-            //     } else {
-            //       yMax = (n + 2) * 10;
-            //     }
-            //   } else if (digitCount < 4) {
-            //     const n = Number((Number(max.toFixed(0)) / 100).toFixed(0));
-            //     if (max < n * 100 + 50) {
-            //       yMax = (n + 1) * 100;
-            //     } else {
-            //       yMax = (n + 2) * 100;
-            //     }
-            //   } else if (digitCount < 5) {
-            //     const n = Number((Number(max.toFixed(0)) / 1000).toFixed(0));
-            //     if (max < n * 1000 + 500) {
-            //       yMax = (n + 1) * 1000;
-            //     } else {
-            //       yMax = (n + 1) * 1000 + 500;
-            //     }
-            //   } else if (digitCount < 6) {
-            //     const n = Number((Number(max.toFixed(0)) / 10000).toFixed(0));
-            //     if (max < n * 10000 + 5000) {
-            //       yMax = (n + 1) * 10000;
-            //     } else {
-            //       yMax = (n + 1) * 10000 + 5000;
-            //     }
-            //   }
+          // if (props.chartsType === 'history') {
+          //   const disLen = Math.abs(max - min);
+          //   propType.ymax = digitCount + disLen / 3;
+          //   propType.ymin = minDigitCount - disLen / 3 > 0 || minDigitCount < 0 ? minDigitCount - disLen / 3 : 0;
+          // } else {
+          //   let yMax = 0,
+          //     yMin = 0;
+          //   if (digitCount < 2) {
+          //     if (max < 0.5) {
+          //       yMax = 1;
+          //     } else if (max < 0.9) {
+          //       yMax = 1.5;
+          //     } else if (max < 5) {
+          //       yMax = 5;
+          //     } else if (max < 10) {
+          //       yMax = 10;
+          //     }
+          //   } else if (digitCount < 3) {
+          //     const n = Number((Number(max.toFixed(0)) / 10).toFixed(0));
+          //     if (max < n * 10 + 5) {
+          //       yMax = (n + 1) * 10;
+          //     } else {
+          //       yMax = (n + 2) * 10;
+          //     }
+          //   } else if (digitCount < 4) {
+          //     const n = Number((Number(max.toFixed(0)) / 100).toFixed(0));
+          //     if (max < n * 100 + 50) {
+          //       yMax = (n + 1) * 100;
+          //     } else {
+          //       yMax = (n + 2) * 100;
+          //     }
+          //   } else if (digitCount < 5) {
+          //     const n = Number((Number(max.toFixed(0)) / 1000).toFixed(0));
+          //     if (max < n * 1000 + 500) {
+          //       yMax = (n + 1) * 1000;
+          //     } else {
+          //       yMax = (n + 1) * 1000 + 500;
+          //     }
+          //   } else if (digitCount < 6) {
+          //     const n = Number((Number(max.toFixed(0)) / 10000).toFixed(0));
+          //     if (max < n * 10000 + 5000) {
+          //       yMax = (n + 1) * 10000;
+          //     } else {
+          //       yMax = (n + 1) * 10000 + 5000;
+          //     }
+          //   }
 
-            //   if (minDigitCount < 2) {
-            //     if (min > 1.5) {
-            //       yMin = 1.0;
-            //     } else if (min > 5) {
-            //       yMin = 5;
-            //     } else {
-            //       yMin = 0;
-            //     }
-            //   } else if (minDigitCount < 3) {
-            //     const n = Number((Number(min.toFixed(0)) / 10).toFixed(0));
-            //     if (n > 1) {
-            //       yMin = (n - 1) * 10;
-            //     } else {
-            //       yMin = 10;
-            //     }
-            //   } else if (digitCount < 4) {
-            //     const n = Number((Number(min.toFixed(0)) / 100).toFixed(0));
-            //     if (n > 1) {
-            //       yMin = (n - 1) * 100;
-            //     } else {
-            //       yMin = 100;
-            //     }
-            //   } else if (digitCount < 5) {
-            //     const n = Number((Number(min.toFixed(0)) / 1000).toFixed(0));
-            //     if (n > 1) {
-            //       yMin = (n - 1) * 1000;
-            //     } else {
-            //       yMin = 1000;
-            //     }
-            //   } else if (digitCount < 6) {
-            //     const n = Number((Number(min.toFixed(0)) / 10000).toFixed(0));
-            //     if (n > 1) {
-            //       yMin = (n - 1) * 10000;
-            //     } else {
-            //       yMin = 10000;
-            //     }
-            //   }
+          //   if (minDigitCount < 2) {
+          //     if (min > 1.5) {
+          //       yMin = 1.0;
+          //     } else if (min > 5) {
+          //       yMin = 5;
+          //     } else {
+          //       yMin = 0;
+          //     }
+          //   } else if (minDigitCount < 3) {
+          //     const n = Number((Number(min.toFixed(0)) / 10).toFixed(0));
+          //     if (n > 1) {
+          //       yMin = (n - 1) * 10;
+          //     } else {
+          //       yMin = 10;
+          //     }
+          //   } else if (digitCount < 4) {
+          //     const n = Number((Number(min.toFixed(0)) / 100).toFixed(0));
+          //     if (n > 1) {
+          //       yMin = (n - 1) * 100;
+          //     } else {
+          //       yMin = 100;
+          //     }
+          //   } else if (digitCount < 5) {
+          //     const n = Number((Number(min.toFixed(0)) / 1000).toFixed(0));
+          //     if (n > 1) {
+          //       yMin = (n - 1) * 1000;
+          //     } else {
+          //       yMin = 1000;
+          //     }
+          //   } else if (digitCount < 6) {
+          //     const n = Number((Number(min.toFixed(0)) / 10000).toFixed(0));
+          //     if (n > 1) {
+          //       yMin = (n - 1) * 10000;
+          //     } else {
+          //       yMin = 10000;
+          //     }
+          //   }
 
-            //   propType.ymax = yMax;
-            //   propType.ymin = yMin;
-            // }
-            const disLen = Math.abs(max - min);
-            if (propType.ymax && propType.ymin >= 0) {
-              if (max > propType.ymax || min < propType.ymin) {
-                propType.ymax = digitCount + disLen / 3;
-                propType.ymin = minDigitCount - disLen / 3 > 0 || minDigitCount < 0 ? minDigitCount - disLen / 3 : 0;
-              } else {
-                propType.ymax = digitCount + digitCount / 4;
-                propType.ymin = minDigitCount - digitCount / 4;
-              }
-            } else {
+          //   propType.ymax = yMax;
+          //   propType.ymin = yMin;
+          // }
+          const disLen = Math.abs(max - min);
+          if (propType.ymax && propType.ymin >= 0) {
+            if (max > propType.ymax || min < propType.ymin) {
               propType.ymax = digitCount + disLen / 3;
               propType.ymin = minDigitCount - disLen / 3 > 0 || minDigitCount < 0 ? minDigitCount - disLen / 3 : 0;
-            }
-            if (propType.ymax == propType.ymin && propType.ymin == 0) {
-              propType.ymax = 10;
-            }
-
-            return true;
-          });
-          // debugger;
-          // 根据sort分组
-          const groupedBy = {};
-          for (const item of chartsColumns) {
-            if (groupedBy[item.sort]) {
-              groupedBy[item.sort].push(item);
             } else {
-              groupedBy[item.sort] = [item];
+              propType.ymax = digitCount + digitCount / 4;
+              propType.ymin = minDigitCount - digitCount / 4;
             }
+          } else {
+            propType.ymax = digitCount + disLen / 3;
+            propType.ymin = minDigitCount - disLen / 3 > 0 || minDigitCount < 0 ? minDigitCount - disLen / 3 : 0;
           }
-          // 根据分组找ymax最大值
-          const newChartsColumns: ChartColumn[] = [];
-          let index = 0;
-          for (let sortId in groupedBy) {
-            const group = groupedBy[sortId];
-            let ymax = group[0].ymax;
-            let ymin = group[0].ymin;
-            for (let i = 1; i < group.length; i++) {
-              if (group[i].ymax > ymax) {
-                ymax = group[i].ymax;
-              }
-            }
-            for (let i = 1; i < group.length; i++) {
-              if (group[i].ymin < ymin) {
-                ymin = group[i].ymin;
-              }
-            }
-            if (!tempYmax[index] || tempYmax[index] < ymax) {
-              tempYmax[index] = ymax;
-              isFresh = true;
-            }
-            if (tempYmin[index] > ymin) {
-              tempYmin[index] = ymin;
-              isFresh = true;
+          if (propType.ymax == propType.ymin && propType.ymin == 0) {
+            propType.ymax = 10;
+          }
+
+          return true;
+        });
+        // debugger;
+        // 根据sort分组
+        const groupedBy = {};
+        for (const item of chartsColumns) {
+          if (groupedBy[item.sort]) {
+            groupedBy[item.sort].push(item);
+          } else {
+            groupedBy[item.sort] = [item];
+          }
+        }
+        // 根据分组找ymax最大值
+        const newChartsColumns: ChartColumn[] = [];
+        let index = 0;
+        for (let sortId in groupedBy) {
+          const group = groupedBy[sortId];
+          let ymax = group[0].ymax;
+          let ymin = group[0].ymin;
+          for (let i = 1; i < group.length; i++) {
+            if (group[i].ymax > ymax) {
+              ymax = group[i].ymax;
             }
-            for (let i = 0; i < group.length; i++) {
-              group[i].ymax = ymax;
-              group[i].ymin = ymin;
-              newChartsColumns.push(group[i]);
+          }
+          for (let i = 1; i < group.length; i++) {
+            if (group[i].ymin < ymin) {
+              ymin = group[i].ymin;
             }
-            ++index;
           }
-          chartsColumns = newChartsColumns;
-          option.xAxis[0].data = xAxisData;
-          if (isFresh) {
-            spinning.value = true;
-            optionUtil.initChartOption(props.chartsType, chartsColumns);
-            spinning.value = false;
-            initCharts(true);
-            nextTick(() => {
-              setOptions(option, true);
-              emit('refresh');
-            });
-          } else {
-            // console.log('echarts监测列表数据', option.xAxis[0].data);
-            setOptions(option, isRefresh);
+          if (!tempYmax[index] || tempYmax[index] < ymax) {
+            tempYmax[index] = ymax;
+            isFresh = true;
+          }
+          if (tempYmin[index] > ymin) {
+            tempYmin[index] = ymin;
+            isFresh = true;
           }
+          for (let i = 0; i < group.length; i++) {
+            group[i].ymax = ymax;
+            group[i].ymin = ymin;
+            newChartsColumns.push(group[i]);
+          }
+          ++index;
+        }
+        chartsColumns = newChartsColumns;
+        option.xAxis[0].data = xAxisData;
+        if (isFresh) {
+          spinning.value = true;
+          optionUtil.initChartOption(props.chartsType, chartsColumns);
+          spinning.value = false;
+          initCharts(true);
+          nextTick(() => {
+            setOptions(option, true);
+            emit('refresh');
+          });
+        } else {
+          // console.log('echarts监测列表数据', option.xAxis[0].data);
           setOptions(option, isRefresh);
         }
+        setOptions(option, isRefresh);
       }
-      setTimeout(() => {
-        spinning.value = false;
-        initCharts(true);
-      }, 1000);
-      return { chartRef, spinning };
-    },
-  });
+    }
+    setTimeout(() => {
+      spinning.value = false;
+      initCharts(true);
+    }, 1000);
+    return { chartRef, spinning };
+  },
+});
 </script>
 <style lang="less" scoped>
-  .spinning {
-    display: flex;
-    width: 100%;
-    height: 100%;
-    justify-content: center;
-    align-items: center;
-  }
+.spinning {
+  display: flex;
+  width: 100%;
+  height: 100%;
+  justify-content: center;
+  align-items: center;
+}
 </style>

+ 299 - 247
src/views/vent/monitorManager/comment/DeviceEcharts.vue

@@ -130,289 +130,341 @@
         chartsType="history"
         style="margin-top: 20px"
         :chartsColumns="chartsColumnList"
+        :regValues="standardValues"
       />
     </div>
   </div>
 </template>
 <script lang="ts">
-  import { ref, defineComponent, watch, reactive, onMounted, watchEffect, inject } from 'vue';
-  import BarAndLine from '/@/components/chart/BarAndLine.vue';
-  import dayjs from 'dayjs';
-  import { defHttp } from '/@/utils/http/axios';
-  import { Select, Pagination } from 'ant-design-vue';
-  import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
+import { ref, defineComponent, watch, reactive, onMounted, watchEffect, inject, computed } from 'vue';
+import BarAndLine from '/@/components/chart/BarAndLine.vue';
+import dayjs from 'dayjs';
+import { defHttp } from '/@/utils/http/axios';
+import { Select, Pagination } from 'ant-design-vue';
+import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
 
-  export default defineComponent({
-    name: 'DeviceEcharts',
-    components: { BarAndLine, Select, Pagination },
-    props: {
-      chartsColumns: {
-        type: Array,
-        default: () => [],
+export default defineComponent({
+  name: 'DeviceEcharts',
+  components: { BarAndLine, Select, Pagination },
+  props: {
+    chartsColumns: {
+      type: Array,
+      default: () => [],
+    },
+    chartsColumnsHistory: {
+      type: Array,
+      default: () => [],
+    },
+    chartsColumnsType: {
+      type: String,
+      required: true,
+    },
+    dataSource: {
+      type: Array,
+      default: () => [],
+    },
+    deviceListApi: {
+      type: Function,
+      required: true,
+    },
+    deviceType: {
+      type: String,
+      required: true,
+    },
+    option: {
+      type: Object,
+      default: () => ({}),
+    },
+    xAxisPropType: {
+      type: String,
+      required: true,
+    },
+  },
+  setup(props) {
+    const globalConfig = inject('globalConfig');
+    const stationType = ref('plc1');
+    let historyList;
+    // if (globalConfig.History_Type == 'vent') {
+    //   historyList = (params) => defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params });
+    // } else {
+    //   historyList = (params) => defHttp.post({ url: '/monitor/history/getHistoryData', params });
+    // }
+    const chartsType = ref('listMonitor');
+    const deviceId = ref('');
+    const options = ref([]);
+    const historyParams = reactive({
+      ttime_begin: dayjs().startOf('date').format('YYYY-MM-DD HH:mm:ss').toString(),
+      ttime_end: dayjs().format('YYYY-MM-DD HH:mm:ss').toString(),
+      skip: '8',
+      interval: '1h',
+    });
+    const chartsColumnList = props.chartsColumns ? props.chartsColumns : getTableHeaderColumns(props.chartsColumnsType);
+    const resultXAxisPropType = ref('');
+    const resultDataSource = ref<any[]>([]);
+    const regData = ref<any[]>([]);
+    const detailDataSource = ref<any[]>([]);
+    const historyData = ref([]);
+    const currentPage = ref<number>(1);
+    const pageSize = ref<number>(20);
+    const total = ref(0);
+    interface RegValueItem {
+      type: string;
+      value: number | string;
+      name: string;
+      color: string;
+      lineType: 'dashed' | 'solid';
+    }
+    const standardValues = ref<RegValueItem[]>([]);
+    const echartsOption = {
+      grid: {
+        top: '60px',
+        left: '10px',
+        right: chartsColumnList.length * 15 + 'px',
+        bottom: '5%',
+        containLabel: true,
       },
-      chartsColumnsHistory: {
-        type: Array,
-        default: () => [],
+      toolbox: {
+        feature: {},
       },
-      chartsColumnsType: {
-        type: String,
-        required: true,
+      xAxis: {
+        axisLabel: {
+          interval: 0,
+        },
       },
-      dataSource: {
-        type: Array,
-        default: () => [],
+    };
+    const echartsOption1 = {
+      grid: {
+        top: '70px',
+        left: '10px',
+        right: chartsColumnList.length * 15 + 'px',
+        bottom: '45px',
+        containLabel: true,
       },
-      deviceListApi: {
-        type: Function,
-        required: true,
+      toolbox: {
+        feature: {},
       },
-      deviceType: {
-        type: String,
-        required: true,
+      xAxis: {
+        interval: 0,
       },
-      option: {
-        type: Object,
-        default: () => ({}),
+    };
+    const echartsOption2 = {
+      grid: {
+        top: '70px',
+        left: '10px',
+        right: chartsColumnList.length * 15 + 'px',
+        bottom: '2%',
+        containLabel: true,
       },
-      xAxisPropType: {
-        type: String,
-        required: true,
+      toolbox: {
+        feature: {},
       },
-    },
-    setup(props) {
-      const globalConfig = inject('globalConfig');
-      const stationType = ref('plc1');
-      let historyList;
-      // if (globalConfig.History_Type == 'vent') {
-      //   historyList = (params) => defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params });
-      // } else {
-      //   historyList = (params) => defHttp.post({ url: '/monitor/history/getHistoryData', params });
-      // }
-      const chartsType = ref('history');
-      const deviceId = ref('');
-      const options = ref([]);
-      const historyParams = reactive({
-        ttime_begin: dayjs().startOf('date').format('YYYY-MM-DD HH:mm:ss').toString(),
-        ttime_end: dayjs().format('YYYY-MM-DD HH:mm:ss').toString(),
-        skip: '8',
-        interval: '1h',
-      });
-      const chartsColumnList = props.chartsColumns ? props.chartsColumns : getTableHeaderColumns(props.chartsColumnsType);
-      const resultXAxisPropType = ref('');
-      const resultDataSource = ref<any[]>([]);
-      const detailDataSource = ref<any[]>([]);
-      const currentPage = ref<number>(1);
-      const pageSize = ref<number>(20);
-      const total = ref(0);
-      const echartsOption = {
-        grid: {
-          top: '60px',
-          left: '10px',
-          right: chartsColumnList.length * 15 + 'px',
-          bottom: '5%',
-          containLabel: true,
-        },
-        toolbox: {
-          feature: {},
-        },
-        xAxis: {
-          axisLabel: {
-            interval: 0,
-          },
-        },
-      };
-      const echartsOption1 = {
-        grid: {
-          top: '70px',
-          left: '10px',
-          right: chartsColumnList.length * 15 + 'px',
-          bottom: '45px',
-          containLabel: true,
-        },
-        toolbox: {
-          feature: {},
-        },
-        xAxis: {
-          interval: 0,
-        },
-      };
-      const echartsOption2 = {
-        grid: {
-          top: '70px',
-          left: '10px',
-          right: chartsColumnList.length * 15 + 'px',
-          bottom: '2%',
-          containLabel: true,
-        },
-        toolbox: {
-          feature: {},
-        },
-      };
+    };
 
-      const onChange = (pageNumber: number) => {
-        console.log('Page: ', pageNumber);
-      };
+    const onChange = (pageNumber: number) => {
+      console.log('Page: ', pageNumber);
+    };
+    const getStandardValuesByID = () => {
+      standardValues.value = [];
+      if (!historyData.value.length || !regData.value.length) return [];
+      const idMap = new Map(regData.value.map((item) => [item.deviceID, item]));
+      const newIdMap = new Map();
+      historyData.value.forEach((item) => {
+        if (idMap.has(item.gdeviceid)) {
+          const regItem = idMap.get(item.gdeviceid);
+          newIdMap.set(item.gdeviceid, {
+            regulation: regItem.regulation,
+          });
+          console.log(newIdMap, '123123123');
+        }
+      });
+      newIdMap.forEach((item) => {
+        if (item.regulation) {
+          // 最小值横线
+          standardValues.value.push({
+            type: item.regulation.type,
+            value: item.regulation.fmin,
+            name: '规程值下限',
+            color: '#ff0000',
+            lineType: 'solid' as const,
+          });
+          // 最大值横线
+          standardValues.value.push({
+            type: item.regulation.type,
+            value: item.regulation.fmax,
+            name: '规程值上限',
+            color: '#ff0000',
+            lineType: 'solid' as const,
+          });
+        }
+      });
+      // regValues.value = standardValues;
+      console.log(standardValues.value, '33333');
+    };
 
-      watch(
-        [chartsType, deviceId, historyParams, pageSize, currentPage],
-        async (
-          [newChartsType, newDeviceId, newHistoryParams, newPageSize, newCurrentPage],
-          [oldChartsType, oldDeviceId, oldHistoryParams, oldPageSize, oldCurrentPage]
-        ) => {
-          console.log('[ historyParams ] >', historyParams.ttime, dayjs(historyParams.ttime).format('HH:mm:ss'));
-          if (newChartsType === 'listMonitor') {
-            // 实时监测所有
-            resultDataSource.value = props.dataSource;
-          } else if (newChartsType === 'history') {
-            resultDataSource.value = [];
-            // 历史
-            if (newChartsType !== oldChartsType || newDeviceId !== oldDeviceId) {
-              currentPage.value = 1;
-            }
-            const device = options.value.find((device) => device['deviceID'] === newDeviceId);
-            if (device) {
-              let res;
-              stationType.value = device['stationtype'];
-              if (device['stationtype'] !== 'redis') {
-                resultXAxisPropType.value = 'ttime';
-                historyList = (params) => defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params });
-                const datas = await historyList({
-                  ttime_begin: newHistoryParams.ttime_begin,
-                  ttime_end: newHistoryParams.ttime_end,
-                  strtype: device.deviceType,
-                  gdeviceid: newDeviceId,
-                  skip: newHistoryParams.skip,
-                  pageSize: pageSize.value,
-                  pageNo: currentPage.value,
-                  column: 'createTime',
-                });
-                res = datas['datalist']['records'];
-                if (res && res.length > 0) {
-                  resultDataSource.value = res.map((item) => Object.assign(item, item.readData));
-                } else {
-                  resultDataSource.value = [];
-                }
-                total.value = datas['datalist'].total;
+    watch(
+      [chartsType, deviceId, historyParams, pageSize, currentPage],
+      async (
+        [newChartsType, newDeviceId, newHistoryParams, newPageSize, newCurrentPage],
+        [oldChartsType, oldDeviceId, oldHistoryParams, oldPageSize, oldCurrentPage]
+      ) => {
+        console.log('[ historyParams ] >', historyParams.ttime, dayjs(historyParams.ttime).format('HH:mm:ss'));
+        if (newChartsType === 'listMonitor') {
+          // 实时监测所有
+          resultDataSource.value = props.dataSource;
+          regData.value = props.dataSource;
+        } else if (newChartsType === 'history') {
+          resultDataSource.value = [];
+          // 历史
+          if (newChartsType !== oldChartsType || newDeviceId !== oldDeviceId) {
+            currentPage.value = 1;
+          }
+          const device = options.value.find((device) => device['deviceID'] === newDeviceId);
+          if (device) {
+            let res;
+            stationType.value = device['stationtype'];
+            if (device['stationtype'] !== 'redis') {
+              resultXAxisPropType.value = 'ttime';
+              historyList = (params) => defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params });
+              const datas = await historyList({
+                ttime_begin: newHistoryParams.ttime_begin,
+                ttime_end: newHistoryParams.ttime_end,
+                strtype: device.deviceType,
+                gdeviceid: newDeviceId,
+                skip: newHistoryParams.skip,
+                pageSize: pageSize.value,
+                pageNo: currentPage.value,
+                column: 'createTime',
+              });
+              res = datas['datalist']['records'];
+              if (res && res.length > 0) {
+                resultDataSource.value = res.map((item) => Object.assign(item, item.readData));
+                historyData.value = res.map((item) => Object.assign(item, item.readData));
+                getStandardValuesByID();
               } else {
-                historyList = (params) => defHttp.post({ url: '/monitor/history/getHistoryData', params });
-                resultXAxisPropType.value = 'time';
-                res = await historyList({
-                  pageSize: pageSize.value,
-                  pageNum: currentPage.value,
-                  startTime: newHistoryParams.ttime_begin,
-                  endTime: newHistoryParams.ttime_end,
-                  deviceId: newDeviceId,
-                  strtype: device.deviceType,
-                  interval: newHistoryParams.interval,
-                  column: 'createTime',
-                });
-                if (res && res.records && res.records.length > 0) {
-                  resultDataSource.value = res.records.map((item) => Object.assign(item, item.readData));
-                } else {
-                  resultDataSource.value = [];
-                }
-                total.value = res.total;
+                resultDataSource.value = [];
               }
+              total.value = datas['datalist'].total;
+            } else {
+              historyList = (params) => defHttp.post({ url: '/monitor/history/getHistoryData', params });
+              resultXAxisPropType.value = 'time';
+              res = await historyList({
+                pageSize: pageSize.value,
+                pageNum: currentPage.value,
+                startTime: newHistoryParams.ttime_begin,
+                endTime: newHistoryParams.ttime_end,
+                deviceId: newDeviceId,
+                strtype: device.deviceType,
+                interval: newHistoryParams.interval,
+                column: 'createTime',
+              });
+              if (res && res.records && res.records.length > 0) {
+                resultDataSource.value = res.records.map((item) => Object.assign(item, item.readData));
+              } else {
+                resultDataSource.value = [];
+              }
+              total.value = res.total;
             }
-          } else if (newChartsType === 'detail') {
-            // 设备详情
-            resultXAxisPropType.value = 'readTime';
-            if (newDeviceId !== oldDeviceId) {
-              detailDataSource.value = [];
-            }
+          }
+        } else if (newChartsType === 'detail') {
+          // 设备详情
+          resultXAxisPropType.value = 'readTime';
+          if (newDeviceId !== oldDeviceId) {
+            detailDataSource.value = [];
           }
         }
-      );
-      watchEffect(() => {
-        if (chartsType.value === 'detail') {
-          const currentData = props.dataSource.find((item: any) => item.deviceID === deviceId.value);
-          if (currentData) {
-            const isHas = detailDataSource.value.find((item) => item[resultXAxisPropType.value] === currentData[resultXAxisPropType.value]);
-            if (!isHas) {
-              if (detailDataSource.value.length < 15) {
-                detailDataSource.value.push(currentData);
-              } else {
-                detailDataSource.value.shift();
-                detailDataSource.value.push(currentData);
-              }
+      }
+    );
+    watchEffect(() => {
+      if (chartsType.value === 'detail') {
+        const currentData = props.dataSource.find((item: any) => item.deviceID === deviceId.value);
+        if (currentData) {
+          const isHas = detailDataSource.value.find((item) => item[resultXAxisPropType.value] === currentData[resultXAxisPropType.value]);
+          if (!isHas) {
+            if (detailDataSource.value.length < 15) {
+              detailDataSource.value.push(currentData);
+            } else {
+              detailDataSource.value.shift();
+              detailDataSource.value.push(currentData);
             }
           }
         }
-      });
+      }
+    });
 
-      onMounted(async () => {
-        const res = await props.deviceListApi();
-        // debugger;
-        if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
-          options.value = res['msgTxt'][0]['datalist'];
-          deviceId.value = options.value[0]['deviceID'];
-        }
-      });
+    onMounted(async () => {
+      const res = await props.deviceListApi();
+      // debugger;
+      if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
+        options.value = res['msgTxt'][0]['datalist'];
+        deviceId.value = options.value[0]['deviceID'];
+      }
+    });
 
-      return {
-        chartsType,
-        deviceId,
-        resultDataSource,
-        historyParams,
-        options,
-        resultXAxisPropType,
-        detailDataSource,
-        currentPage,
-        pageSize,
-        total,
-        echartsOption,
-        echartsOption1,
-        echartsOption2,
-        onChange,
-        globalConfig,
-        stationType,
-        chartsColumnList,
-      };
-    },
-  });
+    return {
+      chartsType,
+      deviceId,
+      resultDataSource,
+      historyParams,
+      options,
+      resultXAxisPropType,
+      detailDataSource,
+      currentPage,
+      pageSize,
+      total,
+      echartsOption,
+      echartsOption1,
+      echartsOption2,
+      standardValues,
+      onChange,
+      globalConfig,
+      stationType,
+      chartsColumnList,
+    };
+  },
+});
 </script>
 <style lang="less">
-  :deep(.vent-select-dropdown) {
+:deep(.vent-select-dropdown) {
+  color: #000 !important;
+  .vent-select-item {
     color: #000 !important;
-    .vent-select-item {
-      color: #000 !important;
-    }
   }
+}
 </style>
 <style lang="less" scoped>
-  @import '/@/design/theme.less';
-  .charts-container {
-    position: relative;
+@import '/@/design/theme.less';
+.charts-container {
+  position: relative;
+  height: 100%;
+  .charts-box {
+    width: 100%;
     height: 100%;
-    .charts-box {
-      width: 100%;
-      height: 100%;
-      position: absolute;
-      bottom: 0;
-      top: 0px;
-    }
-    .@{ventSpace}-picker,
-    .@{ventSpace}-select-selector {
-      background: #00000017 !important;
-      border: 1px solid @vent-form-item-border !important;
-      input,
-      .@{ventSpace}-select-selection-item,
-      .@{ventSpace}-picker-suffix {
-        color: #fff !important;
-      }
-      .@{ventSpace}-select-selection-placeholder {
-        color: #b7b7b7 !important;
-      }
-    }
-    .@{ventSpace}-select-arrow,
-    .@{ventSpace}-picker-separator {
+    position: absolute;
+    bottom: 0;
+    top: 0px;
+  }
+  .@{ventSpace}-picker,
+  .@{ventSpace}-select-selector {
+    background: #00000017 !important;
+    border: 1px solid @vent-form-item-border !important;
+    input,
+    .@{ventSpace}-select-selection-item,
+    .@{ventSpace}-picker-suffix {
       color: #fff !important;
     }
+    .@{ventSpace}-select-selection-placeholder {
+      color: #b7b7b7 !important;
+    }
+  }
+  .@{ventSpace}-select-arrow,
+  .@{ventSpace}-picker-separator {
+    color: #fff !important;
   }
-  :deep(.@{ventSpace}-select-dropdown) {
+}
+:deep(.@{ventSpace}-select-dropdown) {
+  color: #000 !important;
+  .@{ventSpace}-select-item {
     color: #000 !important;
-    .@{ventSpace}-select-item {
-      color: #000 !important;
-    }
   }
+}
 </style>