yangys
2025-11-18 831cfa4c439c6d073d706a82d2a439f8b1818498
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
<!--
 * @Date: 2024-04-18 21:52:18
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-12-20 14:56:14
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/components/TimeAlarm.vue
-->
<template>
    <div ref="processCharts" style="width: 100%;height:80px;" id="record"></div>
</template>
 
<script>
import * as echarts from 'echarts';
import T from '@/components/scEcharts/echarts-theme-T.js';
import moment from 'moment'
export default {
    data() {
        return {
            option: {
                tooltip: {
                    trigger: 'axis',
                    position: 'bottom',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                grid: {
                    left: 0,
                    right: 0,
                    width: "100%"
                },
                xAxis: {
                    type: 'value',
                    interval: 0.05,
                    axisLabel: {
                        show: false,
                        margin: 0
                    },
                    splitLine: {
                        show: false
                    },
                    minorSplitLine: {
                        show: false
                    },
                    splitArea: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    }
                    // "type": "value",
                    // "interval": 0.05,
                    // "axisLabel": {
 
                    // }
                },
                yAxis: {
                    type: 'category',
                    data: [''],
                    show: false
                },
                series: []
            }
        }
    },
    props: ['index','tableData'],
    methods: {
        getTableData(id) {
            this.$HTTP.get(`/api/workinghour/working-process`, {id}).then(res => {
                if (res.code === 200) {
                    if(res.data.length == 0) return;
                    var timeRange = {};
                    timeRange.startTime = res.data[0].startTime;
                    timeRange.endTime = res.data[res.data.length - 1].endTime;
                    var total = Math.abs(moment(timeRange.startTime).diff(moment(timeRange.endTime)));
                    var start = timeRange.startTime;
                    var arr = [];
                    res.data.map((item, i) => {
                        var current = Math.abs(moment(start).diff(moment(item.endTime)))
                        start = item.endTime;
                        //console.log(current / total,'百分比')
                        if(item.deviceStatus == "2") {
                            item.deviceStatusName = "运行";
                            item.color = "#307f45";
                        }else {
                            item.deviceStatusName = "待机";
                            item.color = "#fdff85";
                        }
                        var obj = {name: item.deviceStatusName,type: 'bar',stack: 'total',barWidth: "20px",data: [current / total],itemStyle: {color: item.color},"tooltip": {
                                "trigger": "item",
                                formatter: (value, ticket) => {
                                    return `${item.deviceStatusName}: ${item.startTime} - ${item.endTime}<br />程序名称: ${item.progName}`;
                                }
                        }};
                        arr.push(obj);
                    })
                    this.option.series = arr;
                    var recordDom = this.$refs.processCharts;
                    var myChart = echarts.init(recordDom);
                    myChart.setOption(this.option);
                }
            })
        }
    },
    mounted() {
        var id = this.tableData[this.index - 1].id;
        this.getTableData(id);
    },
}
</script>
 
<style lang="scss" scoped></style>