Browse Source

实时监测

luyanan 6 years ago
parent
commit
0d31507f59

+ 7 - 0
src/api/bridgeInfo.js

@ -73,4 +73,11 @@ export function getTimingMonitor(params) {
73 73
    params
74 74
  })
75 75
}
76
export function getTimingMonitorByTime(params) {
77
  return request({
78
    url: '/ajax/collect/wave/server/time',
79
    method: 'get',
80
    params
81
  })
82
}
76 83
// 监测信息

+ 17 - 13
src/utils/index.js

@ -24,20 +24,24 @@ export function parseTime(startTime, flag, fa) {
24 24
  }
25 25
}
26 26
27
export function turnTime(time, hasT, hasF) { // hasT='date/time'是否有时分秒,hasF是否需要显示格式
28
  if (hasT === 'time') {
29
    if (hasF) {
30
      return [time.getFullYear(), time.getMonth() + 1, time.getDate()].join('/') + ' ' + [time.getHours(), time.getMinutes(), time.getSeconds()].join(':')
31
    } else {
32
      return time.getFullYear() + (time.getMonth() + 1) + time.getDate() + time.getHours() + time.getMinutes() + time.getSeconds()
33
    }
34
  } else if (hasT === 'date') {
35
    if (hasF) {
36
      return [time.getFullYear(), time.getMonth() + 1, time.getDate()].join('/')
37
    } else {
38
      return time.getFullYear() + (time.getMonth() + 1) + time.getDate()
39
    }
27
export function turnTime(date, hasT, hasF) { // hasT='date/time'是否有时分秒,hasF是否需要显示格式
28
  const format = (hasT === 'time') ? (hasF ? '{y}/{m}/{d} {h}:{i}:{s}' : '{y}{m}{d}{h}{i}{s}') : (hasF ? '{y}/{m}/{d}' : '{y}{m}{d}')
29
  const formatObj = {
30
    y: date.getFullYear(),
31
    m: date.getMonth() + 1,
32
    d: date.getDate(),
33
    h: date.getHours(),
34
    i: date.getMinutes(),
35
    s: date.getSeconds()
40 36
  }
37
  const time_str = format.replace(/{(y|m|d|h|i|s)+}/g, (result, key) => {
38
    let value = formatObj[key]
39
    if (result.length > 0 && value < 10) {
40
      value = '0' + value
41
    }
42
    return value || 0
43
  })
44
  return time_str
41 45
}
42 46
43 47
export function param2Obj(url) {

+ 59 - 36
src/views/bridgesConsole/bridgeDetail/index.vue

@ -32,7 +32,7 @@
32 32
          </div>
33 33
          <el-row class="line-chart-box" v-if="monitorList.length">
34 34
            <el-col :xs="24" :sm="24" :lg="24" v-for="item in monitorShowList" :key="item.index">
35
              <lineChart2 :chartData="item"></lineChart2>
35
              <lineChart2 :chartData="item" :maxXcount="maxShowLength"></lineChart2>
36 36
            </el-col>
37 37
          </el-row>
38 38
          <DefaultPage v-if="!monitorList.length"></DefaultPage>
@ -83,7 +83,7 @@ import Cookies from 'js-cookie'
83 83
import queryInfo from '@/utils/queryInfo'
84 84
import queryDict from '@/utils/queryDict'
85 85
import { urlParse, parseTime, turnTime } from '@/utils'
86
import { getDangerList, getTimingMonitor } from '@/api/bridgeInfo'
86
import { getDangerList, getTimingMonitor, getTimingMonitorByTime } from '@/api/bridgeInfo'
87 87
88 88
import lineChart2 from '../lineChart/LineChart2'
89 89
import BInfoDialog01 from './components/BInfoDialog01'
@ -121,9 +121,10 @@ export default {
121 121
      monitorList: [],
122 122
      currentNo: 1,
123 123
      currentSize: 4,
124
      currentTime: turnTime(new Date()),
125
      dateArr: [],
126
      intervalTime: 60 * 1000
124
      currentTime: turnTime(new Date(), 'time', true),
125
      setTime: null,
126
      maxShowLength: 300,
127
      monitorCache: []
127 128
    }
128 129
  },
129 130
  computed: {
@ -145,12 +146,11 @@ export default {
145 146
      if (this.serverSeqArr.length) {
146 147
        this.getTimingMonitor(this.serverSeqArr)
147 148
        this.getDangerList(this.serverSeqArr)
149
        this.setTime = setInterval(() => {
150
          this.getTimingMonitor(this.serverSeqArr)
151
        }, 1000)
148 152
      }
149 153
    }
150
    // setInterval(() => {
151
    //   this.addData(true)
152
    //   this.getTimingMonitor()
153
    // }, 60000)
154 154
  },
155 155
  methods: {
156 156
    getDangerList(arr) {
@ -172,38 +172,65 @@ export default {
172 172
        }
173 173
      })
174 174
    },
175
    addData() {
176
      this.currentTime = turnTime(new Date(+new Date(this.currentTime) + 1000), 'time', true)
177
    },
175 178
    getTimingMonitor(arr) {
176 179
      var that = this
177 180
      const param = {
178 181
        seq: arr
179 182
      }
180
      getTimingMonitor(param).then(res => {
183
      getTimingMonitor({seq: arr}).then(res => {
181 184
        if (res.success && res.data) {
185
          that.addData()
182 186
          var monitorList = []
183
          for (let i = 0; i < res.data.length; i++) {
184
            var str = res.data[i].cid
185
            var monitorData = null
186
            for (let j = 0; j < monitorList.length; ++j) {
187
              if (str === monitorList[j].tit) {
188
                monitorData = monitorList[j]
189
                break
187
          var monitorCache = that.monitorCache
188
          if (monitorCache.length) {
189
            for(let j = 0; j < monitorCache.length; ++j){
190
              let channel_found = false
191
              var xData = monitorCache[j].cd.xData
192
              var max = monitorCache[j].cd.seData.max
193
              var min = monitorCache[j].cd.seData.min
194
              for (let i = 0; i < res.data.length; i++){
195
                if(monitorCache[j].cid === res.data[i].cid){
196
                  channel_found = true
197
                  xData.push(that.currentTime)
198
                  max.push(res.data[i].hvalue)
199
                  min.push(res.data[i].lvalue)
200
                  break
201
                }
202
              }
203
              if (!channel_found) {
204
                xData.push(that.currentTime)
205
                max.push(max[max.length-1])
206
                min.push(min[min.length-1])
207
              }
208
              if (xData.length > that.maxShowLength) {
209
                xData.shift()
210
                max.shift()
211
                min.shift()
190 212
              }
213
              monitorList.push(monitorCache[j].cd)
191 214
            }
192
            if (!monitorData) {
193
              monitorData = {
194
                xData: [],
195
                seData: {
196
                  max: [],
197
                  min: []
215
          } else {
216
            for (let i = 0; i < res.data.length; i++){
217
              var mi = {
218
                cid: res.data[i].cid,
219
                cd: {
220
                  xData: [],
221
                  seData: {
222
                    max: [],
223
                    min: []
224
                  }
198 225
                }
199 226
              }
200
              monitorList.push(monitorData)
201
              monitorData.tit = str
202
              that.addData()
227
              mi.cd.xData.push(that.currentTime)
228
              mi.cd.seData.max.push(res.data[i].hvalue)
229
              mi.cd.seData.min.push(res.data[i].lvalue)
230
              mi.cd.tit = res.data[i].cid
231
              monitorCache.push(mi)
232
              monitorList.push(mi.cd)
203 233
            }
204
            monitorData.xData.push(that.dateArr)
205
            monitorData.seData.max.push(res.data[i].hvalue)
206
            monitorData.seData.min.push(res.data[i].lvalue)
207 234
          }
208 235
          that.monitorList = monitorList
209 236
        }
@ -227,13 +254,6 @@ export default {
227 254
        })
228 255
      }) // 城市级联
229 256
    },
230
    addData(shift) {
231
      this.dateArr.push(this.currentTime)
232
      if (shift) {
233
        this.dateArr.shift()
234
      }
235
      this.currentTime = turnTime(new Date(+new Date(this.currentTime) + this.intervalTime))
236
    },
237 257
    handleCurrentChange(val) {
238 258
      this.currentNo = val
239 259
    },
@ -268,6 +288,9 @@ export default {
268 288
    updateLoginPwd() {
269 289
      this.$refs.updateLoginPwd.dialogTableVisible = true
270 290
    }
291
  },
292
  beforeDestroy() {
293
    clearInterval(this.setTime)
271 294
  }
272 295
}
273 296
</script>

+ 5 - 1
src/views/bridgesConsole/lineChart/LineChart2.vue

@ -27,6 +27,9 @@ export default {
27 27
    },
28 28
    chartData: {
29 29
      type: Object
30
    },
31
    maxXcount: {
32
      type: Number
30 33
    }
31 34
  },
32 35
  data() {
@ -94,7 +97,8 @@ export default {
94 97
          boundaryGap: false,
95 98
          axisTick: {
96 99
            show: false
97
          }
100
          },
101
          max: this.maxXcount // x轴最多显示个数
98 102
        },
99 103
        yAxis: {
100 104
          type: 'value',