无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
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
<!-- 任务算法统计 -->
<template>
    <div class="task-industry">
        <div class="title">机巢事件前五数量占比</div>
        <div class="chart" ref="chartRef"></div>
    </div>
</template>
 
<script setup>
import * as echarts from 'echarts'
import { industryJobNumPieChart } from '@/api/job/task'
import useEchartsResize from '@/hooks/useEchartsResize'
import { useStore } from 'vuex'
 
const store = useStore()
const chartRef = ref(null)
let { chart } = useEchartsResize(chartRef)
 
const option = {
    tooltip: {
        trigger: 'item',
        formatter: '{b}: {c} ({d}%)',
    },
    legend: {
        orient: 'horizontal',
        left: 'center',
        bottom: '2%',
        textStyle: {
            color: '#363636',
            fontSize: 12,
        },
        itemWidth: 2, // 减小图例标记的宽度
        itemHeight: 3, // 减小图例标记的高度
        itemGap: 8, // 减小图例项之间的间距
        formatter: '{name}', // 简化图例文本
    },
    series: [
        {
            name: '机巢事件统计',
            type: 'pie',
            // roseType: 'radius',
            radius: ['36%', '60%'],
            // center: ['50%', '45%'],
            // radius: '70%', // 设置饼图的半径
            center: ['50%', '36%'], // 调整饼图位置
            data: [],
            label: {
                show: true,
                position: 'outside',
                formatter: '{c}',
                fontSize: 12,
                color: '#000',
            },
            labelLine: {
                show: true,
                length: 10,
                length2: 10,
                lineStyle: {
                    color: '#000',
                },
            },
        },
    ],
}
 
// 获取机巢事件数据
const getIndustryJobNumPieChart = value => {
    industryJobNumPieChart(value).then(res => {
        if (res.data.code !== 0) return
        option.series[0].data = res.data.data
        // forEach(item => {
        //   const matchData = res.data.data.find(d => d.name === item.name);
        //   if (matchData) {
        //     item.value = matchData.value;
        //   }
        // });
        chart.value.setOption(option)
    })
}
 
const changeKey = inject('changeKey')
// 添加监听
watch(
  () => [store.state.task.taskSearchParams,changeKey.value],
  () => getIndustryJobNumPieChart(store.state.task.taskSearchParams),
  { deep: true }
)
 
 
onMounted(() => {
    getIndustryJobNumPieChart({ date_enum: 'TODAY' })
})
</script>
 
<style lang="scss" scoped>
.task-industry {
    width: 276px;
    height: 100%;
    background: #FFFFFF;
    border-radius: 8px 8px 8px 8px;
    margin-left: 10px;
 
    .title {
        font-family: Segoe UI, Segoe UI;
        padding: 10px 0 10px 16px;
        width: 160px;
        height: 18px;
        font-weight: bold;
        font-size: 16px;
        color: #363636;
        line-height: 18px;
    }
 
    .chart {
        width: 100%;
        height: 180px;
    }
}
</style>