吉安感知网项目-前端
chenyao
6 days ago c2e0774ce8fecf5ef512afa3ff6125fd2f5377b9
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
<template>
    <div class="deviceChart">
        <div class="titleBg">
            <span>出库去向统计</span>
        </div>
        <div class="chartBox" ref="chartRef"></div>
    </div>
</template>
 
<script setup>
import * as echarts from 'echarts'
import useEchartsResize from '@/hooks/useEchartsResize'
import { statisticalDeviceOutApi } from '@/views/basicManage/deviceStock/fwDevice'
 
const chartRef = ref(null)
let { chart } = useEchartsResize(chartRef)
 
const list = ref([])
function buildOption() {
    const names = list.value.map(item => item.type)
    const values = list.value.map(item => item.count)
    const hasData = values.length > 0
    const maxValue = values.length ? Math.max(...values) : 0
    const stepMax = maxValue === 0 ? 10 : Math.ceil(maxValue / 5) * 5
    const shadowData = values.map(() => stepMax)
 
    return {
        graphic: hasData
            ? []
            : [
                    {
                        type: 'text',
                        left: 'center',
                        top: 'middle',
                        style: {
                            text: '暂无数据',
                            fill: '#FFFFFF',
                            font: '14px Arial',
                            textAlign: 'center',
                            textVerticalAlign: 'middle',
                        },
                    },
              ],
        grid: {
            top: 15,
            left: 10,
            right: 10,
            bottom: 0,
            containLabel: true,
        },
        tooltip: {
            trigger: 'axis',
            backgroundColor: 'rgba(0,0,0,0.7)',
            borderColor: '#0070FF',
            borderWidth: 1,
            textStyle: {
                color: '#FFFFFF',
                fontSize: 14, // 也可以顺便调整字号
            },
            axisPointer: {
                type: 'shadow',
            },
            formatter: params => {
                const target = Array.isArray(params) ? params.find(item => item.seriesIndex === 1) : null
                return `${target?.name ?? ''}:${target?.value ?? 0}`
            },
        },
        xAxis: {
            type: 'category',
            data: names,
            axisLine: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                color: '#B4C0CC',
                fontSize: 12,
                interval: 0,
            },
        },
        yAxis: {
            type: 'value',
            max: Math.ceil(Math.max(...values) * 1.2),
            minInterval: 1,
            axisLabel: {
                color: '#B4C0CC',
                fontSize: 12,
            },
            axisLine: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: "rgba(93, 106, 143, .5)",
                    type: "dashed"
                }
            }
        },
        series: [
            {
                type: 'bar',
                data: shadowData,
                barWidth: 20,
                itemStyle: {
                    color: 'rgba(255,255,255,0.08)',
                },
                z: 0,
            },
            {
                type: 'bar',
                data: values,
                barWidth: 10,
                barGap: '-75%',
                showBackground: false,
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                        { offset: 1, color: '#0783FA' },
                        { offset: 0, color: 'rgba(0,85,255,0)' },
                    ]),
                },
                z: 1,
            },
            {
                type: 'pictorialBar',
                data: values,
                symbol: 'rect',
                symbolPosition: 'end',
                symbolSize: [10, 3],
                symbolOffset: [2.5, -2],
                itemStyle: {
                    color: '#6BB7FF',
                },
                z: 3,
            },
        ],
    }
}
 
onMounted(() => {
    statisticalDeviceOutApi().then(res => {
        list.value = Array.isArray(res?.data?.data) ? res.data.data : []
        chart.value.setOption(buildOption())
    })
})
</script>
 
<style scoped lang="scss">
.deviceChart {
    width: 638px;
}
.titleBg {
    width: 618px;
    height: 34px;
    background: url('@/assets/images/basicManage/chartBg2.svg') no-repeat center / 100% 100%;
}
</style>