forked from drone/command-center-dashboard

chenyao
2025-03-31 295eb3cc87aaa5176d64a4ef985cdad0bfefae9a
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
<!-- 巡检任务数据 -->
<template>
    <common-title title="巡检任务详情" :style="{ marginLeft: pxToRem(14) }"></common-title>
    <div class="inspection-rask-details">
        <CommonDateTime :style="{ top: pxToRem(14),marginLeft: pxToRem(10) }"></CommonDateTime>
        <div class="chart-container" ref="chartRef"></div>
        <div class="pie-container" ref="pieRef"></div>
    </div>
</template>
 
<script setup>
import * as echarts from 'echarts';
import { pxToRem } from '@/utils/rem';
import CommonTitle from '@/components/CommonTitle.vue';
import CommonDateTime from '@/components/CommonDateTime.vue';
 
const chartRef = ref(null);
const pieRef = ref(null);
onMounted(() => {
    const chart = echarts.init(chartRef.value);
    const option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            top: '15%',
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        legend: {
            data: ['计划任务', '实际任务'],
            textStyle: {
                color: '#fff'
            }
        },
        xAxis: {
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月', '6月'],
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            axisLabel: {
                color: '#fff'
            }
        },
        yAxis: {
            type: 'value',
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            splitLine: {
                lineStyle: {
                    color: 'rgba(255, 255, 255, 0.1)'
                }
            },
            axisLabel: {
                color: '#fff'
            }
        },
        series: [
            {
                name: '计划任务',
                type: 'bar',
                barWidth: '20%',
                data: [10, 15, 20, 25, 30, 35],
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#1EE7E7' },
                        { offset: 1, color: 'rgba(30, 231, 231, 0.1)' }
                    ])
                }
            },
            {
                name: '实际任务',
                type: 'bar',
                barWidth: '20%',
                data: [15, 20, 25, 30, 35, 40],
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#0070FF' },
                        { offset: 1, color: 'rgba(0, 112, 255, 0.1)' }
                    ])
                }
            }
        ]
    };
    
    chart.setOption(option);
 
    const pieChart = echarts.init(pieRef.value);
    const pieOption = {
        tooltip: {
            trigger: 'item',
            formatter: '{b}: {c} ({d}%)'
        },
        legend: {
            orient: 'vertical',
            right: '5%',
            top: 'middle',
            textStyle: {
                color: '#fff',
                fontSize: 12
            },
            itemWidth: 10,
            itemHeight: 10,
            itemGap: 10,
            formatter: function(name) {
                let data = pieOption.series[0].data;
                let total = 0;
                let tarValue = 0;
                for (let i = 0; i < data.length; i++) {
                    total += data[i].value;
                    if (data[i].name === name) {
                        tarValue = data[i].value;
                    }
                }
                let percentage = ((tarValue / total) * 100).toFixed(1);
                return `${name} ${percentage}%`;
            }
        },
        series: [
            {
                name: '任务状态',
                type: 'pie',
                radius: ['10%', '90%'],
                center: ['35%', '50%'],  // 将图表向左偏移
                roseType: 'radius',
                itemStyle: {
                    borderRadius: 4
                },
                label: {
                    show: true,
                    position: 'inside',
                    formatter: '{c}%',
                    fontSize: 12,
                    color: '#fff'
                },
                data: [
                    { value: 30, name: '待审核', itemStyle: { color: '#1860EC' } },
                    { value: 25, name: '待处理', itemStyle: { color: '#47D107' } },
                    { value: 20, name: '已完成', itemStyle: { color: '#F29509' } },
                    { value: 15, name: '待分拨', itemStyle: { color: '#E9C81A' } },
                    { value: 18, name: '处理中', itemStyle: { color: '#0FC1E8' } },
                    { value: 18, name: '已完结', itemStyle: { color: '#FE577F' } }
                ]
            }
        ]
    };
    
    pieChart.setOption(pieOption);
    
    window.addEventListener('resize', () => {
        chart.resize();
        pieChart.resize();
    });
});
</script>
 
<style lang="scss" scoped>
.inspection-rask-details {
    margin-left: 29px;
    // padding: 16px 16px;
    width: 390px;
    height: 526px;
    background: linear-gradient(
        270deg,
        rgba(31, 62, 122, 0) 0%,
        rgba(31, 62, 122, 0.35) 21%,
        #1f3e7a 100%
    );
    border-radius: 0px 0px 0px 0px;
    opacity: 0.85;
    .chart-container {
        width: 100%;
        height: 220px;
        margin-top: 20px;
    }
    .pie-container {
        width: 100%;
        height: 212px;
        margin-top: 10px;
    }
}
</style>