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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<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="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%;display: flex;flex-direction: column;">
                <view style="width: 100%;height: 50%;">
                    <!-- 时域图表 -->
                    <uni-ec-canvas class="uni-ec-canvas" id="line-chart" ref="canvasTimeDomain"
                        canvas-id="lazy-load-chart" :ec="TimeDomainEc">
                    </uni-ec-canvas>
                </view>
                <!-- 频域图表 -->
                <view style="width: 100%;height: 50%;">
                    <uni-ec-canvas class="uni-ec-canvas" id="line-chart" ref="canvasFrequencyDomain"
                        canvas-id="lazy-load-chart" :ec="FrequencyDomainEc">
                    </uni-ec-canvas>
                </view>
            </view>
            <view style="width: 100%;height:40%;">
                <view style="width: 100%;margin-bottom: 15rpx;">
                    <view class="cu-capsule radius" style="width: 100%;justify-content: center;">
                        <view style="width: 40%;" class="cu-tag" :class="speedFilterIndex==1?'bg-blue':'line-blue'"
                            @tap="speedFilterTap(1)"><text>加速度</text></view>
                        <view style="width: 40%;" class="cu-tag" :class="speedFilterIndex==2?'bg-blue':'line-blue'"
                            @tap="speedFilterTap(2)"><text>速度</text></view>
                    </view>
                </view>
                <view style="width: 100%;display: flex; justify-content: center;">
                    <view class="cu-capsule radius" style="width: 40%;">
                        <view style="width: 33.33%;" class="cu-tag" :class="timeFilter=='all'?'bg-blue':'line-blue'"
                            @tap="selectFilter('all')"><text>赫兹</text></view>
                        <view style="width: 33.33%;" class="cu-tag" :class="timeFilter=='hours'?'bg-blue':'line-blue'"
                            @tap="selectFilter('hours')"><text>阶次</text></view>
                        <view style="width: 33.33%;" class="cu-tag" :class="timeFilter=='day'?'bg-blue':'line-blue'"
                            @tap="selectFilter('day')"><text>转速</text></view>
                    </view>
                    <view class="cu-capsule radius" style="width: 40%;">
                        <view style="width: 50%;" class="cu-tag" :class="valueFilterIndex==1?'bg-blue':'line-blue'"
                            @tap="valueFilterTap(1)"><text>普通</text></view>
                        <view style="width: 50%;" class="cu-tag" :class="valueFilterIndex==2?'bg-blue':'line-blue'"
                            @tap="valueFilterTap(2)"><text>对数</text></view>
                    </view>
                </view>
 
                <radio-group class="block" @change="changeRadio">
                    <view class="cu-form-group margin-top chart-check "
                        style="min-height: 85rpx;justify-content: unset;">
                        <radio class="round radio blue" checked value="x"></radio>
                        <view class="title" style="margin-left: 20rpx;">x轴</view>
                    </view>
                    <view class="cu-form-group chart-check" style="min-height: 85rpx;justify-content: unset;">
                        <radio class="round radio green" value="y"></radio>
                        <view class="title" style="margin-left: 20rpx;">y轴</view>
                    </view>
                    <view class="cu-form-group chart-check" style="min-height: 85rpx;justify-content: unset;">
                        <radio class="round radio orange" value="z"></radio>
                        <view class="title" style="margin-left: 20rpx;">z轴</view>
                    </view>
                </radio-group>
                <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>
        </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");
    let date = null
    let faquertDate = null
    let chartTimeDomain = null;
    let chartTimeDomainOption = {};
 
    let chartFrequencyDomain = null;
    let chartFrequencyDomainOption = {};
    export default {
        data() {
            return {
                baseInfo: null, //传入基本信息
                monitorData: [], //监测项的数据
                leftDrawerStatus: false, //左侧菜单显示状态
                lastUpdateTime: utils.formatTime(new Date()), //最后更新时间
                speedFilterIndex: 1,
                valueFilterIndex: 1,
                timeFilter: "all",
                currentRadioValue:"x",
                //时域
                TimeDomainEc: {
                    lazyLoad: true,
                    option: {},
                },
                //频域
                FrequencyDomainEc: {
                    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 ?? ""
            
            let seriesData = this.formatterData();
            let faquertData = this.formatterDataFaquery()
 
            setTimeout(function() {
                that.$refs.canvasTimeDomain.init(that.initTimeDomainChart)
                that.initTimeDomainChartData(seriesData)
            }, 1000);
 
            setTimeout(function() {
                that.$refs.canvasFrequencyDomain.init(that.initFrequencyDomainChart)
                that.initFrequencyDomainChartData(faquertData)
            }, 1500);
        },
        onReady() {},
        methods: {
            speedFilterTap(index) {
                this.speedFilterIndex = index
            },
            valueFilterTap(index) {
                this.valueFilterIndex = index
            },
            selectFilter(type) {
                this.timeFilter = type
            },
            changeRadio(e){
                this.currentRadioValue = e.detail.value
                
                this.TimeDomainEc.option.series = this.formatterData()
                this.FrequencyDomainEc.option.series = this.formatterDataFaquery()
            },
            showLeftDrawer: function() {
                this.leftDrawerStatus = true
            },
            hideLeftDrawer: function() {
                this.leftDrawerStatus = false
            },
            formatterData: function() {
                let that = this
                let colorMap = new Map()
                colorMap.set('x','#0081ff');
                colorMap.set('y','#39b54a');
                colorMap.set('z','#f37b1d');
                let currentLineColor = colorMap.get(that.currentRadioValue)
                
                let option = this.baseInfo
                let name = option.name
                
                let date = [Math.floor(Math.random() * 100) / 100]
                let data = [[Math.floor(Math.random() * 100) / 100, parseFloat((Math.random() * (1 - 0.99)).toFixed(3))]];
                for (let i = 1; i < 100; i++) {
                    date.push(Math.floor(Math.random() * 100) / 100);
                    data.push([Math.floor(Math.random() * 100) / 100, parseFloat((Math.random() * (1 - 0.99)).toFixed(3))]);
                }
                let seriesData = [{
                    name: 'Test Data',
                    type: 'line',
                    yAxisIndex: 0,
                    showSymbol: false,
                    smooth: true,
                    hoverAnimation: false,
                    data: data,
                    lineStyle: { // 设置线条的style等
                        normal: {
                            color: currentLineColor, // 折线线条颜色:红色
                        },
                    },
 
                    itemStyle: {
                        // 设置线条上点的颜色(和图例的颜色)
                        normal: {
                            color: currentLineColor,
                        },
                    }
                }]
 
                return seriesData;
            },
            
            formatterDataFaquery: function() {
                let that = this
                
                let colorMap = new Map()
                colorMap.set('x','#0081ff');
                colorMap.set('y','#39b54a');
                colorMap.set('z','#f37b1d');
                let currentLineColor = colorMap.get(that.currentRadioValue)
                
                let option = this.baseInfo
                let name = option.name
            
                let base = +new Date(1968, 9, 3);
                let oneDay = 24 * 3600 * 1000;
                faquertDate = [];
                let data = [[Math.floor(Math.random() * 2000),parseFloat((Math.random() * (1 - 0.9)).toFixed(3))]];
                for (let i = 1; i < 100; i++) {
                    faquertDate.push(Math.floor(Math.random() * 2000));
                    data.push([Math.floor(Math.random() * 2000), parseFloat((Math.random() * (1 - 0.9)).toFixed(3))]);
                }
                let seriesData = [{
                    name: 'Test Data',
                    type: 'line',
                    yAxisIndex: 0,
                    showSymbol: false,
                    symbol: 'none',
                    smooth:true,
                    hoverAnimation: false,
                    data: data,
                    lineStyle: { // 设置线条的style等
                        normal: {
                            color: currentLineColor, // 折线线条颜色:红色
                        },
                    },
            
                    itemStyle: {
                        // 设置线条上点的颜色(和图例的颜色)
                        normal: {
                            color: currentLineColor,
                        },
                    }
                }]
            
                return seriesData;
            },
            //初始化图表
            initTimeDomainChart(canvas, width, height, canvasDpr) {
                chartTimeDomain = echarts.init(canvas, null, {
                    width: width,
                    height: height,
                    devicePixelRatio: canvasDpr
                })
                canvas.setChart(chartTimeDomain)
                chartTimeDomain.setOption(this.TimeDomainEc.option)
                return chartTimeDomain
            },
            //初始化图表数据
            initTimeDomainChartData: function(data) {
                let baseInfo = this.baseInfo;
                chartTimeDomainOption = {
                    tooltip: {
                        trigger: 'axis',
                    },
                    grid: {
                        left: '15%',
                        top: '5%',
                        right: '5%',
                        bottom: '25%'
                    },
                    toolbox: {
                        feature: {
                            dataZoom: {
                                yAxisIndex: 'none'
                            },
                            restore: {},
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: 'value',
                        name: "时域(s)",
                        nameLocation: 'center',
                        nameGap: 30,
                        nameTextStyle: {
                            fontSize: 12,
                            fontWeight: 'normal'
                        },
                        boundaryGap: false,
                        splitLine: {
                            show: true,
                            lineStyle: {
                                type: 'line'
 
                            }
                        },
                        interval :0.1,
                        axisLine: {
                            onZero: false
                        },
                        axisLabel: {
                            formatter: function(value, index) {
                                return parseFloat(value).toFixed(2);
                            },
                             interval:1
                        },
                        min: 0.00,
                        max: 1.00
                    },
                    yAxis: {
                        type: 'value',
                        name: "g",
                        nameLocation: 'center',
                        nameGap: 42,
                        nameRotate: 0,
                        nameTextStyle: {
                            fontSize: 12,
                            fontWeight: 'normal'
                        },
                        boundaryGap: ['1%', '20%'],
                        splitLine: {
                            show: true,
                            lineStyle: {
                                type: 'line'
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                show: true,
                                //color: '#fff'
                            },
                            onZero: false
                        },
                        axisLabel: {
                            formatter: function(value, index) {
                                return parseFloat(value).toFixed(3);
                            }
                        },
                    },
                    series: data
                };
                this.TimeDomainEc.option = chartTimeDomainOption
            },
            //初始化图表
            initFrequencyDomainChart(canvas, width, height, canvasDpr) {
                // console.log(canvas, width, height, canvasDpr)
                chartFrequencyDomain = echarts.init(canvas, null, {
                    width: width,
                    height: height,
                    devicePixelRatio: canvasDpr
                })
                canvas.setChart(chartFrequencyDomain)
                chartFrequencyDomain.setOption(this.FrequencyDomainEc.option)
                return chartFrequencyDomain
            },
            //初始化图表数据
            initFrequencyDomainChartData: function(data) {
                chartFrequencyDomainOption = {
                    tooltip: {
                        trigger: 'axis',
                    },
                    grid: {
                        left: '15%',
                        top: '5%',
                        right: '5%',
                        bottom: '25%'
                    },
                    toolbox: {
                        feature: {
                            dataZoom: {
                                yAxisIndex: 'none'
                            },
                            restore: {},
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: 'value',
                        name: "频域(Hz)",
                        nameLocation: 'center',
                        nameGap: 25,
                        nameTextStyle: {
                            fontSize: 12,
                            fontWeight: 'normal'
                        },
                        boundaryGap: false,
                        splitLine: {
                            show: true,
                            lineStyle: {
                                type: 'line'
                            }
                        },
                        interval :200,
                        axisLine: {
                            onZero: false
                        },
                        
                    },
                    yAxis: {
                        type: 'value',
                        name: "mm/s",
                        nameLocation: 'center',
                        nameGap: 42,
                        // nameRotate: 0,
                        nameTextStyle: {
                            fontSize: 12,
                            fontWeight: 'normal'
                        },
                        boundaryGap: [0, '100%'],
                        splitLine: {
                            show: true,
                            lineStyle: {
                                type: 'line'
                            }
                        },
                        interval :0.02,
                        axisLine: {
                            lineStyle: {
                                show: true,
                                //color: '#fff'
                            },
                            onZero: false
                        },
                        axisLabel: {
                            formatter: function(value, index) {
                                return parseFloat(value).toFixed(2);
                            },
                             interval:1
                        },
                    },
                    series: data
                };
                this.FrequencyDomainEc.option = chartFrequencyDomainOption
            },
            //关闭低功耗蓝牙的连接
            async closeBLEConnection() {
                await uni.closeBLEConnection({
                    deviceId: this.deviceId,
                    success: (res) => {
                        console.log('蓝牙连接关闭', res)
                    },
                    fail: (err) => {
                        console.log('关闭蓝牙连接失败', err)
                    }
                })
            },
            //左侧菜单列表
            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;
                }
                }
        }
    }
</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>