guoshipeng
2022-11-07 13906d0efa0d3411ee5cd4f01d086a56632ee74d
src/views/car/index.vue
@@ -1,23 +1,29 @@
<template>
  <div class="main_body">
    <el-container
      style="height: 100%"
        style="height: 100%"
    >
      <el-aside
        v-if="this.$store.state.aside"
        width="300px"
        style="background-color: rgb(238, 241, 246);padding-top:10px"
          v-if="this.$store.state.aside"
          width="300px"
          style="background-color: rgb(238, 241, 246);padding-top:10px"
      >
        <span style="font-size:13px;padding-left:10px;font-weight:500;color:rgb(64, 158, 255)">走航车设备</span>
        <el-menu style="margin-top:10px">
          <el-menu-item
            v-for="(item,index) in defaultData"
            :key="index"
            style="display: flex;justify-content: space-between;align-items: center;padding-right: 0;border-bottom:1px solid #eee"
            :index="(index+1 + '-' + index + 1).toString()"
            @click="changeCarData(item)"
              v-for="(item,index) in defaultData"
              :key="index"
              style="display: flex;justify-content: space-between;align-items: center;padding-right: 0;border-bottom:1px solid #eee"
              :index="(index+1 + '-' + index + 1).toString()"
              @click="changeCarData(item)"
          >
            <span>{{ item.name }}</span>
            <i
                style="vertical-align: -2.5px;font-size: 20px;margin-right:10px;margin-left:auto"
                class="iconfont iconfaxianzuobiao"
                @click="deviceDetail(item.mac,null,item,0)"
            />
            <!--            @click="deviceDetail('p5dnd7a0245390',null,item,0)"-->
          </el-menu-item>
        </el-menu>
      </el-aside>
@@ -27,64 +33,74 @@
            <el-button size="medium" type="primary" icon="el-icon-setting" @click="dialogFormVisible = true">6参设定</el-button>
          </span>
          <span
            v-for="(item, index) in snesorParams"
            :key="index"
            class="left"
            :class="{ click: changeColor == index }"
            @click="changeCode(index)"
              v-for="(item, index) in snesorParams"
              :key="index"
              class="left"
              :class="{ click: changeColor == index }"
              @click="changeCode(index)"
          >{{ item }}
          </span>
          <span
            v-for="(item,index) in viewOptions"
            :key="index+ '-only'"
            class="right"
            :class="{ click: changeColor1 == index }"
            @click="changeCode1(index)"
              v-for="(item,index) in viewOptions"
              :key="index+ '-only'"
              class="right"
              :class="{ click: changeColor1 == index }"
              @click="changeCode1(index)"
          >{{ item }}
          </span>
          <span v-if="webSocketView" style="float:right;margin: 2px 10px 0 0;">
            <el-button size="medium" type="primary" @click="wsStart()">开启实时</el-button>
          </span>
<!--           <el-date-picker
            v-if="historyView"
            v-model="dateValue"
            value-format="yyyy-MM-dd"
            style="float:right;margin-right: 10px;line-height: 40px;"
            align="right"
            type="date"
            placeholder="选择日期"
            :picker-options="pickerOptions"
            @change="dateChange"
          />-->
          <!--           <el-date-picker
                      v-if="historyView"
                      v-model="dateValue"
                      value-format="yyyy-MM-dd"
                      style="float:right;margin-right: 10px;line-height: 40px;"
                      align="right"
                      type="date"
                      placeholder="选择日期"
                      :picker-options="pickerOptions"
                      @change="dateChange"
                    />-->
          <!-- 选择时间段 -->
          <el-time-picker
              :disabled="isDisTime"
              style="float:right;width: 210px"
              is-range
              v-model="timeValue"
              @blur="blurChange"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围">
          </el-time-picker>
          <!--          <el-time-picker-->
          <!--              :disabled="isDisTime"-->
          <!--              style="float:right;width: 210px"-->
          <!--              is-range-->
          <!--              v-model="timeValue"-->
          <!--              @blur="blurChange"-->
          <!--              range-separator="至"-->
          <!--              start-placeholder="开始时间"-->
          <!--              end-placeholder="结束时间"-->
          <!--              placeholder="选择时间范围">-->
          <!--          </el-time-picker>-->
          <!-- 历史日期选择下拉框 -->
          <el-select v-if="historyView" v-model="dateValue" placeholder="选择日期" style="float:right;line-height:40px;margin-right:10px;width:140px" @change="dateChange">
            <el-option
              v-for="item in isDataList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              @click.native="dataChangeClick"
            />
          </el-select>
          <!--          <el-select v-if="historyView" v-model="dateValue" placeholder="选择日期" style="float:right;line-height:40px;margin-right:10px;width:140px" @change="dateChange">-->
          <!--            <el-option-->
          <!--              v-for="item in isDataList"-->
          <!--              :key="item.value"-->
          <!--              :label="item.label"-->
          <!--              :value="item.value"-->
          <!--              @click.native="dataChangeClick"-->
          <!--            />-->
          <!--          </el-select>-->
          <el-date-picker
              style="float:right;margin-right:10px;"
              @change="dateChange"
              v-model="dateValue"
              type="datetimerange"
              :picker-options="threeOptions"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
          </el-date-picker>
          <!-- 历史/实时切换下拉框 -->
          <el-select v-model="dataTypeValue" placeholder="数据类型" style="float:right;line-height:40px;margin-right:10px;width:103px">
            <el-option
              v-for="item in dataTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
                v-for="item in dataTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
          </el-select>
        </div>
@@ -116,17 +132,17 @@
      <!-- <el-descriptions title="设备标准值"  border>
      </el-descriptions> -->
      <div
        style="font-size: 16px;font-weight: 700;margin:10px 0 20px 0;font-size: 16px;
          style="font-size: 16px;font-weight: 700;margin:10px 0 20px 0;font-size: 16px;
    font-weight: 700;color: #303133;"
      >设备标准值</div>
      <el-table :data="sensorTableData" border>
        <el-table-column
          prop="sensorName"
          label="名称"
            prop="sensorName"
            label="名称"
        />
        <el-table-column
          prop="unit"
          label="单位"
            prop="unit"
            label="单位"
        />
        <el-table-column label="一级">
          <template slot-scope="scope">
@@ -169,6 +185,8 @@
</template>
<script>
import $ from 'jquery'
import '@/assets/icon/iconfont.css'
import requestObj from '@/utils/request'
var GPS = {
  PI: 3.14159265358979324,
  x_pi: 3.14159265358979324 * 3000.0 / 180.0,
@@ -316,7 +334,7 @@
        '平铺',
        '立体'
      ],
      dateValue: null,
      dateValue: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
@@ -342,6 +360,25 @@
          }
        }]
      },
      timeOne: '',
      threeOptions: {
        onPick: ({ maxDate, minDate }) => {
          // 最大时间 最小时间
          this.timeOne = minDate.getTime() // 当选一个日期时 就是最小日期
          // 如何你选择了两个日期了,就把那个变量置空
          if (maxDate) this.timeOne = ''
        },
        disabledDate: time => {
          if (this.timeOne) {
            const WEEK = 3 * 24 * 3600 * 1000 - 1 // 这里乘以3再减去1相当于 限制3天以内
            const minTime = this.timeOne// 三天之前
            const maxTime = this.timeOne + WEEK // 三天之后
            return time.getTime() < minTime || time.getTime() > maxTime || time.getTime() > new Date()
          } else {
            return time.getTime() > new Date()
          }
        }
      },
      sensorDate: null,
      noneData: false,
      defaultData: [],
@@ -355,7 +392,7 @@
        { sensorName: 'CO', unit: 'mg/m³', tab1: '2', tab2: '4', tab3: '14', tab4: '24', tab5: '36', tab6: '48' },
        { sensorName: 'O3', unit: 'ug/m³', tab1: '100', tab2: '160', tab3: '215', tab4: '265', tab5: '800', tab6: '800' },
        { sensorName: 'TVOC', unit: 'mg/m³', tab1: '0.1', tab2: '0.3', tab3: '0.5', tab4: '0.7', tab5: '0.9', tab6: '1' },
        { sensorName: '尘负荷', unit: 'ug/m³', tab1: '0.05', tab2: '0.1', tab3: '0.3', tab4: '0.5', tab5: '0.9', tab6: '1' }
        { sensorName: '尘负荷', unit: 'ug/m³', tab1: '300', tab2: '500', tab3: '1000', tab4: '10000', tab5: '20000', tab6: '50000' }
      ],
      carWs: null,
      map: null,
@@ -397,21 +434,27 @@
  watch: {
    dataTypeValue(n, o) {
      if (this.dataTypeValue === 'webSocket') {
        this.dateValue = null
        this.dateValue = []
        this.historyView = false
        this.webSocketView = true
      } else {
        this.dateValue = null
        this.dateValue = []
        this.historyView = true
        this.webSocketView = false
      }
    },
    dateValue(n, o) {
      if (n === null) {
        this.dateValue = []
      }
    },
    viewKey(n, o) {
      // console.log(n)
    }
    },
    deep: true,
    immediate: true
    // timeValue: {
    //   handler(newVal, oldVal) {
    //     console.log('时间是', this.timeValue, '日期是', this.sensorDate)
    //     this.sensorTime = this.newTime()
    //     console.log(this.sensorTime, 'this.sensorTime')
    //     // if (this.dataValue && this.timeValue) {
@@ -445,11 +488,59 @@
    this.newTime(this.timeValue)
    this.newDate()
    this.getCarData()
    this.$watch('carMac', () => {
      this.getMacDate()
    })
    // this.$watch('carMac', () => {
    //   this.getMacDate()
    // })
  },
  methods: {
    // 时间处理函数
    newTime2(timeArr) {
      var arr = []
      timeArr.map(v => {
        var date = new Date(v)
        var y = date.getFullYear()
        var m = date.getMonth() + 1
        m = m < 10 ? '0' + m : m
        var d = date.getDate()
        d = d < 10 ? '0' + d : d
        var h = date.getHours()
        h = h < 10 ? '0' + h : h
        var minute = date.getMinutes()
        minute = minute < 10 ? '0' + minute : minute
        var s = date.getSeconds()
        s = s < 10 ? '0' + s : s
        arr.push(y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + s)
      })
      return arr
    },
    // 跳转设备详情页
    deviceDetail(mac, item, items, indexs) {
      // console.log('这是传输过去的值')
      // console.log(mac)
      // console.log(item)
      // console.log(items)
      // console.log(indexs)
      // this.monitorPointInfo = item
      this.$router.push({
        name: 'deviceDetail',
        // path: '/carDetail',
        params: {
          monitorPointInfo: item,
          device: items,
          macName: mac,
          indexs: indexs,
          items: [items.latitude, items.longitude]
        },
        query: {
          monitorPointInfo: JSON.stringify(item),
          device: items,
          macName: mac,
          indexs: indexs,
          items: [items.latitude, items.longitude],
          equipment: 'car'
        }
      })
    },
    // 6参设定方法
    customLevel() {
      this.getStart()
@@ -465,14 +556,12 @@
      this.$request({
        url: '/cruiser/selectCruisers',
        method: 'get'
      }).then(res => {
        this.defaultData = res.data
        this.carMac = res.data[0].mac
      }).catch(err => {
        console.log(err)
      })
        .then(res => {
          this.defaultData = res.data
          this.carMac = res.data[0].mac
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 通过mac请求设备有数据的日期
    getMacDate() {
@@ -483,21 +572,19 @@
        params: {
          mac: this.carMac
        }
      }).then(res => {
        for (let i = 0; i < res.data.length; i++) {
          // this.isDataList[i].value = res.data.data[i]
          // this.isDataList[i].label = res.data.data[i]
          // this.isDataList[i] = { value: res.data.data[i], label: res.data.data[i] }
          this.isDataList.push({
            value: res.data[i],
            label: res.data[i]
          })
        }
      }).catch(err => {
        console.log(err)
      })
        .then(res => {
          for (let i = 0; i < res.data.length; i++) {
            // this.isDataList[i].value = res.data.data[i]
            // this.isDataList[i].label = res.data.data[i]
            // this.isDataList[i] = { value: res.data.data[i], label: res.data.data[i] }
            this.isDataList.push({
              value: res.data[i],
              label: res.data[i]
            })
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 进行经纬度转换为距离的计算
    Rad(d) {
@@ -510,7 +597,7 @@
      var a = radLat1 - radLat2
      var b = this.Rad(lng1) - this.Rad(lng2)
      var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
        Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
          Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
      s = s * 6378.137 // EARTH_RADIUS;
      s = Math.round(s * 10000) / 10000 // 输出为公里
      // s=s.toFixed(4);
@@ -538,21 +625,10 @@
    },
    // 数据类型
    dateChange(e) {
      this.sensorDate = e
      // if (this.view) {
      //   this.view.removeAllLayers()
      //   this.map.clearOverlays()
      //   // console.log('清除图层')
      // }
      // this.dataType = 'history'
      // // this.map = null
      // this.getStart()
    },
    // 日期选择点击事件
    dataChangeClick(e) {
      if (!this.isDisTime) {
        // 更改时间格式
        this.newTime(this.timeValue)
      if (e === null) {
        this.sensorDate = []
      } else {
        this.sensorDate = this.newTime2(e)
        if (this.view) {
          this.view.removeAllLayers()
          this.map.clearOverlays()
@@ -562,8 +638,25 @@
        // this.map = null
        this.getStart()
      }
      this.isDisTime = false
    },
    // 日期选择点击事件
    // dataChangeClick(e) {
    //   if (!this.isDisTime) {
    //     // 更改时间格式
    //     if (this.dateValue.length <= 1) {
    //       this.newTime(this.timeValue)
    //     }
    //     if (this.view) {
    //       this.view.removeAllLayers()
    //       this.map.clearOverlays()
    //       // console.log('清除图层')
    //     }
    //     this.dataType = 'history'
    //     // this.map = null
    //     this.getStart()
    //   }
    //   this.isDisTime = false
    // },
    // 时间选框失去焦点
    blurChange() {
      // 更改时间格式
@@ -591,6 +684,7 @@
      }
      that.dataType = 'webSocket'
      // 拼写URL
      // const baseUrl = `${requestObj.baseUrl}`
      var socketUrl = 'cruiserWebsocket/' + this.carMac
      // 替换http为WS
      socketUrl = socketUrl.replace('https', 'ws').replace('http', 'ws')
@@ -629,15 +723,14 @@
        this.view.removeAllLayers()
        this.map.clearOverlays()
      }
      var time1 = this.sensorDate + ' ' + this.sensorTime[0]
      var time2 = this.sensorDate + ' ' + this.sensorTime[1]
      this.$request({
        url: '/cruiser/cruiserTrajectory',
        method: 'get',
        params: {
          mac: this.carMac,
          time1,
          time2
          time1: this.sensorDate[0],
          time2: this.sensorDate[1]
        }
      }).then(res => {
        if (!res.data.length) {
@@ -682,16 +775,20 @@
            lat = GPS.gcj_encrypt(lat, lng).lat
            lng = GPS.bd_encrypt(lat, lng).lon
            lat = GPS.bd_encrypt(lat, lng).lat
            var point = new BMapGL.Point(lng, lat)
            var point = new BMapGL.Point(lng, lat);
            point.a34004 = parseInt(value.a34004)
            point.a34002 = parseInt(value.a34002)
            point.a21026 = parseInt(value.a21026)
            point.a21004 = parseInt(value.a21004)
            // point.a21005 = parseInt(value.a21005)
            point.a21005 = parseFloat(value.a21005).toFixed(3)
            point.a05024 = parseInt(value.a05024)
            point.a99054 = parseFloat(value.a99054).toFixed(3)
            point.dustld = value.dustld - 0
            if (value.dustld - 0 !== 0 && value.dustld - 0 < 100 && (that.carMac === 'p5dnd7a0243622' || that.carMac === 'p5dnd7a0243625')) {
              point.dustld = 100
            } else {
              point.dustld = value.dustld - 0
            }
            // point.dustld = value.dustld - 0
            trackPoints.push(point)
          }
        })
@@ -736,11 +833,11 @@
        }
      }
      // drawPolygon(sensor);//多边形
      draw(that.sensor, that.viewType)
      drawLine()// 轨迹
      draw(that.sensor, that.viewType, that.carMac)
      // drawLine()// 轨迹
      drawStartAndEnd()// 起点和终点标注
      function draw(sensor, type) {
        var levels = getGrading(sensor, type)
      function draw(sensor, type, carMac) {
        var levels = getGrading(sensor, type, carMac)
        $.each(levels, function(index, value) {
          var color = value.color
          var data = value.data
@@ -805,7 +902,7 @@
        var points = []
        $.each(trackPoints, function(index, value) {
          var point = []
          point.push(value['lng'], value['lat'])
          point.push(value['lng'],value['lat'])
          points.push(point)
        })
        data.push({
@@ -864,7 +961,7 @@
        return new BMapGL.Point(lng, lat)
      }
      function getGrading(sensor, type) {
      function getGrading(sensor, type, carMac) {
        var levels = []
        var level0 = {}
        var level1 = {}
@@ -913,10 +1010,14 @@
          if (type === '2D') {
            height = 0
          } else {
            height = value[sensor] * 10
            if (sensor === 'a99054') {
              height = value[sensor] * 500
            }
            height = value[sensor]
            // if (sensor === 'a99054') {
            //   height = value[sensor] * 500
            // }
            // console.log(carMac, 'carMac')
            // if (sensor === 'dustld' && (value[sensor] - 0) < 100 && (value[sensor] - 0) !== 0 && carMac === 'p5dnd7a0243622') {
            //   height = 100 * 10
            // }
          }
          switch (level) {
            case 0:
@@ -1191,10 +1292,10 @@
      // point上添加label文本
      function setLabelStyle(content, point) {
        var label = new BMapGL.Label("<span class='my-maptip'>" + content + '<br /><span>', // 为lable填写内容
          {
            offset: new BMapGL.Size(-8, -10), // label的偏移量,为了让label的中心显示在点上
            position: point
          }
            {
              offset: new BMapGL.Size(-8, -10), // label的偏移量,为了让label的中心显示在点上
              position: point
            }
        )// label的位置
        var offsetSize = new BMapGL.Size(0, 0)
@@ -1243,7 +1344,7 @@
          draw(that.sensor, that.viewType)
          if (that.viewType === '2D') {
            that.map.setTilt(0)
            drawLine()
            // drawLine()
            drawStartAndEnd()
            $('.sensorLevel').attr('src', '/img/pollutionlevel.png')
          } else if (that.viewType === '3D') {
@@ -1309,96 +1410,96 @@
body,
html,
#map_container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    margin: 0;
    z-index: 0;
    font-size: 14px;
    font-family: "微软雅黑";
  width: 100%;
  height: 100%;
  overflow: hidden;
  margin: 0;
  z-index: 0;
  font-size: 14px;
  font-family: "微软雅黑";
}
.main_body {
    border: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    position: relative;
  border: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  position: relative;
}
#cpm {
    width: 300px;
    height: 100px;
    position: absolute;
    background-color: #ffffff;
    display: none;
    left: 50%;
    top: 50%;
    margin-left: -150px;
    margin-top: -50px;
    z-index: 11;
    color: #000000;
    border: 2px solid #FF7F50;
    font-size: 28px;
    line-height: 100px;
    text-align: center;
  width: 300px;
  height: 100px;
  position: absolute;
  background-color: #ffffff;
  display: none;
  left: 50%;
  top: 50%;
  margin-left: -150px;
  margin-top: -50px;
  z-index: 11;
  color: #000000;
  border: 2px solid #FF7F50;
  font-size: 28px;
  line-height: 100px;
  text-align: center;
}
.BMap_pop > img {
    top: 42px !important;
    margin-left: -10px;
  top: 42px !important;
  margin-left: -10px;
}
.BMap_pop div:nth-child(1) div {
    display: none;
  display: none;
}
.BMap_pop div:nth-child(3) {
    display: none;
  display: none;
}
.BMap_pop div:nth-child(5) {
    display: none;
  display: none;
}
.BMap_pop div:nth-child(7) {
    display: none;
  display: none;
}
.BMap_pop div:nth-child(9) {
    top: 35px !important;
    border-radius: 5px;
  top: 35px !important;
  border-radius: 5px;
}
#selectSenor {
    position: absolute;
    z-index: 1;
    left: 30px;
    top: 20px;
    font-size: 20px;
    background: lightgrey;
  position: absolute;
  z-index: 1;
  left: 30px;
  top: 20px;
  font-size: 20px;
  background: lightgrey;
}
#type {
    position: absolute;
    z-index: 1;
    left: 30px;
    top: 50px;
    font-size: 20px;
    background: lightgrey;
  position: absolute;
  z-index: 1;
  left: 30px;
  top: 50px;
  font-size: 20px;
  background: lightgrey;
}
button {
    font-size: 15px;
  font-size: 15px;
}
.sensorLevel {
    position: absolute;
    z-index: 1;
    bottom: 50px;
    left: 10px;
    width: 100px;
    height: 200px;
  position: absolute;
  z-index: 1;
  bottom: 50px;
  left: 10px;
  width: 100px;
  height: 200px;
}
.carTop {
  position: absolute;
@@ -1428,9 +1529,9 @@
  border-right: 1px solid #aaa;
}
.carTop{
    &>.left:nth-child(1){
      border-radius: 5px 0 0 5px;
    }
  &>.left:nth-child(1){
    border-radius: 5px 0 0 5px;
  }
}
.carTop {
  .left{