forked from drone/command-center-dashboard

张含笑
2025-04-08 cbec4308b61d0147cd60abfcbbb90db24c4a8e7f
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
<template>
    <common-title title="行业数据分析" />
    <div class="chart" ref="echartsRef"></div>
</template>
<script setup>
import CommonTitle from '@/components/CommonTitle.vue'
import { getEventIndustryData } from '@/api/home/event'
import * as echarts from 'echarts'
 
const echartsRef = ref(null)
let chart = null
 
const echartsOption = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
        },
    },
    grid: {
        top: '5%',
        left: 0,
        right: 0,
        bottom: 0,
        containLabel: true,
    },
    xAxis: {
        type: 'category',
        axisLabel: {
            rotate: -45, // 旋转角度
            interval: 0, // 显示所有标签
            color: '#FFFFFF',
            fontFamily: 'Source Han Sans CN, Source Han Sans CN',
            fontWeight: 400,
            fontSize: 10,
        },
        data: [],
    },
    yAxis: [
        {
            type: 'value',
            axisLabel: {
                interval: 0, // 显示所有标签
                color: '#FFFFFF',
                fontFamily: 'Source Han Sans CN, Source Han Sans CN',
                fontWeight: 400,
                fontSize: 10,
            },
            axisLine: {
                lineStyle: {
                    color: '#ffffff',
                },
            },
            splitLine: {
                lineStyle: {
                    color: 'rgba(255, 255, 255, 0.1)',
                    type: 'dashed', // 设置为虚线
                },
            },
        },
    ],
    series: [],
}
 
const testObj = color => ({
    type: 'bar',
    emphasis: {
        focus: 'series',
    },
    itemStyle: { color },
    data: [],
})
 
const eventType = [
    { name: '事件', ...testObj('#6FCAFF') },
    { name: '任务', ...testObj('#8EFFAC') },
]
const params = inject('eventOverviewParams')
 
watch(params, () => {
    getData()
})
 
// 获取数据
const getData = async () => {
    const res = await getEventIndustryData(params.value)
    const list = res?.data?.data || []
    echartsOption.xAxis.data = list.map(item => item.name)
    //
    eventType.forEach(item => {
        item.data = []
    })
    list.forEach(item => {
        item.data.forEach(item1 => {
            eventType.forEach(item2 => {
                item2.name === item1.name && item2.data.push(item1.value)
            })
        })
    })
    echartsOption.series = eventType
    chart.setOption(echartsOption)
}
 
onMounted(() => {
    chart = echarts.init(echartsRef.value)
    window.addEventListener('resize', chart.resize)
    getData()
})
</script>
<style scoped lang="scss">
.chart {
    width: 356px;
    height: 190px;
}
</style>