Browse Source

波形图随需求修改完善+

luyanan 6 years ago
parent
commit
00eabd1d1b

+ 14 - 0
src/api/bridgeInfo.js

@ -66,6 +66,20 @@ export function getMonitorByDay(params) {
66 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 83
export function getTimingMonitor(params) {
70 84
  return request({
71 85
    url: '/ajax/collect/wave/curr',

+ 1 - 1
src/utils/index.js

@ -15,7 +15,7 @@ export function urlParse(name) {
15 15
export function parseTime(startTime, flag, fa) {
16 16
  if (flag) {
17 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 19
    } else {
20 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

@ -0,0 +1,78 @@
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,7 +7,7 @@
7 7
      </div>
8 8
      <el-row class="line-chart-box">
9 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 11
        </el-col>
12 12
      </el-row>
13 13
      <div class="pagination-container">
@ -25,7 +25,7 @@
25 25
</template>
26 26
27 27
<script>
28
import { urlParse, parseTime } from '@/utils'
28
import { urlParse, parseTime, turnTime } from '@/utils'
29 29
import { getDangerDetail, setUnreadToRead } from '@/api/bridgeInfo'
30 30
import lineChart from '../lineChart/LineChart'
31 31
@ -38,7 +38,7 @@ export default {
38 38
      alarmList: [],
39 39
      pageSize: 6,
40 40
      pageNo: 1,
41
      intervalTime: 3 * 1000
41
      intervalTime: (3 * 1000) / 300
42 42
    }
43 43
  },
44 44
  components: {
@ -48,32 +48,47 @@ export default {
48 48
    this.alarmId = urlParse('aid')
49 49
    this.alarmTit = urlParse('msg')
50 50
    this.alarmRead = urlParse('flag')
51
    this.alarmTime = urlParse('_t')
51 52
    this.getDangerDetail()
52 53
    if (this.alarmRead === 'false') {
53 54
      this.setUnreadToRead()
54 55
    }
55 56
  },
56 57
  computed: {
57
    alarmTime() {
58
      const alramM = this.alarmId.split('_')
59
      return parseTime(alramM[ alramM.length - 1], true)
60
    },
61 58
    alarmShowList() {
62 59
      return this.alarmList.slice((this.pageNo - 1) * this.pageSize, this.pageNo * this.pageSize)
63 60
    }
64 61
  },
65 62
  methods: {
66 63
    getDangerDetail() {
64
      var that = this
67 65
      const param = {
68 66
        aid: this.alarmId
69 67
      }
70 68
      getDangerDetail(param).then(res => {
71 69
        if (res.success && res.data) {
70
          var rList = []
71
          var startTime = ''
72 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,7 +5,7 @@
5 5
        <span>报警信息</span>
6 6
      </div>
7 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 9
          <span>{{item.alarmTime}}</span>
10 10
          <span>{{item.device}},请点击查看。</span>
11 11
          <span class="svg-container" v-if="!item.readed">
@ -84,10 +84,10 @@ export default {
84 84
        }
85 85
      })
86 86
    },
87
    alarmShow(id, flag, msg) {
87
    alarmShow(id, flag, time, msg) {
88 88
      this.$router.replace({
89 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 93
    handleCurrentChange(val) {

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

@ -16,7 +16,7 @@
16 16
            <el-button type="text" @click="queryDangerInfo">查看全部</el-button>
17 17
          </div>
18 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 20
              <span>{{item.alarmTime}}</span>
21 21
              <span>{{item.device}},请点击查看。</span>
22 22
              <span class="svg-container" v-if="!item.readed">
@ -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" :maxXcount="maxShowLength"></lineChart2>
35
              <lineChart :chartData="item" :maxXcount="maxShowLength"></lineChart>
36 36
            </el-col>
37 37
          </el-row>
38 38
          <DefaultPage v-if="!monitorList.length"></DefaultPage>
@ -82,10 +82,11 @@ import '@/styles/roleuser.scss'
82 82
import Cookies from 'js-cookie'
83 83
import queryInfo from '@/utils/queryInfo'
84 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 90
import BInfoDialog01 from './components/BInfoDialog01'
90 91
import BInfoDialog02 from './components/BInfoDialog02'
91 92
import BInfoDialog03 from './components/BInfoDialog03'
@ -99,7 +100,7 @@ import DefaultPage from '@/components/DefaultPage'
99 100
export default {
100 101
  name: 'dashboard-other',
101 102
  components: {
102
    lineChart2,
103
    lineChart,
103 104
    BInfoDialog01,
104 105
    BInfoDialog02,
105 106
    BInfoDialog03,
@ -121,7 +122,8 @@ export default {
121 122
      monitorList: [],
122 123
      currentNo: 1,
123 124
      currentSize: 4,
124
      currentTime: turnTime(new Date(), 'time', true),
125
      currentTime: '',
126
      sysTime: '',
125 127
      setTime: null,
126 128
      maxShowLength: 300,
127 129
      monitorCache: []
@ -144,16 +146,14 @@ export default {
144 146
    if (this.bridgeId) {
145 147
      this.serverSeqArr = queryInfo.queryServers(this.bridgeId, true)
146 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 154
  methods: {
156
    getDangerList(arr) {
155
    getDangerList() {
156
      var arr = this.serverSeqArr
157 157
      const param = {
158 158
        seq: arr,
159 159
        pageSize: 5,
@ -172,64 +172,70 @@ export default {
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 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 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 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 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,10 +260,10 @@ export default {
254 260
    handleCurrentChange(val) {
255 261
      this.currentNo = val
256 262
    },
257
    alarmShow(id, flag, msg) {
263
    alarmShow(id, flag, time, msg) {
258 264
      this.$router.replace({
259 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 269
    queryDangerInfo() {
@ -287,7 +293,8 @@ export default {
287 293
    }
288 294
  },
289 295
  beforeDestroy() {
290
    clearInterval(this.setTime)
296
    clearTimeout(this.setTime)
297
    // clearInterval(this.setTime)
291 298
  }
292 299
}
293 300
</script>

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

@ -6,6 +6,7 @@
6 6
            v-model="valueDate"
7 7
            type="date"
8 8
            value-format="yyyyMMdd"
9
            :picker-options="pickerOptions0"
9 10
            @change="changeDate">
10 11
          </el-date-picker>
11 12
          <!-- <el-date-picker
@ -20,7 +21,7 @@
20 21
      </div>
21 22
      <el-row class="line-chart-box" v-if="alarmList.length">
22 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 25
        </el-col>
25 26
      </el-row>
26 27
      <DefaultPage v-if="!alarmList.length"></DefaultPage>
@ -43,9 +44,9 @@
43 44
import '@/styles/roleuser.scss'
44 45
import Cookies from 'js-cookie'
45 46
import queryInfo from '@/utils/queryInfo'
46
import { parseTime } from '@/utils'
47 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 51
import DefaultPage from '@/components/DefaultPage'
51 52
@ -54,16 +55,22 @@ export default {
54 55
    return {
55 56
      historyM: true,
56 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 64
      dateRange: '',
59 65
      serverSeqArr: [],
60 66
      alarmList: [],
67
      monitorCache: [],
61 68
      pageSize: 2,
62 69
      pageNo: 1
63 70
    }
64 71
  },
65 72
  components: {
66
    lineChart2,
73
    lineChart,
67 74
    DefaultPage
68 75
  },
69 76
  computed: {
@ -79,15 +86,17 @@ export default {
79 86
    }
80 87
  },
81 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 95
    getMonitorByDay() {
83 96
      var that = this
84 97
      var date = that.valueDate
85 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 100
        if (res.success && res.data) {
92 101
          var monitorList = []
93 102
          for (let i = 0; i < res.data.length; i++) {
@ -101,27 +110,27 @@ export default {
101 110
            }
102 111
            if (!monitorData) {
103 112
              monitorData = {
113
                tit: '',
104 114
                xData: [],
105
                seData: {
106
                  max: [],
107
                  min: []
108
                }
115
                seData: []
109 116
              }
110 117
              monitorList.push(monitorData)
111 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 125
          that.alarmList = monitorList
118
          console.log(that.alarmList)
119 126
        }
120 127
      })
121 128
    },
122 129
    changeDate(val) {
123 130
      this.valueDate = val
124
      this.getMonitorByDay()
131
      if (this.serverSeqArr.length) {
132
        this.getMonitorByDay()
133
      }
125 134
    },
126 135
    handleCurrentChange(val) {
127 136
      this.pageNo = val

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

@ -4,7 +4,6 @@
4 4
5 5
<script>
6 6
import echarts from 'echarts'
7
import { parseTime, turnTime } from '@/utils'
8 7
require('echarts/theme/macarons') // echarts theme
9 8
import { debounce } from '@/utils'
10 9
@ -24,30 +23,25 @@ export default {
24 23
    },
25 24
    height: {
26 25
      type: String,
27
      default: '260px'
26
      default: '350px'
28 27
    },
29 28
    autoResize: {
30 29
      type: Boolean,
31 30
      default: true
32 31
    },
33 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 36
      type: Number
37
    },
38
    historyM: { // 判断是否需要坐标轴上的滚动条
39
      type: Boolean
44 40
    }
45 41
  },
46 42
  data() {
47 43
    return {
48 44
      lineColorNow: this.lineColor % 2 === 0 ? '#FF005A' : '#3888fa',
49
      Ydate: [],
50
      nowTime: parseTime(this.startTime, true, true),
51 45
      chart: null
52 46
    }
53 47
  },
@ -61,10 +55,6 @@ export default {
61 55
      }, 100)
62 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 59
  beforeDestroy() {
70 60
    if (!this.chart) {
@ -74,9 +64,6 @@ export default {
74 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 67
    this.chart.dispose()
81 68
    this.chart = null
82 69
  },
@ -89,24 +76,21 @@ export default {
89 76
    }
90 77
  },
91 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 79
    setOptions(datastr) {
97 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 89
        grid: {
106 90
          left: 10,
107 91
          right: 10,
108 92
          bottom: 20,
109
          top: 30,
93
          top: 60,
110 94
          containLabel: true
111 95
        },
112 96
        tooltip: {
@ -116,17 +100,19 @@ export default {
116 100
          },
117 101
          padding: [5, 10]
118 102
        },
103
        xAxis: {
104
          data: datastr.xData,
105
          max: this.maxXcount // x轴最多显示个数
106
        },
119 107
        yAxis: {
120
          // name: '豪伏(-8192-8192)',
121
          axisTick: {
122
            show: false
123
          }
108
          name: '伏(mv)',
109
          type: 'value'
124 110
        },
125 111
        legend: {
126
          data: [this.legendName]
112
          data: ['波动值']
127 113
        },
128 114
        series: [{
129
          name: this.legendName, itemStyle: {
115
          name: '波动值', itemStyle: {
130 116
            normal: {
131 117
              color: this.lineColorNow,
132 118
              lineStyle: {
@ -137,18 +123,47 @@ export default {
137 123
          },
138 124
          smooth: true,
139 125
          type: 'line',
140
          data: datastr,
126
          data: datastr.seData,
141 127
          animationDuration: 2800,
142 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 161
    initChart() {
147
      for (var i = 1; i < this.chartData.length; i++) {
148
        this.addData()
149
      }
150 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,186 +0,0 @@
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>