zmc
2023-10-12 f3acb8ce787f3df0eda633031473be4e6a9ff448
src/test/TestDrawer.vue
@@ -5,27 +5,24 @@
    <div ref="h1" class="header-container">
      <span class="describe-info">店铺名选择:</span>
      <!-- 店铺名  级联 -->
      <ShopNameAndID
        @submit-id="(n) => (deviceId[1] = n)"
      ></ShopNameAndID>
        <ShopNameAndID @submit-id="(n) => (deviceId[1] = n)"></ShopNameAndID>
      <!-- 异常类型选择 -->
      <ExceptionType @submitExceptionType="(val) => (exceptionValue = val)">
      </ExceptionType>
      <TimeSelect @submit-time="giveTime"></TimeSelect>
      <!-- </div> -->
    </div>
    <div
      ref="h2"
      style="display: flex; margin-top: 2px; justify-content: right"
    >
      <el-button
        type="primary"
        plain
        @click="showTable"
        style="margin-left: 20px"
          :loading="button.queryButton"
        >查询</el-button
      >
@@ -247,10 +244,9 @@
        </el-card>
      </el-collapse-item>
    </el-collapse>
    <!-- <hr/>
 <br> -->
    <h4 class="table-text">异常数据</h4>
    <!--  -->
  </el-col>
</el-row>
    <el-card class="table-page" v-show="!isNoData">
@@ -259,11 +255,12 @@
        v-loading="loading"
        :data="displayData"
        style="width: 100%"
        stripe
        border
        :height="tableHeight"
      :cell-class-name="tableCellClassName"
      >
        <el-table-column fixed prop="diName" label="店铺名称" >
      <el-table-column prop="diName" label="店铺名称">
          <template #default="{ row }">
            <el-tooltip effect="dark" :content="row.diName">
              <div class="cell ellipsis">{{ row.diName }}</div>
@@ -317,7 +314,10 @@
        </el-table-column>
        <el-table-column label="操作" >
          <template #default="{ row }">
            <el-button type="warning" @click="showDrawer(row)"
          <el-button
            type="primary"
            class="table-button"
            @click="showDrawer(row)"
              >查看详情</el-button
            >
          </template>
@@ -353,13 +353,15 @@
          <div class="dialog-button-position">
            <el-button
              type="danger"
              :disabled="isPreCantouch"
            :loading="button.preButton"
            :disabled="isPreCantouch || banTouch"
              @click="getPreviousRowData"
              >上条异常</el-button
            >
            <el-button
              type="danger"
              :disabled="isNextCantouch"
            :loading="button.afterButton"
            :disabled="isNextCantouch || banTouch"
              @click="getNextRowData"
              >下条异常</el-button
            >
@@ -370,20 +372,23 @@
        <!-- 折线图 -->
        <!-- 掉线 -->
        <!-- <div
          ref="ref"
          v-show="isOfflineShow"
      <div
          ref="lineChart"
          class="line-chart"
          style="
            width: 100%;
            height: 300px;
            /* min-width: 100px; */
            margin-bottom: 20px;
            margin-left: 10px;
            min-width: 350px;
            /* margin-left: 10px;
            min-width: 350px; */
          "
        ></div> -->
        ></div>
        <ExceptionTypeLineChart :option="option" :is-open-dialog="centerDialogVisible" ></ExceptionTypeLineChart>
      <!-- <ExceptionTypeLineChart
        :option="option"
        :is-open-dialog="centerDialogVisible"
        v-loading="chartLoading"
      ></ExceptionTypeLineChart> -->
        <!--  -->
        <div style="margin-top: 40px; margin-bottom: 5px; border: 1px">
@@ -405,8 +410,12 @@
        </div>
        <el-tag type="success" class="mx-1" effect="dark" round
          ><span class="table-line-lable" v-show="rowExceptionType == '0'">异常记录: </span>
          <span v-show="rowExceptionType == '1' || rowExceptionType == '2'">缺失数据:</span>
        ><span class="table-line-lable" v-show="rowExceptionType == '0'"
          >异常记录:
        </span>
        <span v-show="rowExceptionType == '1' || rowExceptionType == '2'"
          >缺失数据:</span
        >
          <span class="table-line-num">{{ exceptionTotal }}条</span>
          <span v-show="rowExceptionType === '1' || rowExceptionType === '2'">
            (逻辑计算)</span
@@ -420,10 +429,10 @@
import ExceptionType from '../sfc/ExceptionType.vue';
import TimeSelect from '../sfc/TimeSelect.vue';
import ExceptionText from '../sfc/ExceptionText.vue';
import * as echarts from 'echarts';
import * as XLSX from 'xlsx/xlsx.mjs';
import dayjs from 'dayjs';
import axiosInstanceInstance from '../utils/request.js';
import * as echarts from 'echarts';
const ShopNameAndID = defineAsyncComponent(() =>
  import('../sfc/../sfc/ShopNameAndID.vue')
@@ -440,10 +449,23 @@
    TimeSelect,
    ShopNameAndID,
    ExceptionText,
    ExceptionTypeLineChart
    // ExceptionTypeLineChart
  },
  data() {
    return {
      chart: null,
      // 折线图加载中
      chartLoading:false,
      button:{
        // 查询按钮
        queryButton:false,
        // 上一条按钮
        preButton:false,
        // 下一条按钮
        afterButton:false,
        //
        banTouch:0
      },
      // 异常折线图的配置
      option: {},
      // 折线图展示
@@ -553,7 +575,7 @@
      // 店铺名 级联选择器
      optionsShop: [],
      // 异常类型选择器
      exceptionValue: [],
      exceptionValue: []
    };
  },
  // 监听  判断按钮是否可点击
@@ -590,6 +612,8 @@
      this.getShopNames();
    },
    centerDialogVisible() {
      // this.initChart();
      // this.chart.clear
      window.addEventListener('resize', this.updateChart);
    }
  },
@@ -601,19 +625,88 @@
    this.getRecentSevenDays();
    // 根据异常类型返回店铺名称和设备编号 渲染异常分析部分对应的店铺名
    this.getShopNames();
    this.calcTableHeight()
    window.addEventListener('resize', this.updateChart);
    this.calcTableHeight();
 
    window.addEventListener('resize', this.updateChart);
  },
  beforeUnmount() {
    if (this.chart) {
      this.chart.dispose;
    }
  },
  methods: {
     // 动态计算表格高度
    calDialogWidth(){
    },
    // 功能:初始化折线图
    initChart() {
      // 创建echarts实例
      this.chart = echarts.init(this.$refs.lineChart);
      // 定义图表的配置项和数据
      const option = {
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        tooltip: {},
        toolbox: {
          // 工具栏
          feature: {
            // dataZoom: {
            //   // 区域缩放
            //   yAxisIndex: 'none'
            // },
            // 保存为图片
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'time',
          data: [],
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            name: '油烟浓度',
            type: 'line',
            data: []
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表
      this.chart.setOption(option, true);
    },
    // 功能:跟页面响应式变化
    resizeChart() {
      this.chart.resize();
    },
    // 功能:改变表格某个单元格的颜色
    tableCellClassName({ row, column, rowIndex, columnIndex }) {
     if(columnIndex == 3){
        if (row.exceptionType == '0') {
          return 'exceeding-row';
        } else if (row.exceptionType == '1') {
          return 'abnormal-power-supply';
        } else if (row.exceptionType == '2') {
          return 'disconnect';
        }
     }
    },
    //功能: 动态计算表格高度
     calcTableHeight(){
      const h1 = this.$refs.h1.$el.offsetHeight;
      const h2 = this.$refs.h4.$el.offsetHeight;
      this.tableHeight =  `calc(100vh - ${h1}px - ${h2}px - 45px - var(--el-main-padding) * 2 - var(--el-card-padding))`;
    },
    
    // 时间是否超过10分钟
    //功能: 时间是否超过10分钟
    isTimeDifferenceGreaterThan10Minutes(dateString1, dateString2) {
      const date1 = new Date(dateString1);
      const date2 = new Date(dateString2);
@@ -639,7 +732,6 @@
          let current = timePoints[i];
          let next = timePoints[i + 1];
          while (this.isTimeDifferenceGreaterThan10Minutes(current, next)) {
            console.log('generateTimePoints');
            current = dayjs(current)
              .add(10, 'minute')
              .format('YYYY-MM-DD HH:mm:ss');
@@ -668,7 +760,6 @@
      const year2 = date2.getFullYear();
      const month2 = date2.getMonth();
      const day2 = date2.getDate();
      console.log(month1, month2);
      // 判断两个日期是否相差一个月
      if (year1 === year2) {
@@ -698,16 +789,14 @@
    // 刚打开卡片时第一个图形不会自动伸缩 当点击上/下一条时会自动伸缩
    // 图形响应式变化
    // updateChart() {
    //   this.$nextTick(() => {
    //     if (this.chart1) {
    //       this.chart1.resize();
    //     }
    //     if (this.chart2) {
    //       this.chart2.resize();
    //     }
    //   });
    // },
    updateChart() {
      this.$nextTick(() => {
        if (this.chart) {
          this.chart.resize();
        }
      });
    },
    // 从时间选择器组件拿到开始和结束时间
    giveTime(val) {
      //将中国标准时间转为指定格式(该组件返回的标准时间的格式,所以必须的加这个函数)
@@ -720,8 +809,8 @@
    descTenTime(begin, end) {
      let time = [];
      if(begin == end){
        time.push(begin)
        return time
        time.push(begin);
        return time;
      }
      // 保留结果 00 10 20 30
      let temp = dayjs(begin).add(10, 'minute').format('YYYY-MM-DD HH:mm:ss');
@@ -749,9 +838,9 @@
        const abnormalTimeTenMinute = this.descTenTime(
        this.rowBeginTime,
        this.rowEndTime
      )
      );
      // 去除供电异常和掉线区间的第一个有元素的值
      this.exceedingData = []
      this.exceedingData = [];
      for (let i = 0; i < abnormalTimeTenMinute.length; i++) {
        this.exceedingData.push({
@@ -777,6 +866,9 @@
    getNextRowData() {
      // 不是表格的第一行 
      if (this.selectedRowIndex !== 0) {
        // 点击过程中 锁住上下条按钮  在设置完图形配置项后解锁
        this.banTouch = 1
        //得到上一行数据索引
        this.selectedRowIndex = this.selectedRowIndex - 1;
        //请求数据 改变exceedingData
@@ -792,32 +884,29 @@
        if (this.drawerData.endTime) {
          params['endTime'] = this.displayData[this.selectedRowIndex].endTime;
        }
        this.button.afterButton = true
        axiosInstanceInstance
          .get('/fume/exceed', { params: params })
          .then((response) => {
            // 保存返回的超标数据
            this.exceedingData = response.data.data;
            // this.chart = null;
            // this.drawChart();
            this.drawChartTest();
            this.exceptionTotal = this.exceedingData.length;
            this.button.afterButton = false
          });
      }
      //表格的第一行,则上一条无数据
      else{
        console.log(null);
      }
    },
    // 获取获取表格下一行数据
    getPreviousRowData() {
      // 不是表格的第一行  
      if (this.selectedRowIndex < this.displayData.length - 1) {
        //得到上一行数据索引
        // 点击过程中 锁住上下条按钮  在设置完图形配置项后解锁
        this.banTouch = 1
        
        //得到上一行数据索引
        this.selectedRowIndex = this.selectedRowIndex + 1;
        console.log('上', this.selectedRowIndex);
        //请求数据 改变exceedingData
        this.setinfo(this.selectedRowIndex);
@@ -832,19 +921,16 @@
        if (this.drawerData.endTime) {
          params['endTime'] = this.displayData[this.selectedRowIndex].endTime;
        }
        this.button.preButton = true
        axiosInstanceInstance
          .get('/fume/exceed', { params: params })
          .then((response) => {
            // 保存返回的超标数据
            this.exceedingData = response.data.data;
            console.log(this.exceedingData);
            this.drawChartTest();
            this.exceptionTotal = this.exceedingData.length;
            this.button.preButton = false
          });
      }
      //表格的第一行,则上一条无数据
      else {
        console.log(null);
      }
    },
@@ -860,6 +946,10 @@
      this.centerDialogVisible = true;
      // 初始化折线图
      this.initChart();
      // this.chart.clear
      // 根据行数据请求详细超标数据渲染折线图
      let params = {};
      if (this.drawerData.devId) {
@@ -871,6 +961,7 @@
      if (this.drawerData.endTime) {
        params['endTime'] = this.drawerData.endTime;
      }
      axiosInstanceInstance
        .get('/fume/exceed', { params: params })
        .then((response) => {
@@ -895,8 +986,7 @@
      if (this.exceptionValue.length != 0) {
        params['exceptionValue'] = this.exceptionValue.join();
      }
      console.log('原', this.exceptionValue);
      console.log('处理', this.exceptionValue.join());
      if (this.beginTime) {
        params['beginTime'] = this.beginTime;
      }
@@ -904,12 +994,15 @@
        params['endTime'] = this.endTime;
      }
      this.loading = true;
      this.button.queryButton = true
      axiosInstanceInstance
        .get('/fume/abnormalthree', { params: params })
        .then((response) => {
          this.abnormalData = response.data.data;
          this.total = this.abnormalData.length;
          this.loading = false;
          this.button.queryButton = false
          if (response.data.data.length == 0) {
            ElMessage('该时段无数据');
            this.isNoData = true;
@@ -918,8 +1011,7 @@
          // 移除空数据状态
          this.isNoData = false;
          this.handleCurrentChange(1);
          console.log('返回的数据', this.abnormalData);
          console.log('长度', response.data.data.total);
        });
    },
    handleSizeChange(val) {
@@ -943,7 +1035,6 @@
      // 计算结束时间减去开始时间中间相差多少个十分钟
      const diffInMinutes = end.diff(start, 'minute');
      const diffInTenMinutes = Math.floor(diffInMinutes / 10);
      console.log('几个10分钟', diffInTenMinutes);
      return diffInTenMinutes;
    },
@@ -1023,7 +1114,7 @@
    findTimeInExceptionData(data, time) {
      for (let i = 0; i < data.length; i++) {
        if(data[i]==null){
            continue
          continue;
        }
        if (data[i]['mvDataTime'] == time) {
          return data[i]['mvFumeConcentration2'];
@@ -1060,7 +1151,6 @@
        current = dayjs(current)
          .add(10, 'minute')
          .format('YYYY-MM-DD HH:mm:ss');
      }
      obj['xAxis'] = xAxis;
      obj['yAxis'] = yAxis;
@@ -1072,16 +1162,14 @@
    removeLastItemOfBeforeData(beforeDataOfExceeding){
      let tempList = [];
      if(beforeDataOfExceeding.length ==1){
        return tempList
        return tempList;
      }else{
        for(let i=0;i<beforeDataOfExceeding.length-1;i++){
        tempList.push({ ...beforeDataOfExceeding[i]})
          tempList.push({ ...beforeDataOfExceeding[i] });
      }
      return tempList;
      }
    },
    // 设置option
    // 参数:x轴时间, y轴油烟浓度, 异常类别(0代表超标,1代表供电异常和掉线), 异常开始时间,异常结束时间,异常开始时间在整个区间的索引下标,异常结束时间在整个区间的索引下标
@@ -1094,10 +1182,10 @@
      beginIndex,
      endIndex
    ) {
      this.option = {}
      this.option = {};
      // 超标
      if (exceptionCategory == 0) {
        this.option = {
        this.chart.setOption({
          tooltip: {},
        toolbox: {
          // 工具栏
@@ -1121,7 +1209,7 @@
          },
          yAxis: {
            type: 'value',
            name: 'mg/m³',
            name: 'mg/m³'
          },
          series: [
            {
@@ -1147,10 +1235,10 @@
                  [
                    {
                      name: '超标时间段',
                      xAxis: exceptionBeginTime,
                      xAxis: exceptionBeginTime
                    },
                    {
                      xAxis: exceptionEndTime,
                      xAxis: exceptionEndTime
                    }
                  ]
                ]
@@ -1205,11 +1293,11 @@
              }
            ]
          }
        };
        });
      }
      // 供电异常和掉线
      else if (exceptionCategory == 1) {
        this.option = {
        this.chart.setOption( {
          tooltip: {},
        toolbox: {
          // 工具栏
@@ -1259,19 +1347,19 @@
              }
            }
          ]
        };
        });
      }
      this.banTouch = 0
    },
    // 功能:点击 ‘查看详情’, ‘下一条’按钮时会 先逻辑计算。最后展示图形
    drawChartTest() {
      this.beforeData = []
      this.afterData= []
      this.allExceptionTimeData = []
      this.beforeData = [];
      this.afterData = [];
      this.allExceptionTimeData = [];
      //异常的开始时间 结束时间
      let exceptionBeginTime =this.rowBeginTime
      let exceptionEndTime = this.rowEndTime
      let exceptionBeginTime = this.rowBeginTime;
      let exceptionEndTime = this.rowEndTime;
      // beforeAndAfterTime[0]:前30分钟的时间点
      // beforeAndAfterTime[1]:后10分钟的时间点
@@ -1295,18 +1383,18 @@
        beforeAndAfterTime[2]
      );
      // 折线图加载中效果
      this.chartLoading = true
      // 请求前半段
      axiosInstanceInstance
        .get('/fume/history', { params: paramsBefore })
        .then((result1) => {
          this.beforeData = result1.data.data;
          console.log('beforeData:',this.beforeData);
          // 请求后半段
          axiosInstanceInstance
            .get('/fume/history', { params: paramsAfter })
            .then((result2) => {
              this.afterData = result2.data.data;
              console.log('afterData:',this.afterData);
              //保存异常区间的值
              let tempArr = [];
              // 保存异常区间前后的值
@@ -1334,11 +1422,12 @@
                after = this.shallowCopyList(this.afterData);
                // after = this.afterData
                console.log('after:',after);
              } 
              // 超标
              else {
                let beforeTemp = this.removeLastItemOfBeforeData(this.beforeData)
                let beforeTemp = this.removeLastItemOfBeforeData(
                  this.beforeData
                );
                // 前后区间只显示距离超标区间时间最近的浓度小于1的时间点
                for (let i = beforeTemp.length - 1; i >= 0; i--) {
                  if (beforeTemp[i].mvFumeConcentration2 >= 1) {
@@ -1362,7 +1451,6 @@
              // 将前后区间数据 与 异常区间数据 合并
              this.allExceptionTimeData = [...before, ...tempArr, ...after];
              console.log('组合数据:',this.allExceptionTimeData);
              // x轴日期时间
              let dateList = [];
              // y轴 超标油烟浓度
@@ -1378,9 +1466,6 @@
              dateList = timeAndValue['xAxis'];
              fumeExceeding = timeAndValue['yAxis'];
              console.log('dateList:',dateList);
              console.log('fumeExceeding:',fumeExceeding);
              // 提取异常起始时间点在整个区间内的数据索引
              let startIndex = dateList.findIndex(
@@ -1416,6 +1501,7 @@
                  endIndex
                );
              }
              this.chartLoading = false
            });
        });
    },
@@ -1438,7 +1524,6 @@
            ]
          };
        });
        console.log(this.optionsShop);
      });
    },
    exportDom() {
@@ -1492,8 +1577,6 @@
        })
        .then((result) => {
          this.exception0 = result.data.data;
          console.log('异常0', this.exception0);
          console.log('异常0数量', this.exception0.length);
        });
      axiosInstanceInstance
        .get('/fume/shopname', {
@@ -1523,7 +1606,6 @@
    getRecentSevenDays() {
      // 给级联选择器设置默认的选择项
      this.devId = ['付小姐在成都', 'qinshi_31010320210010'];
      console.log(this.currentDateTime, this.oneWeekAgoDateTime);
      let params = {};
      params['beginTime'] = this.beginTime;
      params['endTime'] = this.endTime;
@@ -1548,13 +1630,7 @@
</script>
<style scoped>
/* .exception-root-container {
  margin: 20px;
  padding: 10px;
  border: 1px;
  height: 615px;
} */
.header-container {
  display: flex;
  margin-left: 20px;
@@ -1590,8 +1666,6 @@
/* 异常分析数据与按钮 */
.exception-container {
  display: flex;
  /* direction: column; */
  /* flex-grow: 2,1; */
}
.example-showcase .el-loading-mask {
  z-index: 9;
@@ -1613,7 +1687,6 @@
  font-size: 18px;
}
.collapse-header-text {
  /* margin-right: 150px; */
  margin-top: 5px;
  font-size: 14px;
  color: gray;
@@ -1622,7 +1695,6 @@
.box-card-label {
  font-size: 14px;
  white-space: nowrap;
  /* overflow-x: auto; */
}
:deep().el-card {
  border-radius: 9px;
@@ -1637,15 +1709,14 @@
.table-page {
  margin-left: 20px;
}
:deep().table-page .el-card__body {
  /* padding: 0px; */
}
.table-text {
  font-size: 18px;
  margin: 5px 0px 10px 20px;
}
.text-blank {
  margin-right: 10px;
  color: #000000;
}
/* 店铺名选择文本 */
.describe-info {
@@ -1677,16 +1748,12 @@
.box-card {
  height: 190px;
}
:deep().box-card .el-card__body {
  /* padding: 5px; */
}
.sub-box-card {
  height: 100px;
  border: 0px;
}
:deep().sub-box-card .el-card__body {
  /* padding: 0px; */
}
.mx-1 {
  margin-bottom: 0px;
}
@@ -1695,10 +1762,31 @@
  justify-content: right;
  margin-bottom: 10px;
}
.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-light-9);
:deep().el-table__row .exceeding-row{
  background-color:  #F53F3F;
}
.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-light-9);
:deep().el-table__row .abnormal-power-supply{
  background-color:  #FDF4BF;
}
:deep().el-table__row .disconnect{
  background-color:  #F7BA1E;
}
.el-table {
  color: #000000;
}
/* 表格的内边距 */
:deep().el-table .el-table__cell {
  padding: 2px;
}
/* 表格中的按钮宽度铺满 */
.table-button {
  width: 100%;
}
</style>