Browse Source

波形图随需求修改完善+

luyanan 6 years ago
parent
commit
00eabd1d1b

+ 14 - 0
src/api/bridgeInfo.js

66
    params
66
    params
67
  })
67
  })
68
}
68
}
69
export function getSysTime(params) {
70
  return request({
71
    url: '/ajax/sys/serviceTime',
72
    method: 'get',
73
    params
74
  })
75
}
76
export function getMonitorByTime(params) {
77
  return request({
78
    url: '/ajax/collect/wave/server/time',
79
    method: 'get',
80
    params
81
  })
82
}
69
export function getTimingMonitor(params) {
83
export function getTimingMonitor(params) {
70
  return request({
84
  return request({
71
    url: '/ajax/collect/wave/curr',
85
    url: '/ajax/collect/wave/curr',

+ 1 - 1
src/utils/index.js

15
export function parseTime(startTime, flag, fa) {
15
export function parseTime(startTime, flag, fa) {
16
  if (flag) {
16
  if (flag) {
17
    if (!fa) {
17
    if (!fa) {
18
      return startTime.substring(0, 4) + '年' + startTime.substring(4, 6) + '月' + startTime.substring(6, 8) + '日 ' + startTime.substring(8, 10) + ':' + startTime.substring(10, 12)
18
      return startTime.substring(0, 4) + '年' + startTime.substring(4, 6) + '月' + startTime.substring(6, 8) + '日 ' + startTime.substring(8, 10) + ':' + startTime.substring(10, 12) + ':' + startTime.substring(12, 14)
19
    } else {
19
    } else {
20
      return startTime.substring(0, 4) + '/' + startTime.substring(4, 6) + '/' + startTime.substring(6, 8) + ' ' + startTime.substring(8, 10) + ':' + startTime.substring(10, 12) + ':' + startTime.substring(12, 14)
20
      return startTime.substring(0, 4) + '/' + startTime.substring(4, 6) + '/' + startTime.substring(6, 8) + ' ' + startTime.substring(8, 10) + ':' + startTime.substring(10, 12) + ':' + startTime.substring(12, 14)
21
    }
21
    }

+ 78 - 0
src/utils/timingConstruct.js

1
/**
2
 * Created by luyanan on 18/9/4.
3
 * construct monitor
4
 */
5
/* eslint-disable one-var */
6
import { parseTime } from '@/utils/index'
7
8
var monitorModel = {
9
  construct: function(mCache, $data) {
10
    for (let i = 0; i < $data.length; ++i) {
11
      if ($data[i].ctime === $data[0].ctime) {
12
        mCache.push({
13
          cid: $data[i].cid,
14
          cd: {
15
            tit: '',
16
            xData: [],
17
            seData: []
18
          }
19
        })
20
      }
21
    }
22
  },
23
  fixData: function(item, ftbegin, ftend, $daI) {
24
    if ($daI) {
25
      item.xData.push(parseTime(ftbegin, true, true))
26
      item.xData.push(parseTime(ftend, true, true))
27
      item.seData.push($daI.hvalue)
28
      item.seData.push($daI.lvalue)
29
      item.tit = $daI.cid
30
    } else {
31
      item.xData.push(parseTime(ftbegin, true, true))
32
      item.xData.push(parseTime(ftend, true, true))
33
      item.seData.push(0)
34
      item.seData.push(0)
35
    }
36
  },
37
  shiftData: function(item) {
38
    item.xData.shift()
39
    item.xData.shift()
40
    item.seData.shift()
41
    item.seData.shift()
42
  },
43
  setData: function(mCache, $data, ftbegin, ftend, maxNum) {
44
    if ($data.length) {
45
      for (let n = 0; n < mCache.length; ++n) {
46
        let found_c = false
47
        for (let m = 0; m < $data.length; ++m) {
48
          var tj = ($data[m].cid === mCache[n].cid && (ftbegin === $data[m].ctime))
49
          if (maxNum) {
50
            tj = ($data[m].cid === mCache[n].cid)
51
          }
52
          if (tj) {
53
            found_c = true
54
            this.fixData(mCache[n].cd, ftbegin, ftend, $data[m])
55
            break
56
          }
57
        }
58
        if (!found_c) {
59
          this.fixData(mCache[n].cd, ftbegin, ftend)
60
        }
61
62
        if (maxNum && mCache[n].cd.xData.length > maxNum) {
63
          this.shiftData(mCache[n].cd)
64
        }
65
      }
66
    } else {
67
      for (let k = 0; k < mCache.length; ++k) {
68
        this.fixData(mCache[k].cd, ftbegin, ftend)
69
70
        if (maxNum && mCache[k].cd.xData.length > maxNum) {
71
          this.shiftData(mCache[k].cd)
72
        }
73
      }
74
    }
75
  }
76
}
77
78
export default monitorModel

+ 25 - 10
src/views/bridgesConsole/bridgeDanger/dangerDetail.vue

7
      </div>
7
      </div>
8
      <el-row class="line-chart-box">
8
      <el-row class="line-chart-box">
9
        <el-col :xs="24" :sm="24" :lg="24" v-for="(item, index) in alarmShowList" :key="item.index">
9
        <el-col :xs="24" :sm="24" :lg="24" v-for="(item, index) in alarmShowList" :key="item.index">
10
          <lineChart :chartData="item.data" :startTime="item.stime" :legendName="'传感器' + item.seq" :lineColor="index" :intervalTime="intervalTime"></lineChart>
10
          <lineChart :chartData="item" :lineColor="index"></lineChart>
11
        </el-col>
11
        </el-col>
12
      </el-row>
12
      </el-row>
13
      <div class="pagination-container">
13
      <div class="pagination-container">
25
</template>
25
</template>
26
26
27
<script>
27
<script>
28
import { urlParse, parseTime } from '@/utils'
28
import { urlParse, parseTime, turnTime } from '@/utils'
29
import { getDangerDetail, setUnreadToRead } from '@/api/bridgeInfo'
29
import { getDangerDetail, setUnreadToRead } from '@/api/bridgeInfo'
30
import lineChart from '../lineChart/LineChart'
30
import lineChart from '../lineChart/LineChart'
31
31
38
      alarmList: [],
38
      alarmList: [],
39
      pageSize: 6,
39
      pageSize: 6,
40
      pageNo: 1,
40
      pageNo: 1,
41
      intervalTime: 3 * 1000
41
      intervalTime: (3 * 1000) / 300
42
    }
42
    }
43
  },
43
  },
44
  components: {
44
  components: {
48
    this.alarmId = urlParse('aid')
48
    this.alarmId = urlParse('aid')
49
    this.alarmTit = urlParse('msg')
49
    this.alarmTit = urlParse('msg')
50
    this.alarmRead = urlParse('flag')
50
    this.alarmRead = urlParse('flag')
51
    this.alarmTime = urlParse('_t')
51
    this.getDangerDetail()
52
    this.getDangerDetail()
52
    if (this.alarmRead === 'false') {
53
    if (this.alarmRead === 'false') {
53
      this.setUnreadToRead()
54
      this.setUnreadToRead()
54
    }
55
    }
55
  },
56
  },
56
  computed: {
57
  computed: {
57
    alarmTime() {
58
      const alramM = this.alarmId.split('_')
59
      return parseTime(alramM[ alramM.length - 1], true)
60
    },
61
    alarmShowList() {
58
    alarmShowList() {
62
      return this.alarmList.slice((this.pageNo - 1) * this.pageSize, this.pageNo * this.pageSize)
59
      return this.alarmList.slice((this.pageNo - 1) * this.pageSize, this.pageNo * this.pageSize)
63
    }
60
    }
64
  },
61
  },
65
  methods: {
62
  methods: {
66
    getDangerDetail() {
63
    getDangerDetail() {
64
      var that = this
67
      const param = {
65
      const param = {
68
        aid: this.alarmId
66
        aid: this.alarmId
69
      }
67
      }
70
      getDangerDetail(param).then(res => {
68
      getDangerDetail(param).then(res => {
71
        if (res.success && res.data) {
69
        if (res.success && res.data) {
70
          var rList = []
71
          var startTime = ''
72
          for (let i = 0; i < res.data.length; i++) {
72
          for (let i = 0; i < res.data.length; i++) {
73
            const arr = JSON.parse('[' + String(res.data[i].data.split(',')) + ']')
74
            res.data[i].data = arr
73
            startTime = parseTime(res.data[0].stime, true, true)
74
            var str = res.data[i].seq
75
            var rData = {
76
              tit: '',
77
              xData: [],
78
              seData: []
79
            }
80
            rList.push(rData)
81
            rData.tit = str
82
            var dataArr = JSON.parse('[' + String(res.data[i].data.split(',')) + ']')
83
            var timeArr = []
84
            for (var j = 0; j < dataArr.length; j++) {
85
              startTime = turnTime(new Date(+new Date(startTime) + that.intervalTime), 'time', true)
86
              timeArr.push(startTime)
87
            }
88
            rData.xData = timeArr
89
            rData.seData = dataArr
75
          }
90
          }
76
          this.alarmList = res.data
91
          that.alarmList = rList
77
        }
92
        }
78
      })
93
      })
79
    },
94
    },

+ 3 - 3
src/views/bridgesConsole/bridgeDanger/dangerList.vue

5
        <span>报警信息</span>
5
        <span>报警信息</span>
6
      </div>
6
      </div>
7
      <ul class="item-ul" v-if="dangerList.length">
7
      <ul class="item-ul" v-if="dangerList.length">
8
        <li :class="!item.readed ? 'readed-li' : ''" v-for="item in dangerShowList" :key="item.index" @click="alarmShow(item.aid, item.readed, item.device)">
8
        <li :class="!item.readed ? 'readed-li' : ''" v-for="item in dangerShowList" :key="item.index" @click="alarmShow(item.aid, item.readed, item.alarmTime, item.device)">
9
          <span>{{item.alarmTime}}</span>
9
          <span>{{item.alarmTime}}</span>
10
          <span>{{item.device}},请点击查看。</span>
10
          <span>{{item.device}},请点击查看。</span>
11
          <span class="svg-container" v-if="!item.readed">
11
          <span class="svg-container" v-if="!item.readed">
84
        }
84
        }
85
      })
85
      })
86
    },
86
    },
87
    alarmShow(id, flag, msg) {
87
    alarmShow(id, flag, time, msg) {
88
      this.$router.replace({
88
      this.$router.replace({
89
        name: 'dangerDetail',
89
        name: 'dangerDetail',
90
        query: { aid: id, msg: msg, flag: flag }
90
        query: { aid: id, msg: msg, _t: time, flag: flag }
91
      })
91
      })
92
    },
92
    },
93
    handleCurrentChange(val) {
93
    handleCurrentChange(val) {

+ 70 - 63
src/views/bridgesConsole/bridgeDetail/index.vue

16
            <el-button type="text" @click="queryDangerInfo">查看全部</el-button>
16
            <el-button type="text" @click="queryDangerInfo">查看全部</el-button>
17
          </div>
17
          </div>
18
          <ul class="item-ul" v-if="dangerList.length">
18
          <ul class="item-ul" v-if="dangerList.length">
19
            <li :class="!item.readed ? 'readed-li' : ''" v-for="item in dangerList" :key="item.index" @click="alarmShow(item.aid, item.readed, item.device)">
19
            <li :class="!item.readed ? 'readed-li' : ''" v-for="item in dangerList" :key="item.index" @click="alarmShow(item.aid, item.readed, item.alarmTime, item.device)">
20
              <span>{{item.alarmTime}}</span>
20
              <span>{{item.alarmTime}}</span>
21
              <span>{{item.device}},请点击查看。</span>
21
              <span>{{item.device}},请点击查看。</span>
22
              <span class="svg-container" v-if="!item.readed">
22
              <span class="svg-container" v-if="!item.readed">
32
          </div>
32
          </div>
33
          <el-row class="line-chart-box" v-if="monitorList.length">
33
          <el-row class="line-chart-box" v-if="monitorList.length">
34
            <el-col :xs="24" :sm="24" :lg="24" v-for="item in monitorShowList" :key="item.index">
34
            <el-col :xs="24" :sm="24" :lg="24" v-for="item in monitorShowList" :key="item.index">
35
              <lineChart2 :chartData="item" :maxXcount="maxShowLength"></lineChart2>
35
              <lineChart :chartData="item" :maxXcount="maxShowLength"></lineChart>
36
            </el-col>
36
            </el-col>
37
          </el-row>
37
          </el-row>
38
          <DefaultPage v-if="!monitorList.length"></DefaultPage>
38
          <DefaultPage v-if="!monitorList.length"></DefaultPage>
82
import Cookies from 'js-cookie'
82
import Cookies from 'js-cookie'
83
import queryInfo from '@/utils/queryInfo'
83
import queryInfo from '@/utils/queryInfo'
84
import queryDict from '@/utils/queryDict'
84
import queryDict from '@/utils/queryDict'
85
import { urlParse, parseTime, turnTime } from '@/utils'
86
import { getDangerList, getTimingMonitor } from '@/api/bridgeInfo'
85
import monModel from '@/utils/timingConstruct'
86
import { urlParse, parseTime } from '@/utils'
87
import { getDangerList, getSysTime, getMonitorByTime } from '@/api/bridgeInfo'
87
88
88
import lineChart2 from '../lineChart/LineChart2'
89
import lineChart from '../lineChart/LineChart'
89
import BInfoDialog01 from './components/BInfoDialog01'
90
import BInfoDialog01 from './components/BInfoDialog01'
90
import BInfoDialog02 from './components/BInfoDialog02'
91
import BInfoDialog02 from './components/BInfoDialog02'
91
import BInfoDialog03 from './components/BInfoDialog03'
92
import BInfoDialog03 from './components/BInfoDialog03'
99
export default {
100
export default {
100
  name: 'dashboard-other',
101
  name: 'dashboard-other',
101
  components: {
102
  components: {
102
    lineChart2,
103
    lineChart,
103
    BInfoDialog01,
104
    BInfoDialog01,
104
    BInfoDialog02,
105
    BInfoDialog02,
105
    BInfoDialog03,
106
    BInfoDialog03,
121
      monitorList: [],
122
      monitorList: [],
122
      currentNo: 1,
123
      currentNo: 1,
123
      currentSize: 4,
124
      currentSize: 4,
124
      currentTime: turnTime(new Date(), 'time', true),
125
      currentTime: '',
126
      sysTime: '',
125
      setTime: null,
127
      setTime: null,
126
      maxShowLength: 300,
128
      maxShowLength: 300,
127
      monitorCache: []
129
      monitorCache: []
144
    if (this.bridgeId) {
146
    if (this.bridgeId) {
145
      this.serverSeqArr = queryInfo.queryServers(this.bridgeId, true)
147
      this.serverSeqArr = queryInfo.queryServers(this.bridgeId, true)
146
      if (this.serverSeqArr.length) {
148
      if (this.serverSeqArr.length) {
147
        this.getTimingMonitor(this.serverSeqArr)
148
        this.getDangerList(this.serverSeqArr)
149
        this.setTime = setInterval(() => {
150
          this.getTimingMonitor(this.serverSeqArr)
151
        }, 1000)
149
        this.getSysTime()
150
        this.getDangerList()
152
      }
151
      }
153
    }
152
    }
154
  },
153
  },
155
  methods: {
154
  methods: {
156
    getDangerList(arr) {
155
    getDangerList() {
156
      var arr = this.serverSeqArr
157
      const param = {
157
      const param = {
158
        seq: arr,
158
        seq: arr,
159
        pageSize: 5,
159
        pageSize: 5,
172
        }
172
        }
173
      })
173
      })
174
    },
174
    },
175
    addData() {
176
      this.currentTime = turnTime(new Date(+new Date(this.currentTime) + 1000), 'time', true)
175
    getSysTime() {
176
      getSysTime().then(res => {
177
        if (res.success) {
178
          this.sysTime = 1536028430317 + (8 * 60 * 60 * 1000) + 160000
179
          this.first_Q = true
180
          this.getTimingMonitor()
181
        }
182
      })
183
    },
184
    formatTime(time) {
185
      var d = new Date()
186
      d.setTime(time)
187
      d = JSON.stringify(d).replace(/[^\d]/g, '').substring(0, 14)
188
      return d
177
    },
189
    },
178
    getTimingMonitor(arr) {
190
    getTimingMonitor() {
179
      var that = this
191
      var that = this
180
      getTimingMonitor({ seq: arr }).then(res => {
192
      var preTime = 10 * 1000
193
      var arr = this.serverSeqArr
194
      var startTime = this.formatTime(this.first_Q ? (this.sysTime - preTime) : this.sysTime)
195
      var endTime = this.formatTime(this.sysTime)
196
      getMonitorByTime({ seq: arr, begin: startTime, end: endTime }).then(res => {
197
        var mCache = that.monitorCache
198
        var mList = []
181
        if (res.success && res.data) {
199
        if (res.success && res.data) {
182
          that.addData()
183
          var monitorList = []
184
          var monitorCache = that.monitorCache
185
          if (monitorCache.length) {
186
            for (let j = 0; j < monitorCache.length; ++j) {
187
              let channel_found = false
188
              var xData = monitorCache[j].cd.xData
189
              var max = monitorCache[j].cd.seData.max
190
              var min = monitorCache[j].cd.seData.min
191
              for (let i = 0; i < res.data.length; i++) {
192
                if (monitorCache[j].cid === res.data[i].cid) {
193
                  channel_found = true
194
                  xData.push(that.currentTime)
195
                  max.push(res.data[i].hvalue)
196
                  min.push(res.data[i].lvalue)
200
          if (that.first_Q) {
201
            if (res.data.length) {
202
              that.first_Q = false
203
              var ftime = res.data[0].ctime
204
              monModel.construct(mCache, res.data)
205
206
              var f_q_t = that.sysTime - preTime
207
208
              for (;;) {
209
                var fts = that.formatTime(f_q_t)
210
                var ftsE = that.formatTime(f_q_t + 500)
211
                if (fts >= ftime) {
212
                  if (fts > that.sysTime) {
213
                    monModel.setData(mCache, res.data, fts, ftsE, null)
214
                  }
215
                }
216
                f_q_t += 1000
217
                if (f_q_t > that.sysTime) {
197
                  break
218
                  break
198
                }
219
                }
199
              }
220
              }
200
              if (!channel_found) {
201
                xData.push(that.currentTime)
202
                max.push(max[max.length - 1])
203
                min.push(min[min.length - 1])
204
              }
205
              if (xData.length > that.maxShowLength) {
206
                xData.shift()
207
                max.shift()
208
                min.shift()
221
              for (let l = 0; l < mCache.length; ++l) {
222
                mList.push(mCache[l].cd)
209
              }
223
              }
210
              monitorList.push(monitorCache[j].cd)
211
            }
224
            }
212
          } else {
225
          } else {
213
            for (let i = 0; i < res.data.length; i++) {
214
              var mi = {
215
                cid: res.data[i].cid,
216
                cd: {
217
                  xData: [],
218
                  seData: {
219
                    max: [],
220
                    min: []
221
                  }
222
                }
223
              }
224
              mi.cd.xData.push(that.currentTime)
225
              mi.cd.seData.max.push(res.data[i].hvalue)
226
              mi.cd.seData.min.push(res.data[i].lvalue)
227
              mi.cd.tit = res.data[i].cid
228
              monitorCache.push(mi)
229
              monitorList.push(mi.cd)
226
            var xtime = that.formatTime(that.sysTime)
227
            var xtimeE = that.formatTime(that.sysTime + 500)
228
229
            monModel.setData(mCache, res.data, xtime, xtimeE, that.maxShowLength)
230
            for (let l = 0; l < mCache.length; ++l) {
231
              mList.push(mCache[l].cd)
230
            }
232
            }
231
          }
233
          }
232
          that.monitorList = monitorList
234
          that.monitorList = mList
235
          that.sysTime += 1000
236
          that.setTime = setTimeout(function() {
237
            that.getTimingMonitor()
238
          }, 1000)
233
        }
239
        }
234
      })
240
      })
235
    },
241
    },
254
    handleCurrentChange(val) {
260
    handleCurrentChange(val) {
255
      this.currentNo = val
261
      this.currentNo = val
256
    },
262
    },
257
    alarmShow(id, flag, msg) {
263
    alarmShow(id, flag, time, msg) {
258
      this.$router.replace({
264
      this.$router.replace({
259
        name: 'dangerDetail',
265
        name: 'dangerDetail',
260
        query: { aid: id, msg: msg, flag: flag }
266
        query: { aid: id, msg: msg, _t: time, flag: flag }
261
      })
267
      })
262
    },
268
    },
263
    queryDangerInfo() {
269
    queryDangerInfo() {
287
    }
293
    }
288
  },
294
  },
289
  beforeDestroy() {
295
  beforeDestroy() {
290
    clearInterval(this.setTime)
296
    clearTimeout(this.setTime)
297
    // clearInterval(this.setTime)
291
  }
298
  }
292
}
299
}
293
</script>
300
</script>

+ 28 - 19
src/views/bridgesConsole/bridgeMonitor/index.vue

6
            v-model="valueDate"
6
            v-model="valueDate"
7
            type="date"
7
            type="date"
8
            value-format="yyyyMMdd"
8
            value-format="yyyyMMdd"
9
            :picker-options="pickerOptions0"
9
            @change="changeDate">
10
            @change="changeDate">
10
          </el-date-picker>
11
          </el-date-picker>
11
          <!-- <el-date-picker
12
          <!-- <el-date-picker
20
      </div>
21
      </div>
21
      <el-row class="line-chart-box" v-if="alarmList.length">
22
      <el-row class="line-chart-box" v-if="alarmList.length">
22
        <el-col :xs="24" :sm="24" :lg="24" v-for="item in alarmShowList" :key="item.index">
23
        <el-col :xs="24" :sm="24" :lg="24" v-for="item in alarmShowList" :key="item.index">
23
          <lineChart2 :chartData="item" :historyM="historyM"></lineChart2>
24
          <lineChart :chartData="item" :historyM="historyM"></lineChart>
24
        </el-col>
25
        </el-col>
25
      </el-row>
26
      </el-row>
26
      <DefaultPage v-if="!alarmList.length"></DefaultPage>
27
      <DefaultPage v-if="!alarmList.length"></DefaultPage>
43
import '@/styles/roleuser.scss'
44
import '@/styles/roleuser.scss'
44
import Cookies from 'js-cookie'
45
import Cookies from 'js-cookie'
45
import queryInfo from '@/utils/queryInfo'
46
import queryInfo from '@/utils/queryInfo'
46
import { parseTime } from '@/utils'
47
import { getMonitorByDay } from '@/api/bridgeInfo'
47
import { getMonitorByDay } from '@/api/bridgeInfo'
48
import lineChart2 from '../lineChart/LineChart2'
48
import { parseTime } from '@/utils'
49
import lineChart from '../lineChart/LineChart'
49
50
50
import DefaultPage from '@/components/DefaultPage'
51
import DefaultPage from '@/components/DefaultPage'
51
52
54
    return {
55
    return {
55
      historyM: true,
56
      historyM: true,
56
      bridgeId: '',
57
      bridgeId: '',
57
      valueDate: new Date().toISOString().substring(0, 10).replace(/-/g, ''),
58
      pickerOptions0: {
59
        disabledDate(time) {
60
          return time.getTime() > Date.now() - 8.64e7
61
        }
62
      },
63
      valueDate: this.formatTime((new Date()).getTime() + ((8 - 24) * 60 * 60 * 1000)),
58
      dateRange: '',
64
      dateRange: '',
59
      serverSeqArr: [],
65
      serverSeqArr: [],
60
      alarmList: [],
66
      alarmList: [],
67
      monitorCache: [],
61
      pageSize: 2,
68
      pageSize: 2,
62
      pageNo: 1
69
      pageNo: 1
63
    }
70
    }
64
  },
71
  },
65
  components: {
72
  components: {
66
    lineChart2,
73
    lineChart,
67
    DefaultPage
74
    DefaultPage
68
  },
75
  },
69
  computed: {
76
  computed: {
79
    }
86
    }
80
  },
87
  },
81
  methods: {
88
  methods: {
89
    formatTime(time) {
90
      var d = new Date()
91
      d.setTime(time)
92
      d = JSON.stringify(d).replace(/[^\d]/g, '').substring(0, 8)
93
      return d
94
    },
82
    getMonitorByDay() {
95
    getMonitorByDay() {
83
      var that = this
96
      var that = this
84
      var date = that.valueDate
97
      var date = that.valueDate
85
      var arr = this.serverSeqArr
98
      var arr = this.serverSeqArr
86
      var param = {
87
        seq: arr,
88
        day: date
89
      }
90
      getMonitorByDay(param).then(res => {
99
      getMonitorByDay({ seq: arr, day: date }).then(res => {
91
        if (res.success && res.data) {
100
        if (res.success && res.data) {
92
          var monitorList = []
101
          var monitorList = []
93
          for (let i = 0; i < res.data.length; i++) {
102
          for (let i = 0; i < res.data.length; i++) {
101
            }
110
            }
102
            if (!monitorData) {
111
            if (!monitorData) {
103
              monitorData = {
112
              monitorData = {
113
                tit: '',
104
                xData: [],
114
                xData: [],
105
                seData: {
106
                  max: [],
107
                  min: []
108
                }
115
                seData: []
109
              }
116
              }
110
              monitorList.push(monitorData)
117
              monitorList.push(monitorData)
111
              monitorData.tit = str
118
              monitorData.tit = str
112
            }
119
            }
113
            monitorData.xData.push(parseTime(res.data[i].ctime, true, true))
114
            monitorData.seData.max.push(res.data[i].hvalue)
115
            monitorData.seData.min.push(res.data[i].lvalue)
120
            monitorData.xData.push(parseTime(res.data[i].ctime, true, true).substring(11, 19))
121
            monitorData.xData.push(parseTime(res.data[i].ctime, true, true).substring(11, 19))
122
            monitorData.seData.push(res.data[i].hvalue)
123
            monitorData.seData.push(res.data[i].lvalue)
116
          }
124
          }
117
          that.alarmList = monitorList
125
          that.alarmList = monitorList
118
          console.log(that.alarmList)
119
        }
126
        }
120
      })
127
      })
121
    },
128
    },
122
    changeDate(val) {
129
    changeDate(val) {
123
      this.valueDate = val
130
      this.valueDate = val
124
      this.getMonitorByDay()
131
      if (this.serverSeqArr.length) {
132
        this.getMonitorByDay()
133
      }
125
    },
134
    },
126
    handleCurrentChange(val) {
135
    handleCurrentChange(val) {
127
      this.pageNo = val
136
      this.pageNo = val

+ 56 - 41
src/views/bridgesConsole/lineChart/LineChart.vue

4
4
5
<script>
5
<script>
6
import echarts from 'echarts'
6
import echarts from 'echarts'
7
import { parseTime, turnTime } from '@/utils'
8
require('echarts/theme/macarons') // echarts theme
7
require('echarts/theme/macarons') // echarts theme
9
import { debounce } from '@/utils'
8
import { debounce } from '@/utils'
10
9
24
    },
23
    },
25
    height: {
24
    height: {
26
      type: String,
25
      type: String,
27
      default: '260px'
26
      default: '350px'
28
    },
27
    },
29
    autoResize: {
28
    autoResize: {
30
      type: Boolean,
29
      type: Boolean,
31
      default: true
30
      default: true
32
    },
31
    },
33
    chartData: {
32
    chartData: {
34
      type: Array
33
      type: Object
35
    },
34
    },
36
    legendName: {
37
      type: String
38
    },
39
    startTime: {
40
      type: String
41
    },
42
    intervalTime: {
35
    maxXcount: {
43
      type: Number
36
      type: Number
37
    },
38
    historyM: { // 判断是否需要坐标轴上的滚动条
39
      type: Boolean
44
    }
40
    }
45
  },
41
  },
46
  data() {
42
  data() {
47
    return {
43
    return {
48
      lineColorNow: this.lineColor % 2 === 0 ? '#FF005A' : '#3888fa',
44
      lineColorNow: this.lineColor % 2 === 0 ? '#FF005A' : '#3888fa',
49
      Ydate: [],
50
      nowTime: parseTime(this.startTime, true, true),
51
      chart: null
45
      chart: null
52
    }
46
    }
53
  },
47
  },
61
      }, 100)
55
      }, 100)
62
      window.addEventListener('resize', this.__resizeHanlder)
56
      window.addEventListener('resize', this.__resizeHanlder)
63
    }
57
    }
64
65
    // 监听侧边栏的变化
66
    // const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
67
    // sidebarElm.addEventListener('transitionend', this.__resizeHanlder)
68
  },
58
  },
69
  beforeDestroy() {
59
  beforeDestroy() {
70
    if (!this.chart) {
60
    if (!this.chart) {
74
      window.removeEventListener('resize', this.__resizeHanlder)
64
      window.removeEventListener('resize', this.__resizeHanlder)
75
    }
65
    }
76
66
77
    // const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
78
    // sidebarElm.removeEventListener('transitionend', this.__resizeHanlder)
79
80
    this.chart.dispose()
67
    this.chart.dispose()
81
    this.chart = null
68
    this.chart = null
82
  },
69
  },
89
    }
76
    }
90
  },
77
  },
91
  methods: {
78
  methods: {
92
    addData() {
93
      this.Ydate.push(this.nowTime)
94
      this.nowTime = turnTime(new Date(+new Date(this.nowTime) + this.intervalTime), 'time', true)
95
    },
96
    setOptions(datastr) {
79
    setOptions(datastr) {
97
      this.chart.setOption({
80
      this.chart.setOption({
98
        xAxis: {
99
          data: this.Ydate,
100
          boundaryGap: false,
101
          axisTick: {
102
            show: false
103
          }
81
        title: {
82
          text: '传感器' + datastr.tit,
83
          textStyle: {
84
            color: '#333',
85
            fontSize: 14
86
          },
87
          top: '0'
104
        },
88
        },
105
        grid: {
89
        grid: {
106
          left: 10,
90
          left: 10,
107
          right: 10,
91
          right: 10,
108
          bottom: 20,
92
          bottom: 20,
109
          top: 30,
93
          top: 60,
110
          containLabel: true
94
          containLabel: true
111
        },
95
        },
112
        tooltip: {
96
        tooltip: {
116
          },
100
          },
117
          padding: [5, 10]
101
          padding: [5, 10]
118
        },
102
        },
103
        xAxis: {
104
          data: datastr.xData,
105
          max: this.maxXcount // x轴最多显示个数
106
        },
119
        yAxis: {
107
        yAxis: {
120
          // name: '豪伏(-8192-8192)',
121
          axisTick: {
122
            show: false
123
          }
108
          name: '伏(mv)',
109
          type: 'value'
124
        },
110
        },
125
        legend: {
111
        legend: {
126
          data: [this.legendName]
112
          data: ['波动值']
127
        },
113
        },
128
        series: [{
114
        series: [{
129
          name: this.legendName, itemStyle: {
115
          name: '波动值', itemStyle: {
130
            normal: {
116
            normal: {
131
              color: this.lineColorNow,
117
              color: this.lineColorNow,
132
              lineStyle: {
118
              lineStyle: {
137
          },
123
          },
138
          smooth: true,
124
          smooth: true,
139
          type: 'line',
125
          type: 'line',
140
          data: datastr,
126
          data: datastr.seData,
141
          animationDuration: 2800,
127
          animationDuration: 2800,
142
          animationEasing: 'cubicInOut'
128
          animationEasing: 'cubicInOut'
143
        }]
129
        }]
144
      })
130
      })
131
      if (this.historyM) {
132
        this.chart.setOption({
133
          dataZoom: [
134
            {
135
              type: 'slider',
136
              show: true,
137
              start: 94,
138
              end: 100,
139
              handleSize: 8
140
            },
141
            {
142
              type: 'inside',
143
              start: 94,
144
              end: 100
145
            },
146
            {
147
              type: 'slider',
148
              show: true,
149
              yAxisIndex: 0,
150
              filterMode: 'empty',
151
              width: 12,
152
              height: '70%',
153
              handleSize: 8,
154
              showDataShadow: false,
155
              left: '98%'
156
            }
157
          ]
158
        })
159
      }
145
    },
160
    },
146
    initChart() {
161
    initChart() {
147
      for (var i = 1; i < this.chartData.length; i++) {
148
        this.addData()
149
      }
150
      this.chart = echarts.init(this.$el, 'macarons')
162
      this.chart = echarts.init(this.$el, 'macarons')
151
      this.setOptions(this.chartData)
163
      var that = this
164
      setTimeout(function() {
165
        that.setOptions(that.chartData)
166
      }, 1)
152
    }
167
    }
153
  }
168
  }
154
}
169
}

+ 0 - 186
src/views/bridgesConsole/lineChart/LineChart2.vue

1
<template>
2
  <div :class="className" :style="{height:height,width:width}"></div>
3
</template>
4
5
<script>
6
import echarts from 'echarts'
7
require('echarts/theme/macarons') // echarts theme
8
import { debounce } from '@/utils'
9
10
export default {
11
  props: {
12
    className: {
13
      type: String,
14
      default: 'chart'
15
    },
16
    width: {
17
      type: String,
18
      default: '100%'
19
    },
20
    height: {
21
      type: String,
22
      default: '350px'
23
    },
24
    autoResize: {
25
      type: Boolean,
26
      default: true
27
    },
28
    chartData: {
29
      type: Object
30
    },
31
    maxXcount: {
32
      type: Number
33
    },
34
    historyM: { // 判断是否需要坐标轴上的滚动条
35
      type: Boolean
36
    }
37
  },
38
  data() {
39
    return {
40
      chart: null
41
    }
42
  },
43
  mounted() {
44
    this.initChart()
45
    if (this.autoResize) {
46
      this.__resizeHanlder = debounce(() => {
47
        if (this.chart) {
48
          this.chart.resize()
49
        }
50
      }, 100)
51
      window.addEventListener('resize', this.__resizeHanlder)
52
    }
53
  },
54
  beforeDestroy() {
55
    if (!this.chart) {
56
      return
57
    }
58
    if (this.autoResize) {
59
      window.removeEventListener('resize', this.__resizeHanlder)
60
    }
61
62
    this.chart.dispose()
63
    this.chart = null
64
  },
65
  watch: {
66
    chartData: {
67
      deep: true,
68
      handler(val) {
69
        this.setOptions(val)
70
      }
71
    }
72
  },
73
  methods: {
74
    setOptions(datastr) {
75
      this.chart.setOption({
76
        title: {
77
          text: '传感器' + datastr.tit,
78
          textStyle: {
79
            color: '#333',
80
            fontSize: 14
81
          },
82
          left: 16
83
        },
84
        grid: {
85
          left: 10,
86
          right: 10,
87
          bottom: 20,
88
          top: 50,
89
          containLabel: true
90
        },
91
        tooltip: {
92
          trigger: 'axis',
93
          axisPointer: {
94
            type: 'cross'
95
          },
96
          padding: [5, 10]
97
        },
98
        xAxis: {
99
          data: datastr.xData,
100
          boundaryGap: false,
101
          axisTick: {
102
            show: false
103
          },
104
          max: this.maxXcount // x轴最多显示个数
105
        },
106
        yAxis: {
107
          type: 'value',
108
          axisLabel: {
109
            formatter: '{value} mv'
110
          },
111
          axisTick: {
112
            show: false
113
          }
114
        },
115
        legend: {
116
          data: ['最大值', '最小值']
117
        },
118
        series: [{
119
          name: '最大值', itemStyle: {
120
            normal: {
121
              color: '#FF005A',
122
              lineStyle: {
123
                color: '#FF005A',
124
                width: 2
125
              }
126
            }
127
          },
128
          smooth: true,
129
          type: 'line',
130
          data: datastr.seData.max,
131
          animationDuration: 2800,
132
          animationEasing: 'cubicInOut'
133
        }, {
134
          name: '最小值', itemStyle: {
135
            normal: {
136
              color: '#3888fa',
137
              lineStyle: {
138
                color: '#3888fa',
139
                width: 2
140
              }
141
            }
142
          },
143
          smooth: true,
144
          type: 'line',
145
          data: datastr.seData.min,
146
          animationDuration: 2800,
147
          animationEasing: 'cubicInOut'
148
        }]
149
      })
150
      if (this.historyM) {
151
        this.chart.setOption({
152
          dataZoom: [
153
            {
154
              type: 'slider',
155
              show: true,
156
              start: 94,
157
              end: 100,
158
              handleSize: 8
159
            },
160
            {
161
              type: 'inside',
162
              start: 94,
163
              end: 100
164
            },
165
            {
166
              type: 'slider',
167
              show: true,
168
              yAxisIndex: 0,
169
              filterMode: 'empty',
170
              width: 12,
171
              height: '70%',
172
              handleSize: 8,
173
              showDataShadow: false,
174
              left: '98%'
175
            }
176
          ]
177
        })
178
      }
179
    },
180
    initChart() {
181
      this.chart = echarts.init(this.$el, 'macarons')
182
      this.setOptions(this.chartData)
183
    }
184
  }
185
}
186
</script>