wujingjing
2024-03-19 4d833fbb211c6c18694351ef9e4c8bb4f900aafd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
<template>
    <view>
        <!-- 顶部标题栏 -->
        <view class="title_style">
            <view class="deviceNav">
                <text class="cuIcon-sort" style="font-size: 44rpx;width: 10%;" @tap="showLeftDrawer"
                    data-target="DrawerModalL"></text>
                <!-- <text style="font-size: 32rpx;font-family: none;">{{deviceInfo.name}}</text> -->
                <view class="flex" style="flex-direction: column;width: 70%;">
                    <text style="font-size: 32rpx;font-family: none;">数据检测</text>
                    <!-- <text style="font-size: 18rpx;font-family: none;margin-top: 10rpx;">运行时间:{{runingDay}}天{{rungingHours}}小时</text> -->
                </view>
                <view class="flex align-center justify-around" style="width: 10%;">
                    <!-- 总数据图表跳转-->
                    <!-- <text class="iconfont icon-qushitu sum_chart" @tap="toHistorySumChart"
                        style="font-size: 44rpx;"></text> -->
                    <!-- 测试数据读写的弹框  不用的时候可以隐藏-->
                    <!-- <text class="iconfont icon-rizhi" @tap="testDilog" style="font-size: 44rpx;"></text> -->
                    <!-- 数据刷新按钮 -->
                    <text class="cuIcon-refresh" @tap="refreshDeviceDate" style="font-size: 44rpx;"></text>
                </view>
            </view>
            <view class="deviceName">
                <text class="title">上海义维</text>
                <text class="date">数据更新于&nbsp;{{lastUpdateTime}}</text>
            </view>
        </view>
 
 
        <!-- 实时数据总图表 -->
        <scroll-view scroll-y="true" style="height: calc(100vh - 243rpx);width: 100vw;background-color: #ffffff;">
            <view class="bg-white flex justify-center align-center"
                style="position: relative;background-color: #ffffff;width: 100%;height: 60%;">
                <uni-ec-canvas class="uni-ec-canvas" id="line-chart" ref="canvas" canvas-id="lazy-load-chart" :ec="ec">
                </uni-ec-canvas>
            </view>
            <view style="width: 100%;height:40%;">
                <view style="width: 100%;display: flex; justify-content: space-around;">
                    <view class="cu-capsule radius">
                        <view class="cu-tag" :class="valueFilterIndex==1?'bg-blue':'line-blue'"
                            @tap="valueFilterTap(1)"><text>均方根值</text></view>
                        <view class="cu-tag" :class="valueFilterIndex==2?'bg-blue':'line-blue'"
                            @tap="valueFilterTap(2)"><text>峭度值</text></view>
                    </view>
                    <view class="cu-capsule radius">
                        <view class="cu-tag" :class="timeFilter=='all'?'bg-blue':'line-blue'"
                            @tap="selectFilter('all')"><text>全部</text></view>
                        <view class="cu-tag" :class="timeFilter=='hours'?'bg-blue':'line-blue'"
                            @tap="selectFilter('hours')"><text>按小时</text></view>
                        <view class="cu-tag" :class="timeFilter=='day'?'bg-blue':'line-blue'"
                            @tap="selectFilter('day')"><text>按天</text></view>
                    </view>
                </view>
 
                <view>
                    <view class="cu-form-group margin-top chart-check "
                        style="min-height: 85rpx;justify-content: unset;">
                        <checkbox class="round radio blue" :checked="true" @click="changeCheckBox('X轴')"></checkbox>
                        <view class="title" style="margin-left: 20rpx;">x轴</view>
                    </view>
                    <view class="cu-form-group chart-check" style="min-height: 85rpx;justify-content: unset;">
                        <checkbox class="round radio green" :checked="true" @click="changeCheckBox('Y轴')"></checkbox>
                        <view class="title" style="margin-left: 20rpx;">y轴</view>
                    </view>
                    <view class="cu-form-group chart-check" style="min-height: 85rpx;justify-content: unset;">
                        <checkbox class="round radio orange" :checked="true" @click="changeCheckBox('Z轴')"></checkbox>
                        <view class="title" style="margin-left: 20rpx;">z轴</view>
                    </view>
                    <view class="cu-form-group chart-check" style="min-height: 85rpx;justify-content: unset;">
                        <checkbox class="round radio grey" :checked="true" @click="changeCheckBox('温度')"></checkbox>
                        <view class="title" style="margin-left: 20rpx;">温度</view>
                    </view>
                    <view class="cu-form-group chart-check" style="min-height: 85rpx;justify-content: unset;">
                        <icon class="cuIcon-time" style="font-size: 50rpx;"></icon>
                        <view class="title" style="margin-left: 20rpx;">时间</view>
                    </view>
                </view>
            </view>
        </scroll-view>
 
        <!-- 左侧菜单抽屉 -->
        <view class="cu-modal drawer-modal justify-start" style="z-index: 100;"
            :class="leftDrawerStatus==true?'show':''" @tap="hideLeftDrawer">
            <view class="cu-dialog basis-lg" style="max-width: 50%;background-color: #000;" @tap.stop="">
                <view class="cu-list menu text-left">
                    <view class="cu-item arrow" @tap="deviceList(item.click)"
                        style="min-height: 100rpx;min-height: 55px;background: #000;color: #fff;"
                        v-for="(item,index) in leftDrawerList" :key="index">
                        <view style="width: 50rpx;height: 50rpx;">
                            <text :class="'iconfont ' + item.icon" style="font-size: 50rpx;"></text>
                        </view>
                        <view class="content">
                            <view style="padding-left: 20rpx;"><text>{{item.text}}</text></view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
 
    </view>
</template>
 
<script>
    import uniEcCanvas from '../../component/uni-ec-canvas/uni-ec-canvas.vue'
    import * as echarts from '@/component/uni-ec-canvas/echarts'
    const Constant = require('../../utils/constant.js');
    const utils = require("../../utils/tool.js");
    const moment = require("../../utils/moment.js")
    let chart = null;
    let chartOption = {};
    export default {
        data() {
            return {
                baseInfo: null, //传入基本信息
                monitorData: [], //监测项的数据
                leftDrawerStatus: false, //左侧菜单显示状态
                lastUpdateTime: utils.formatTime(new Date()), //最后更新时间
                valueFilterIndex: 1,
                timeFilter: "all",
                legendSelected: {
                    "X轴": true,
                    "Y轴": true,
                    "Z轴": true,
                    "温度": true,
                },
                ec: {
                    lazyLoad: true,
                    option: {},
                },
                leftDrawerList: [{
                        text: '设备列表',
                        icon: 'icon-shebeiliebiao',
                        click: 'deviceList'
                    },
                    {
                        text: '趋势记录',
                        icon: 'icon-qushitu',
                        click: 'trendRecord'
                    },
                    {
                        text: '高级功能',
                        icon: 'icon-gaojigongneng',
                        click: 'advancedFeatures'
                    },
                    {
                        text: '诊断',
                        icon: 'icon-jiankangzhenduan'
                    },
                    {
                        text: '设备信息',
                        icon: 'icon-shebeixinxi',
                        click: 'equipmentSet'
                    },
                    {
                        text: '生产报告',
                        icon: 'icon-baogao'
                    },
                    {
                        text: 'FAQ',
                        icon: 'icon-FAQ'
                    },
                    {
                        text: '用户设置',
                        icon: 'icon-yonghu'
                    },
                ],
            }
        },
        components: {
            uniEcCanvas
        },
        onLoad(option) {
            let that = this
            let name = option.name
            let type = 'x_zdsd'
            let data = data = uni.getStorageSync(name)
            this.baseInfo = option
 
            console.log('123', option)
            let seriesData = this.formatterData();
 
 
            setTimeout(function() {
                that.$refs.canvas.init(that.initChart)
                that.initChartData(seriesData)
 
                let data = that.formatterData()
                that.ec.option.series = data
 
            }, 1000);
        },
        onReady() {},
        methods: {
            valueFilterTap(index) {
                this.valueFilterIndex = index
            },
            selectFilter(type) {
                this.timeFilter = type
            },
            showLeftDrawer: function() {
                this.leftDrawerStatus = true
            },
            hideLeftDrawer: function() {
                this.leftDrawerStatus = false
            },
            changeCheckBox(names) {
                this.ec.option.legend.data.forEach(item => {
                    if (names.includes(item)) {
                        this.legendSelected[item] = !this.legendSelected[item]
                        }
                })
 
                this.ec.option.legend.selected = this.legendSelected
            },
            deviceList: function(e) {
                if (e == 'deviceList') {
                    this.closeBLEConnection()
                    uni.redirectTo({
                        url: '../Connect/mainIndex'
                    })
                } else if (e == 'equipmentSet') {
                    clearInterval(timer)
                    let productName = this.deviceInfo.name
                    uni.navigateTo({
                        url: '../Setting/index?name=' + productName
                    })
                } else if (e == 'trendRecord') {
                    uni.reLaunch({
                        url: '../TrendRecord/index'
                    })
                } else if (e == 'advancedFeatures') {
                    uni.reLaunch({
                        url: '../AdvancedFeatures/index'
                    })
                } else {
                    return;
                }
            },
            formatterData: function() {
                let that = this
                let option = this.baseInfo
                let name = option.name
                // let data = uni.getStorageSync(name)
 
                let data = [{ //测试
                    "date": "2021-06-03 15:19:30",
                    "x_zdjsd": "2.64", //X轴振动加速度
                    "x_zdsd": "66.91", //X轴振动速度
                    "y_zdjsd": "1.12", //Y轴振动加速度
                    "y_zdsd": "5.87", //Y轴振动速度
                    "z_zdjsd": "0.18", //Z轴振动加速度
                    "z_zdsd": "0.08", //Z轴振动速度
                    "temperature": 28.9, //温度
                    "battery": 3.3, //电压
                }]
                let temperature = []
                let x_axis= []
                let y_axis= []
                let z_axis= []
                for (let i = 0; i < 15; i++) {
                    let axisnum = Math.floor(Math.random() * 200)
                    x_axis.push({
                        value: [this.getRandomDate(), axisnum]
                    })
                    y_axis.push({
                        value: [this.getRandomDate(), axisnum]
                    })
                    z_axis.push({
                        value: [this.getRandomDate(), axisnum]
                    })
                    let num = Math.floor(Math.random() * 100)
                    temperature.push({value:[this.getRandomDate(), num]})
                }
                let seriesData = [{
                        name: 'X轴',
                        type: 'line',
                        yAxisIndex: 0,
                        showSymbol: false,
                        smooth: true,
                        hoverAnimation: false,
                        data: x_axis,
                        lineStyle: { // 设置线条的style等
                            normal: {
                                color: '#0081ff', // 折线线条颜色:红色
                            },
                        },
 
                        itemStyle: {
                            // 设置线条上点的颜色(和图例的颜色)
                            normal: {
                                color: '#0081ff',
                            },
                        }
                    },
                    {
                        name: 'Y轴',
                        type: 'line',
                        yAxisIndex: 0,
                        showSymbol: false,
                        smooth: true,
                        hoverAnimation: false,
                        data: y_axis,
                        lineStyle: { // 设置线条的style等
                            normal: {
                                color: '#39b54a', // 折线线条颜色:红色
                            },
                        },
                        itemStyle: {
                            // 设置线条上点的颜色(和图例的颜色)
                            normal: {
                                color: '#39b54a',
                            },
                        }
                    },
 
                    {
                        name: 'Z轴',
                        type: 'line',
                        yAxisIndex: 0,
                        showSymbol: false,
                        smooth: true,
                        hoverAnimation: false,
                        data: z_axis,
                        lineStyle: { // 设置线条的style等
                            normal: {
                                color: '#f37b1d', // 折线线条颜色:红色
                            },
                        },
                        itemStyle: {
                            // 设置线条上点的颜色(和图例的颜色)
                            normal: {
                                color: '#f37b1d',
                            },
                        }
                    },
                    {
                        name: '温度',
                        type: 'line',
                        yAxisIndex: 1,
                        smooth: true,
                        showSymbol: false,
                        hoverAnimation: false,
                        data: temperature,
                        lineStyle: { // 设置线条的style等
                            normal: {
                                color: '#8799a3', // 
                            },
                        },
                        itemStyle: {
                            // 设置线条上点的颜色(和图例的颜色)
                            normal: {
                                color: '#8799a3',
                            },
                        }
                    },
                ]
 
                return seriesData;
            },
            //初始化图表
            initChart(canvas, width, height, canvasDpr) {
                // console.log(canvas, width, height, canvasDpr)
                chart = echarts.init(canvas, null, {
                    width: width,
                    height: height,
                    devicePixelRatio: canvasDpr
                })
                canvas.setChart(chart)
                chart.setOption(this.ec.option)
                return chart
            },
            //初始化图表数据
            initChartData: function(data) {
                let baseInfo = this.baseInfo;
 
                let option = {
                    title: {
                        text: baseInfo.monitorName,
                        left: "center"
 
                    },
                    tooltip: {
                        trigger: 'axis',
                        formatter: function(params) {
                            // console.log(params);
                            var params_record = params[0].data;
                            var date = new Date(params[0].axisValue);
                            let str = '';
                            str += date.getHours() + ':' + date.getMinutes() + ':' +
                                date.getSeconds() + '\n';
                            for (var i = 0; i < params.length; i++) {
                                let item = params[i];
                                if (i == params.length - 1) {
                                    str += item.seriesName + ':' + item.data.value[1]
                                } else {
                                    str += item.seriesName + ':' + item.data.value[1] +
                                        '\n'
                                }
                            }
                            return str;
                        },
                        axisPointer: {
                            // animation: false
                        }
                    },
                    legend: {
                        data: ['X轴', 'Y轴', 'Z轴', '温度'],
                        show: false,
                        selected: this.legendSelected
                    },
                    grid: {
                        containLabel: true,
                        x: '15',
                        y: '80',
                        x2: '15',
                        y2: '40'
                    },
                    xAxis: {
                        type: 'time',
                        splitLine: {
                            show: true,
                            lineStyle: {
                                type: 'dashed'
 
                            }
                        },
                        splitNumber: 3,
                        axisLabel: {
                            //color: '#fff',
                            formatter: function(v, index) {
                                var date = new Date(v);
                                return utils.formatTime(date);
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                // color: '#fff'
                            },
                        },
                    min:function(value){
                        return utils.formatTime(new Date(value.min))
                    },
                    max:function(value){
                        return utils.formatTime(new Date(value.max))
                    },
                    },
                    yAxis: [{
                            name: 'mm/s²',
                            nameLocation: 'end',
                            type: 'value',
                            // boundaryGap: [0, '100%'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    type: 'dashed'
                                }
                            },
                            axisLabel: {
                                //color: '#fff',
                            },
                            axisLine: {
                                lineStyle: {
                                    show: true,
                                    //color: '#fff'
                                },
 
                            },
                            min: 0,
                            max: 130,
                            // interval: 26,
                            scale: true
                        },
                        {
                            name: '℃',
                            nameLocation: 'end',
                            type: 'value',
                            position: "right",
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    type: 'dashed'
                                }
                            },
                            axisLabel: {
                                //color: '#fff',
 
                            },
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    //color: '#fff'
                                },
                            },
                            min: 0,
                            max: 100,
                            // interval: 20,
                            scale: true
                        },
                    ],
                    series: data
                };
                this.ec.option = option
 
 
            },
 
 
     getRandomDate() {
        return moment(new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * Math.floor((Math.random()*10000))).getTime()).format('YYYY-MM-DD HH:mm:ss');
    },
            //关闭低功耗蓝牙的连接
            closeBLEConnection: function() {
                uni.closeBLEConnection({
                    deviceId: this.deviceId,
                    success: (res) => {
                        console.log('蓝牙连接关闭', res)
                    },
                    fail: (err) => {
                        console.log('关闭蓝牙连接失败', err)
                    }
                })
            },
        }
    }
</script>
 
<style>
    @import url("/style/animation.css");
    @import url("/style/main.css");
    @import url("/style/icon.css");
    @import url("/style/iconfont.css");
 
    .uni-ec-canvas {
        width: 100%;
        height: 100%;
        display: block;
    }
 
    .title_style {
        width: 100%;
        height: 243rpx;
        text-align: center;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        flex-direction: column;
        color: #ffffff;
        border-bottom: 3rpx solid #c0c0c0;
        box-sizing: border-box;
    }
 
    .deviceNav {
        display: flex;
        height: 30%;
        width: 100%;
        background: #16b5cb;
        justify-content: space-between;
        align-items: center;
        padding: 0px 26rpx;
    }
 
    .deviceName {
        width: 100%;
        height: 70%;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        flex-direction: column;
        background-color: #f5f5f5;
    }
 
    .deviceName .title {
        margin: 25rpx auto;
        font-size: 48rpx;
        color: #000000;
    }
 
    .deviceName .date {
        color: #c1c2c3;
        font-size: 24rpx;
    }
 
    .chart-check checkbox::before {
        content: unset;
    }
</style>