zmc
2023-08-14 172d73cbe737c04b3d2c3fe8908db2460c241543
src/test/TestNoData.vue
@@ -19,7 +19,10 @@
      <TimeSelect @submit-time="giveTime"></TimeSelect>
      <!-- </div> -->
    </div>
    <div ref="h2" style="display: flex; margin-top: 2px; justify-content: right">
    <div
      ref="h2"
      style="display: flex; margin-top: 2px; justify-content: right"
    >
      <!-- <span class="collapse-header-text">
              静安区 {{ beginTime }} —— {{ endTime }} 油烟检测异常信息汇总</span
            > -->
@@ -31,13 +34,14 @@
        style="margin-left: 20px"
        >查询</el-button
      >
      <el-button
      <!-- <el-button
        type="warning"
        plain
        @click="getAllData"
        style="margin-left: 20px"
        >查询全部</el-button
      >
      > -->
      <el-tooltip
        class="box-item"
@@ -58,8 +62,8 @@
    </div>
    <div style="display: flex; justify-content: right">
      <span class="collapse-header-text">
              静安区 {{ beginTime }} —— {{ endTime }} 油烟检测异常信息汇总</span
            >
        静安区 {{ beginTime }} —— {{ endTime }} 油烟检测异常信息汇总</span
      >
    </div>
    <br />
@@ -72,7 +76,7 @@
            content="点击可折叠"
            placement="right-start"
          >
            <h4 class="collapse-header"> 异常分析</h4>
            <h4 class="collapse-header">异常分析</h4>
            <el-icon class="header-icon">
              <i-ep-info-filled />
            </el-icon>
@@ -84,119 +88,172 @@
            content="点击可折叠"
            placement="right-start"
          >
          </el-tooltip>
        </template>
        <el-card class="box-card">
          <el-row :gutter="25">
            <el-col :span="8">
              <div style="display: flex;">
                <img src="@/assets/exceed.jpg" style="width: 25px;height: 25px;margin-top: 5px;" />
              <span style="font-size: 16px;font-weight: bold;margin-top: 4px;margin-left: 4px;">油烟浓度超标</span>
              <div style="display: flex">
                <img
                  src="@/assets/exceed.jpg"
                  style="width: 25px; height: 25px; margin-top: 5px"
                />
                <span
                  style="
                    font-size: 16px;
                    font-weight: bold;
                    margin-top: 4px;
                    margin-left: 4px;
                  "
                  >油烟浓度超标</span
                >
              </div>
              <div class="box-card-label">
                <span class="box-card-label">店铺数量:</span>
                <span style="font-size: 20px"
                  >{{ exception0.length }} /{{ shopsTotal }}</span
                >
                <span style="margin-left: 150px; font-size: 14px">
                  占比:{{
                    ((exception0.length / shopsTotal) * 100).toFixed(1)
                  }}%</span
                >
                <el-scrollbar>
                  <span class="box-card-label">店铺数量:</span>
                  <span style="font-size: 20px"
                    >{{ exception0.length }} /{{ shopsTotal }}</span
                  >
                  <span style="margin-left: 150px; font-size: 14px">
                    占比:{{
                      ((exception0.length / shopsTotal) * 100).toFixed(1)
                    }}%</span
                  >
                </el-scrollbar>
              </div>
              <hr />
              <div class="box-card-butcontainer">
                <el-card class="sub-box-card">
                <ExceptionText
                  v-for="(item,index) in exception0"
                  :key="item"
                  :devId="item.devId"
                  exception-value="0"
                  :begin-time="beginTime"
                  :end-time="endTime"
                  @submit-exception-data="getAbnormalDataByClick"
                >
                  {{ item.diName }}
                  <span v-if="index<exception0.length-1" class="text-blank"> , </span>
                </ExceptionText>
                <el-card class="sub-box-card">
                  <el-scrollbar max-height="70px">
                    <ExceptionText
                      v-for="(item, index) in exception0"
                      :key="item"
                      :devId="item.devId"
                      exception-value="0"
                      :begin-time="beginTime"
                      :end-time="endTime"
                      @submit-exception-data="getAbnormalDataByClick"
                    >
                      {{ item.diName }}
                      <span
                        v-if="index < exception0.length - 1"
                        class="text-blank"
                        >,</span
                      >
                    </ExceptionText>
                  </el-scrollbar>
                </el-card>
              </div>
            </el-col>
            <el-col :span="8">
              <div style="display: flex;">
              <img src="@/assets/exception.jpg" style="width: 25px;height: 25px;margin-top: 5px;" />
              <span style=" font-size: 16px;font-weight: bold;margin-top: 5px;margin-left: 4px;"
                >供电异常</span
              >
            </div>
              <div style="display: flex">
                <img
                  src="@/assets/exception.jpg"
                  style="width: 25px; height: 25px; margin-top: 5px"
                />
                <span
                  style="
                    font-size: 16px;
                    font-weight: bold;
                    margin-top: 5px;
                    margin-left: 4px;
                  "
                  >供电异常</span
                >
              </div>
              <div class="box-card-label">
                <span class="box-card-label">店铺数量:</span>
                <span style="font-size: 20px"
                  >{{ exception1.length }} /{{ shopsTotal }}</span
                >
                <span style="margin-left: 150px; font-size: 14px">
                  占比:{{
                    ((exception1.length / shopsTotal) * 100).toFixed(1)
                  }}%</span
                >
                <el-scrollbar>
                  <span class="box-card-label">店铺数量:</span>
                  <span style="font-size: 20px"
                    >{{ exception1.length }} /{{ shopsTotal }}</span
                  >
                  <span style="margin-left: 150px; font-size: 14px">
                    占比:{{
                      ((exception1.length / shopsTotal) * 100).toFixed(1)
                    }}%</span
                  >
                </el-scrollbar>
              </div>
              <hr />
              <div>
                <el-card class="sub-box-card">
                <ExceptionText
                  v-for="(item,index) in exception1"
                  :key="item"
                  :devId="item.devId"
                  exception-value="1"
                  :begin-time="beginTime"
                  :end-time="endTime"
                  @submit-exception-data="getAbnormalDataByClick"
                >
                  {{ item.diName }}
                  <span v-if="index < exception1.length-1" class="text-blank"> , </span>
                </ExceptionText>
              </el-card>
                <el-card class="sub-box-card">
                  <el-scrollbar max-height="70px">
                    <ExceptionText
                      v-for="(item, index) in exception1"
                      :key="item"
                      :devId="item.devId"
                      exception-value="1"
                      :begin-time="beginTime"
                      :end-time="endTime"
                      @submit-exception-data="getAbnormalDataByClick"
                    >
                      {{ item.diName }}
                      <span
                        v-if="index < exception1.length - 1"
                        class="text-blank"
                        >,</span
                      >
                    </ExceptionText>
                  </el-scrollbar>
                </el-card>
              </div>
            </el-col>
            <el-col :span="8">
              <div style="display: flex;">
              <img src="@/assets/offline.jpg" style="width: 25px;height: 25px;margin-top: 5px;" />
              <span style=" font-size: 16px;font-weight: bold;margin-top: 5px;margin-left: 4px;">掉线</span>
              <div style="display: flex">
                <img
                  src="@/assets/offline.jpg"
                  style="width: 25px; height: 25px; margin-top: 5px"
                />
                <span
                  style="
                    font-size: 16px;
                    font-weight: bold;
                    margin-top: 5px;
                    margin-left: 4px;
                  "
                  >掉线</span
                >
              </div>
              <div class="box-card-label">
                <span class="box-card-label">店铺数量:</span>
                <span style="font-size: 20px"
                  >{{ exception2.length }} /{{ shopsTotal }}</span
                >
                <span style="margin-left: 150px; font-size: 14px">
                  占比:{{
                    ((exception2.length / shopsTotal) * 100).toFixed(1)
                  }}%</span
                >
                <el-scrollbar>
                  <span class="box-card-label">店铺数量:</span>
                  <span style="font-size: 20px"
                    >{{ exception2.length }} /{{ shopsTotal }}</span
                  >
                  <span style="margin-left: 150px; font-size: 14px">
                    占比:{{
                      ((exception2.length / shopsTotal) * 100).toFixed(1)
                    }}%</span
                  >
                </el-scrollbar>
              </div>
              <hr />
              <div>
                <el-card class="sub-box-card">
                <ExceptionText
                  v-for="(item,index) in exception2"
                  :key="item"
                  :devId="item.devId"
                  exception-value="2"
                  :begin-time="beginTime"
                  :end-time="endTime"
                  @submit-exception-data="getAbnormalDataByClick"
                >
                  {{ item.diName }}
                  <span v-if="index<exception2.length-1" class="text-blank"> , </span>
                </ExceptionText>
                <el-card class="sub-box-card">
                  <el-scrollbar max-height="70px">
                    <ExceptionText
                      v-for="(item, index) in exception2"
                      :key="item"
                      :devId="item.devId"
                      exception-value="2"
                      :begin-time="beginTime"
                      :end-time="endTime"
                      @submit-exception-data="getAbnormalDataByClick"
                    >
                      {{ item.diName }}
                      <span
                        v-if="index < exception2.length - 1"
                        class="text-blank"
                        >,</span
                      >
                    </ExceptionText>
                  </el-scrollbar>
                </el-card>
              </div>
            </el-col>
@@ -204,19 +261,19 @@
        </el-card>
      </el-collapse-item>
    </el-collapse>
 <!-- <hr/>
    <!-- <hr/>
 <br> -->
    <h4 class="table-text"> 异常数据</h4>
    <h4 class="table-text">异常数据</h4>
    <el-card class="table-page" v-show="!isNoData">
      <el-table
        ref="tableH"
        v-loading="loading"
        :data="displayData"
        style="width: 100%"
        :row-class-name="tableRowClassName"
        stripe
        border
        :height=tableHeight
        border
        :height="tableHeight"
      >
        <el-table-column fixed prop="diName" label="店铺名称" width="340">
          <template #default="{ row }">
@@ -323,8 +380,11 @@
        <!-- 超标数据时 -->
        <!-- 折线图 -->
        <!-- 掉线 -->
        <div
          ref="chart"
          ref="chart1"
          v-show="isOfflineShow"
          style="
            width: 100%;
            height: 300px;
@@ -335,8 +395,20 @@
          "
        ></div>
        <!--  v-show="!isAbnormal" -->
        <!-- 表格 -->
        <!-- 超标 -->
        <div
          ref="chart2"
          v-show="isExceedShow"
          style="
            width: 100%;
            height: 300px;
            /* min-width: 100px; */
            margin-bottom: 20px;
            margin-left: 10px;
            min-width: 350px;
          "
        ></div>
        <!-- <ExceptionTypeLineChart :allData="allChartData"></ExceptionTypeLineChart> -->
        <!--  -->
        <div style="margin-top: 40px; margin-bottom: 5px; border: 1px">
@@ -373,7 +445,6 @@
</template>
<script>
import ExceptionType from '../sfc/ExceptionType.vue';
import TimeSelect from '../sfc/TimeSelect.vue';
import ExceptionText from '../sfc/ExceptionText.vue';
@@ -385,22 +456,31 @@
const ShopNameAndID = defineAsyncComponent(() =>
  import('../sfc/../sfc/ShopNameAndID.vue')
);
// 异步组件
// const ExceptionTypeLineChart = defineAsyncComponent(() =>
//   import('../sfc/ExceptionTypeLineChart.vue')
// )
export default {
  name: 'TablePage',
  components: {
    ExceptionType,
    TimeSelect,
    ShopNameAndID,
    ExceptionText
    // ExceptionTypeLineChart
  },
  data() {
    return {
      //掉线或超标的图形展示
      isOfflineShow: false,
      isExceedShow: false,
      // 折线图展示
      isChartShow: false,
      // table元素
      tableRef:null,
      tableRef: null,
      // 异常表格数据
      tableHeight:300,
      tableHeight: 300,
      // 空数据状态
      isNoData: false,
      // 弹出框中表格条数
@@ -441,7 +521,8 @@
      afterData: [],
      // 折线图实例
      chart: null,
      chart1: null,
      chart2: null,
      // -1表示未选择表格的行
      selectedRowIndex: -1,
@@ -531,7 +612,7 @@
          this.isNextCantouch = false;
        }
      }
      // 处于表格最后一提哦啊数据 设置‘下一条’按钮不可点
      // 处于表格最后一条数据 设置‘下一条’按钮不可点
      else if (newVaue === this.displayData.length - 1) {
        this.isNextCantouch = true;
        //用户先点了第一条,pre为true,然后点击最后一条,next为true。此时两个按钮都被封锁
@@ -552,11 +633,13 @@
    },
    endTime() {
      this.getShopNames();
    },
    centerDialogVisible() {
      window.addEventListener('resize', this.updateChart);
    }
  },
  mounted() {
    // 从接口获取店铺名称 给级联下拉框
    this.getDeviceInfo();
@@ -566,28 +649,99 @@
    // 根据异常类型返回店铺名称和设备编号 渲染异常分析部分对应的店铺名
    this.getShopNames();
    window.addEventListener('resize', this.updateChart);
    // this.tableHeight = this.calcTableHeight()
  },
  methods: {
    // calcTableHeight() {
    //   const h1 = this.$refs.h1.offsetHeight;
    //   const h2 = this.$refs.h2.offsetHeight;
    //   const h3 = this.$refs.h3.$el.offsetHeight;
    //   const h4 = this.$refs.h4.$el.offsetHeight;
    //   // return `calc(100vh - ${h1}px - ${h2}px - var(--el-main-padding) * 2 - var(--el-header-height))`;
    //   return `calc(100vh - ${h1}px - ${h2}px- ${h3}px - ${h4}px  - 60px - var(--el-main-padding) * 2)`;
    // },
    // 时间是否超过10分钟
    isTimeDifferenceGreaterThan10Minutes(dateString1, dateString2) {
      const date1 = new Date(dateString1);
      const date2 = new Date(dateString2);
    warn() {
      alert('点击了');
      // 计算两个日期的时间差(毫秒)
      const timeDifferenceMs = Math.abs(date1 - date2);
      // 转换为分钟
      const timeDifferenceMinutes = Math.floor(timeDifferenceMs / (1000 * 60));
      // 判断时间差是否大于10分钟
      return timeDifferenceMinutes > 10;
    },
    // 以10分钟为间隔返回时间字符串数组
    generateTimePoints(timePoints,yAxisData) {
      let updatedTimePoints = [];
      let yAxisDataAdressed = []
      for (let i = 0; i < timePoints.length; i++) {
        updatedTimePoints.push(timePoints[i]);
        yAxisDataAdressed.push(yAxisData[i])
        if (i < timePoints.length - 1) {
          let current = timePoints[i];
          let next = timePoints[i + 1];
          while (this.isTimeDifferenceGreaterThan10Minutes(current, next)) {
            current = dayjs(current)
              .add(10, 'minute')
              .format('YYYY-MM-DD HH:mm:ss');
            updatedTimePoints.push(current);
            yAxisDataAdressed.push(null)
          }
        }
      }
      let obj = {}
      obj['time'] = updatedTimePoints
      obj['data'] = yAxisDataAdressed
      return obj;
    },
    isExceedOneMonth(dateStr1, dateStr2) {
      // 超过一个月,返回True,否则返回False
      // 将日期字符串转为日期对象
      const date1 = new Date(dateStr1);
      const date2 = new Date(dateStr2);
      // 获取两个日期的年、月、日
      const year1 = date1.getFullYear();
      const month1 = date1.getMonth();
      const day1 = date1.getDate();
      const year2 = date2.getFullYear();
      const month2 = date2.getMonth();
      const day2 = date2.getDate();
      console.log(month1, month2);
      // 判断两个日期是否相差一个月
      if (year1 === year2) {
        // 年份相等,比较月份差值
        if (Math.abs(month1 - month2) === 1) {
          // 月份差值为1,还需要判断具体日期
          if (
            (month1 < month2 && day1 < day2) ||
            (month1 > month2 && day1 > day2)
          ) {
            return true;
          }
        }
      } else if (Math.abs(year1 - year2) === 1) {
        // 年份差值为1,比较月份和日期
        if (
          (year1 < year2 && month1 === 11 && month2 === 0 && day1 < day2) ||
          (year1 > year2 && month1 === 0 && month2 === 11 && day1 > day2)
        ) {
          return true;
        }
      }
      // 默认返回false,表示两个日期字符串不相差一个月
      return false;
    },
    // 刚打开卡片时第一个图形不会自动伸缩 当点击上/下一条时会自动伸缩
    // 图形响应式变化
    updateChart() {
      this.$nextTick(() => {
        if (this.chart) {
          this.chart.resize();
        if (this.chart1) {
          this.chart1.resize();
        }
        if (this.chart2) {
          this.chart2.resize();
        }
      });
    },
@@ -637,6 +791,7 @@
        this.rowBeginTime,
        this.rowEndTime
      );
      for (let i = 0; i < abnormalTimeTenMinute.length; i++) {
        this.exceedingData.push({
          mvStatCode: this.rowMvStatCode,
@@ -645,6 +800,22 @@
          mvFumeConcentration2: ''
        });
      }
      // 全部数据加入
      // for (let i = 0; i < data.length; i++) {
      //   if (data[i] == null) {
      //     this.exceedingData.push({
      //       mvStatCode: this.rowMvStatCode,
      //       diName: this.rowShopName,
      //       mvDataTime: abnormalTimeTenMinute[i],
      //       mvFumeConcentration2: ''
      //     });
      //   }
      //   else {
      //     this.exceedingData.push(data[i]);
      //   }
      // }
      // 保存无数据时表格条数
      this.exceptionTotal = abnormalTimeTenMinute.length;
    },
@@ -688,7 +859,7 @@
          .then((response) => {
            // 保存返回的超标数据
            this.exceedingData = response.data.data;
            this.chart = null;
            // this.chart = null;
            this.drawChart();
            this.exceptionTotal = this.exceedingData.length;
          });
@@ -696,12 +867,6 @@
      //表格的第一行,则上一条无数据
      else if (this.selectedRowIndex === 0) {
        console.log(null);
        // 警告
        // ElMessage.warn('已是第一条数据');
        // ElMessage.info('已是该页第一条数据');
        // ’上一条‘的按钮不可点击
        // this.isPreCantouch = true
      }
    },
@@ -737,7 +902,6 @@
            this.exceedingData = response.data.data;
            console.log('返回的异常数据为:');
            console.log(this.exceedingData);
            this.chart = null;
            this.drawChart();
            this.exceptionTotal = this.exceedingData.length;
          });
@@ -747,7 +911,6 @@
        console.log(null);
        // 警告
        // ElMessage.info('已是该页最后一条数据');
        // ’下一条‘的按钮不可点击
        // this.isNextCantouch = true
      }
@@ -796,8 +959,8 @@
    // 用户根据输入的条件查询
    showTable() {
      if (this.beginTime > this.endTime) {
        alert('请输入正确的时间范围');
      if (this.isExceedOneMonth(this.beginTime, this.endTime)) {
        alert('时间跨度不能超过一个月');
        return;
      }
      let params = {};
@@ -825,7 +988,7 @@
          this.total = this.abnormalData.length;
          this.loading = false;
          if (response.data.data.length == 0) {
            alert('该时段无数据');
            ElMessage('该时段无数据');
            this.isNoData = true;
            return;
          }
@@ -842,19 +1005,10 @@
      this.handleCurrentChange(1);
    },
    handleCurrentChange(val) {
      // this.startIndex = (val - 1) * this.pageSize;
      // const endIndex = this.startIndex + this.pageSize;
      const startIndex = (val - 1) * this.pageSize;
      const endIndex = startIndex + this.pageSize;
      // console.log('起始索引为:',this.startIndex)
      // console.log('页面大小为:',this.pageSize)
      this.displayData = this.abnormalData.slice(startIndex, endIndex);
      // setTimeout(() => {
      //  this.displayData = this.abnormalData
      // }, 1000);
      // console.log(this.displayData);
      this.displayData = this.abnormalData.slice(startIndex, endIndex);
    },
    //相差多少个十分钟  计算中并不包括开始时间,但包括结束时间。
@@ -872,25 +1026,15 @@
    // 供电异常和掉线的折线图
    linechart(xAxisData1, abnormalBeginTime, abnormalEndTime, fumeExceeding) {
      this.chart = echarts.init(this.$refs.chart);
      // $('#ModalGrade').on('shown.bs.modal', function(){
      //   this.chart.resize()
      // })
      this.chart.setOption({
        title: {
          // text: '油烟超标数据',
          // left: 'center'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
      // 超标图形chart2实例为空
      if (this.chart2 != null) {
        this.chart2 == null;
      }
      if (this.chart1 == null) {
        this.chart1 = echarts.init(this.$refs.chart1);
      }
      this.chart1.setOption({
        tooltip: {},
        // legend: {
        //   data: ['油烟超标数据']
        // },
        toolbox: {
          // 工具栏
          feature: {
@@ -904,14 +1048,8 @@
          }
        },
        xAxis: {
          // type: 'time',
          // 在类目轴(type: 'category')中有效。
          data: xAxisData1,
          name: '时间'
          // axisLabel: {
          //   interval:3,
          //   rotate:40
          // }
        },
        yAxis: {
          type: 'value',
@@ -924,7 +1062,7 @@
        },
        series: [
          {
            name: '油烟超标数据',
            name: '油烟数据',
            type: 'line',
            data: fumeExceeding,
            markLine: {
@@ -951,15 +1089,16 @@
    // 展示折线图
    drawChart() {
      // 当出现供电异常和掉线时,时段无数据 则拼接前后段数据
      if (
        this.exceedingData.length === 0 ||
        this.rowExceptionType === '1' ||
        this.rowExceptionType === '2'
      ) {
        // 重构表格 手动填充
        this.setExceptionData();
        this.isOfflineShow = true;
        this.isExceedShow = false;
        //  // 重构表格 手动填充
        //  this.setExceptionData();
        // 展示
        this.isAbnormal = true;
        // 拼接日期
@@ -998,83 +1137,121 @@
          beginTime: after10MinBegin,
          endTime: after40MinEnd
        };
        // 请求前半段
        axiosInstanceInstance
          .get('/fume/history', { params: paramsBefore })
          .then((result) => {
            this.beforeData = result.data.data;
            // 请求后半段
            axiosInstanceInstance
              .get('/fume/history', { params: paramsAfter })
              .then((result) => {
                this.afterData = result.data.data;
                //用null填充中异常无数据的时间
                //相差几个10分钟
                const TenMinuteNum = this.diffTenMinutesNum(
                  this.abnormalBt,
                  this.abnormalEt
                );
                //保存空值
                let tempArr = [];
                for (let i = 0; i < TenMinuteNum; i++) {
                  tempArr.push(null);
                }
                console.log('填充数组为:', tempArr);
                console.log('前后数据为:', this.beforeData, this.afterData);
                this.allExceptionTimeData = [
                  ...this.beforeData,
                  ...tempArr,
                  ...this.afterData
                ];
                console.log('合并后数组为', this.allExceptionTimeData);
                // 重构表格 手动填充
                this.setExceptionData(this.allExceptionTimeData);
                //展示图形
                // x轴日期时间
                let dateList = [];
                // y轴 超标油烟浓度
                let fumeExceeding = [];
                // 连续的时间
                let dateListTemp = []
                let fumeExceedingTemp = []
                for (let i = 0; i < this.allExceptionTimeData.length; i++) {
                  if (this.allExceptionTimeData[i] == null) {
                    //x轴日期
                    //无数据时, 为前面时间点增加10分钟
                    dateList.push(
                      dayjs(dateList[dateList.length - 1])
                        .add(10, 'minute')
                        .format('YYYY-MM-DD HH:mm:ss')
                    );
                    // 超标油烟浓度
                    fumeExceeding.push(null);
                  } else {
                    //x轴日期
                    dateList.push(this.allExceptionTimeData[i].mvDataTime);
                    // 超标油烟浓度
                    fumeExceeding.push(
                      this.allExceptionTimeData[i].mvFumeConcentration2
                    );
                  }
                }
                // 时间连续
                //  for(let i =0;i<dateList.length-1;i++){
                //   if(this.isTimeDifferenceGreaterThan10Minutes(dateList[i],dateList[i+1])){
                //     dateListTemp.push(dayjs(dateList[i]).add(10,'minute').format('YYYY-MM-DD HH:mm:ss'))
                //     fumeExceedingTemp.push(null)
                //   }else{
                //     dateListTemp.push(dateList[i])
                //     fumeExceedingTemp.push(fumeExceeding[i])
                //   }
                //  }
                 // 时间连续
                let objData= this.generateTimePoints(dateList,fumeExceeding);
                dateListTemp = objData['time']
                fumeExceedingTemp = objData['data']
                //展示折线图
                // this.chart = null;
                // console.log('x轴的日期为:',dateList);
                // console.log('开始和结束日期为:',this.abnormalBt,this.abnormalEt);
                let dateList1 = [];
                dateListTemp.forEach((item) => {
                  dateList1.push(dayjs(item).format('HH:mm'));
                });
                this.abnormalBt = dayjs(this.abnormalBt).format('HH:mm');
                this.abnormalEt = dayjs(this.abnormalEt).format('HH:mm');
                // console.log('变化的数据:',dateList1);
                // console.log('变化的数据:',this.abnormalBt);
                // console.log('变化的数据:',this.abnormalEt);
                if (this.char1) {
                  this.char1.dispose();
                }
                this.linechart(
                  dateList1,
                  this.abnormalBt,
                  this.abnormalEt,
                  fumeExceedingTemp
                );
              });
          });
        // 请求后半段
        axiosInstanceInstance
          .get('/fume/history', { params: paramsAfter })
          .then((result) => {
            this.afterData = result.data.data;
          });
        //用null填充中异常无数据的时间
        //相差几个10分钟
        const TenMinuteNum = this.diffTenMinutesNum(
          this.abnormalBt,
          this.abnormalEt
        );
        //保存空值
        let tempArr = [];
        for (let i = 0; i < TenMinuteNum; i++) {
          tempArr.push(null);
        }
        console.log('填充数组为:', tempArr);
        //合并数组
        setTimeout(() => {
          this.allExceptionTimeData = [
            ...this.beforeData,
            ...tempArr,
            ...this.afterData
          ];
          console.log('合并后数组为', this.allExceptionTimeData);
          //展示图形
          // x轴日期时间
          let dateList = [];
          // y轴 超标油烟浓度
          let fumeExceeding = [];
          for (let i = 0; i < this.allExceptionTimeData.length; i++) {
            if (this.allExceptionTimeData[i] == null) {
              //x轴日期
              //无数据时, 为前面时间点增加10分钟
              dateList.push(
                dayjs(dateList[dateList.length - 1])
                  .add(10, 'minute')
                  .format('YYYY-MM-DD HH:mm:ss')
              );
              // 超标油烟浓度
              fumeExceeding.push(null);
            } else {
              //x轴日期
              dateList.push(this.allExceptionTimeData[i].mvDataTime);
              // 超标油烟浓度
              fumeExceeding.push(
                this.allExceptionTimeData[i].mvFumeConcentration2
              );
            }
          }
          console.log('x:', dateList);
          console.log('fume:', fumeExceeding);
          //展示折线图
          this.chart = null;
          this.linechart(
            dateList,
            this.abnormalBt,
            this.abnormalEt,
            fumeExceeding
          );
        }, 500);
        // ----------------------------------------
      }
      // ----------------------------------------
      // 油烟浓度超标时的折线图
      else {
        // 图形展示
        this.isExceedShow = true;
        this.isOfflineShow = false;
        // // 清空,让无数据条数隐藏,使历史数据的标签条数显示出来
        // this.abnormalTimeTenMinute = []
        this.isAbnormal = false;
@@ -1094,6 +1271,8 @@
        let beginTime = new Date(dateList[0]);
        const endTime = new Date(dateList[dateList.length - 1]);
        let beginT = dayjs(beginTime).format('HH:mm');
        let endT = dayjs(endTime).format('HH:mm');
        // 往前30分钟
        const before30MinBegin = dayjs(beginTime)
          .subtract(30, 'minute')
@@ -1109,7 +1288,7 @@
        const after10MinEnd = dayjs(endTime)
          .add(10, 'minute')
          .format('YYYY-MM-DD HH:mm:ss');
        console.log('前后时间为', before30MinBegin, after30MinEnd);
        let paramsBefore = {
          devId: this.displayData[this.selectedRowIndex].devId,
          beginTime: before30MinBegin,
@@ -1125,167 +1304,213 @@
          .get('/fume/history', { params: paramsBefore })
          .then((result) => {
            this.beforeData = result.data.data;
          });
        // 请求后半段
        axiosInstanceInstance
          .get('/fume/history', { params: paramsAfter })
          .then((result) => {
            this.afterData = result.data.data;
          });
            // 请求后半段
            axiosInstanceInstance
              .get('/fume/history', { params: paramsAfter })
              .then((result) => {
                this.afterData = result.data.data;
                let before = [];
                let after = [];
                console.log('请求后的数据为', this.beforeData, this.afterData);
        setTimeout(() => {
          console.log('请求后的数据为', this.beforeData, this.afterData);
          this.allExceptionTimeData = [
            ...this.beforeData,
            ...this.exceedingData,
            ...this.afterData
          ];
          // x轴日期时间
          let dateList1 = [];
          // y轴 超标油烟浓度
          let fumeExceeding1 = [];
          console.log('所有数据长度', this.allExceptionTimeData.length);
          console.log('所有数据', this.allExceptionTimeData);
          for (let i = 0; i < this.allExceptionTimeData.length; i++) {
            if (this.allExceptionTimeData[i] == null) {
              //x轴日期
              //无数据时, 为前面时间点增加10分钟
              dateList1.push(
                dayjs(dateList1[dateList1.length - 1])
                  .add(10, 'minute')
                  .format('YYYY-MM-DD HH:mm:ss')
              );
              // 超标油烟浓度
              fumeExceeding1.push(null);
            } else {
              //x轴日期
              dateList1.push(this.allExceptionTimeData[i].mvDataTime);
              // 超标油烟浓度
              fumeExceeding1.push(
                this.allExceptionTimeData[i].mvFumeConcentration2
              );
            }
          }
          // 提取时间区间内的数据索引
          var startIndex = dateList1.findIndex((item) => item === dateList[0]);
          var endIndex = dateList1.findIndex(
            (item) => item === dateList[dateList.length - 1]
          );
          this.chart = echarts.init(this.$refs.chart);
          this.chart.setOption({
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            tooltip: {},
            // legend: {
            //   data: ['油烟超标数据']
            // },
            toolbox: {
              // 工具栏
              feature: {
                dataZoom: {
                  // 区域缩放
                  yAxisIndex: 'none'
                },
                // 保存为图片
                saveAsImage: {}
              }
            },
            xAxis: {
              // type: 'time',
              // 在类目轴(type: 'category')中有效。
              data: dateList1,
              name: '时间'
            },
            yAxis: {
              type: 'value',
              axisLabel: {
                show: true,
                interval: 'auto'
                // formatter:'{value} %'
              },
              name: 'mg/m³'
            },
            visualMap: {
              show: false,
              dimension: 0,
              pieces: [
                {
                  lte: startIndex,
                  color: 'green'
                },
                {
                  gt: startIndex,
                  lte: endIndex,
                  color: 'red'
                },
                {
                  gt: endIndex,
                  lte: dateList1.length - 1,
                  color: 'green'
                // 前后区间只显示距离超标区间时间最近的浓度小于1的时间点
                for (let i = this.beforeData.length - 1; i >= 0; i--) {
                  if (this.beforeData[i].mvFumeConcentration2 >= 1) {
                    break;
                  }
                  if (this.beforeData[i].mvFumeConcentration2 < 1) {
                    before.unshift(this.beforeData[i]);
                  }
                }
              ]
            },
            series: [
              {
                name: '油烟超标数据',
                type: 'line',
                data: fumeExceeding1,
                console.log('before:', before);
                for (let i = this.afterData.length - 1; i >= 0; i--) {
                  if (this.afterData[i].mvFumeConcentration2 >= 1) {
                    break;
                  }
                  if (this.afterData[i].mvFumeConcentration2 < 1) {
                    after.unshift(this.afterData[i]);
                  }
                }
                console.log('after:', after);
                this.allExceptionTimeData = [
                  ...before,
                  ...this.exceedingData,
                  ...after
                ];
                // markArea: {
                //   itemStyle: {
                //     color: 'rgba(255, 173, 177, 0.4)'
                //   },
                //   data: [
                //     [
                //       {
                //         name: '浓度超标',
                //         xAxis: dateList[0]
                //       },
                //       {
                //         xAxis: dateList[dateList.length - 1]
                //       }
                //     ]
                //   ]
                // },
                markLine: {
                  symbol: 'none',
                  itemStyle: {
                    // 基线公共样式
                    normal: {
                      lineStyle: {
                        // show:false,
                        // 'solid'实线;'dashed'虚线;'dotted'点线
                        type: 'dashed'
                // x轴日期时间
                let dateList1 = [];
                // y轴 超标油烟浓度
                let fumeExceeding1 = [];
                for (let i = 0; i < this.allExceptionTimeData.length; i++) {
                  if (this.allExceptionTimeData[i] == null) {
                    //x轴日期
                    //无数据时, 为前面时间点增加10分钟
                    dateList1.push(
                      dayjs(dateList1[dateList1.length - 1])
                        .add(10, 'minute')
                        .format('YYYY-MM-DD HH:mm:ss')
                    );
                    // 超标油烟浓度
                    fumeExceeding1.push(null);
                  } else {
                    //x轴日期
                    dateList1.push(this.allExceptionTimeData[i].mvDataTime);
                    // 超标油烟浓度
                    fumeExceeding1.push(
                      this.allExceptionTimeData[i].mvFumeConcentration2
                    );
                  }
                }
                let dateListLine = [];
                let fumeExceedingTemp = [];
                console.log('处理前数据为:', dateList1);
                // 颗粒度10分钟时间连续
                let objData= this.generateTimePoints(dateList1,fumeExceeding1);
                dateListLine = objData['time']
                fumeExceedingTemp = objData['data']
                console.log('处理后时间为:', dateListLine);
                console.log('处理后数据为:', fumeExceedingTemp);
                // 提取时间区间内的数据索引
                let startIndex = dateListLine.findIndex(
                  (item) => item === dateList[0]
                );
                let endIndex = dateListLine.findIndex(
                  (item) => item === dateList[dateList.length - 1]
                );
                let dateListTemp = [];
                dateListLine.forEach((item) => {
                  dateListTemp.push(dayjs(item).format('HH:mm'));
                });
                // 供电异常或掉线图形chart1实例为空
                if (this.chart1 != null) {
                  this.chart1 == null;
                }
                if (this.chart2 == null || this.chart2 == undefined) {
                  this.chart2 = echarts.init(this.$refs.chart2);
                }
                console.log(dateListTemp);
                console.log(fumeExceedingTemp)
                let temp = fumeExceedingTemp.map((item) => {
                        if (item >= 1) {
                          return {
                            value: item,
                            itemStyle: {
                              color: 'red'
                            }
                          };
                        }
                        return item;
                      })
                console.log(temp);
                this.chart2.setOption({
                  tooltip: {},
                  toolbox: {
                    // 工具栏
                    feature: {
                      dataZoom: {
                        // 区域缩放
                        yAxisIndex: 'none'
                      },
                      label: {
                        show: true,
                        position: 'end',
                        formatter: '{b}'
                      }
                      // 保存为图片
                      saveAsImage: {}
                    }
                  },
                  data: [
                    {
                      name: '预警',
                      type: 'average',
                      yAxis: 1,
                      lineStyle: {
                        // color: '#ff0000'
                  xAxis: {
                    data: dateListTemp,
                    name: '时间'
                  },
                  yAxis: {
                    type: 'value',
                    axisLabel: {
                      show: true,
                      interval: 'auto'
                      // formatter:'{value} %'
                    },
                    name: 'mg/m³'
                  },
                  visualMap: {
                    show: false,
                    dimension: 0,
                    pieces: [
                      {
                        lte: startIndex,
                        color: 'green'
                      },
                      {
                        gt: startIndex,
                        lte: endIndex,
                        color: 'red'
                      },
                      {
                        gt: endIndex,
                        lte: dateList1.length - 1,
                        color: 'green'
                      }
                    ]
                  },
                  series: [
                    {
                      name: '油烟浓度',
                      type: 'line',
                      data: temp,
                      markArea: {
                        itemStyle: {
                          color: 'rgba(255, 173, 177, 0.4)'
                        },
                        data: [
                          [
                            {
                              name: '超标时间段',
                              xAxis: beginT
                            },
                            {
                              xAxis: endT
                            }
                          ]
                        ]
                      },
                      markLine: {
                        symbol: 'none',
                        itemStyle: {
                          // 基线公共样式
                          normal: {
                            lineStyle: {
                              type: 'dashed'
                            },
                            label: {
                              show: true,
                              position: 'end',
                              formatter: '{b}'
                            }
                          }
                        },
                        data: [
                          {
                            name: '超标',
                            type: 'average',
                            yAxis: 1,
                            lineStyle: {
                              // color: '#ff0000'
                              color: 'red'
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
                });
              });
          });
        }, 500);
      }
    },
    getDeviceInfo() {
@@ -1341,32 +1566,32 @@
    },
    // 查询全部异常表数据
    getAllData() {
      this.isNoData = false;
      this.loading = true;
      axiosInstanceInstance.get('/fume/abnormal').then((result) => {
        this.abnormalData = result.data.data;
        this.loading = false;
        this.total = this.abnormalData.length;
        if (result.data.data.length == 0) {
          alert('该时段无数据');
          this.isNoData = true;
          return;
        }
        this.isNoData = false;
        // 默认显示第一页
        this.handleCurrentChange(1);
      });
    // getAllData() {
    //   this.isNoData = false;
    //   this.loading = true;
    //   axiosInstanceInstance.get('/fume/abnormal').then((result) => {
    //     this.abnormalData = result.data.data;
    //     this.loading = false;
    //     this.total = this.abnormalData.length;
    //     if (result.data.data.length == 0) {
    //       ElMessage('该时段无数据')
    //       this.isNoData = true;
    //       return;
    //     }
    //     this.isNoData = false;
    //     // 默认显示第一页
    //     this.handleCurrentChange(1);
    //   });
      // 得到异常表的最早和最晚时间
      setTimeout(() => {
        axiosInstanceInstance.get('/fume/time').then((result) => {
          this.beginTime = result.data.data[0].beginTime;
          this.endTime = result.data.data[0].endTime;
          // console.log('be,end',this.beginTime,this.endTime);
        });
      }, 500);
    },
    //   // 得到异常表的最早和最晚时间
    //   setTimeout(() => {
    //     axiosInstanceInstance.get('/fume/time').then((result) => {
    //       this.beginTime = result.data.data[0].beginTime;
    //       this.endTime = result.data.data[0].endTime;
    //       // console.log('be,end',this.beginTime,this.endTime);
    //     });
    //   }, 500);
    // },
    getAbnormalDataByClick(val) {
      this.abnormalData = val;
@@ -1414,7 +1639,7 @@
          this.exception2 = result.data.data;
        });
    },
    // 页面加载时默认展示7天异常表数据
    getRecentSevenDays() {
      // 给级联选择器设置默认的选择项
@@ -1435,7 +1660,7 @@
        .get('/fume/abnormalone', { params: params })
        .then((response) => {
          if (response.data.data.length == 0) {
            alert('该时段无数据');
            ElMessage('该时段无数据');
            return;
          }
          // 保存返回的
@@ -1447,17 +1672,15 @@
          this.loading = false;
        });
    }
  },
  }
};
</script>
<style scoped>
.exception-root-container {
  margin: 20px;
  padding: 10px;
  border: 1px;
  border: 1px;
  height: 615px;
  /* min-height: 80vh;
  min-width: 100vh; */
@@ -1515,6 +1738,7 @@
  color: var(--el-color-primary);
}
.collapse-header {
  margin-left: 5px;
  font-size: 18px;
}
.collapse-header-text {
@@ -1527,11 +1751,10 @@
.box-card-label {
  font-size: 14px;
  white-space: nowrap;
  overflow-x: auto;
  /* overflow-x: auto; */
}
:deep().el-card {
  border-radius: 9px;
}
/* ‘查看详情’ 的弹出框高度调整 */
:deep().el-dialog {
@@ -1541,14 +1764,14 @@
  border-radius: 9px;
}
:deep().table-page .el-card__body {
  padding: 0px;
  /* padding: 0px; */
}
.table-text {
  font-size: 18px;
  margin-bottom: 10px;
  margin: 5px 0px 10px 4px;
}
.text-blank {
  margin-left: 10px;
  margin-right: 10px;
}
/* 店铺名选择文本 */
.describe-info {
@@ -1563,7 +1786,6 @@
  font-weight: bold;
}
/* 异常表格下标签中的数组 */
.table-line-num {
  font-weight: bold;
@@ -1572,22 +1794,21 @@
.button_info.el-button_inner {
  text-align: left;
}
:deep().el-collapse .el-collapse-item__content{
:deep().el-collapse .el-collapse-item__content {
  padding-bottom: 0px;
}
.box-card {
  height: 190px;
}
:deep().box-card .el-card__body {
  padding: 5px;
  /* padding: 5px; */
}
.sub-box-card {
  height: 100px;
  overflow-y: auto;
  border: 0px;
}
:deep().sub-box-card .el-card__body {
  padding: 0px;
  /* padding: 0px; */
}
.mx-1 {
  margin-bottom: 0px;