<template>
|
<div class="machineNest">
|
<div class="nestTop">
|
<div class="card-title">
|
<img :src="jc1" alt="" />
|
<div class="cardtotal">
|
<p>机巢工单数量排名</p>
|
</div>
|
</div>
|
</div>
|
<div class="nestCenter">
|
<div class="chart" ref="echartsRef"></div>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import * as echarts from 'echarts';
|
import useEchartsResize from '@/hooks/useEchartsResize';
|
import jc1 from '@/assets/images/workbench/jc1.png';
|
import jc2 from '@/assets/images/workbench/jc2.png';
|
import { industryJobNumPieChart } from '@/api/home/index';
|
import { nextTick } from 'vue';
|
|
const echartsRef = ref(null);
|
let { chart: jcchart } = useEchartsResize(echartsRef);
|
const jcOrder = ref([]);
|
const props = defineProps({
|
dateSelect: {
|
type: String,
|
},
|
});
|
const params = reactive({
|
date_enum: props.dateSelect,
|
});
|
// 空数据计算
|
const isEmptyData = computed(() => {
|
return jcOrder.value.length === 0 ||
|
jcOrder.value.every(item => !item.name || item.value === 0)
|
})
|
// 图表初始化
|
const initChart = () => {
|
if (echartsRef.value && !jcchart.value) {
|
jcchart.value = echarts.init(echartsRef.value)
|
}
|
}
|
// 获取机巢事件数据
|
const getIndustryJobNumPieChart = () => {
|
industryJobNumPieChart(params).then(res => {
|
const resList = res?.data?.data || [];
|
jcOrder.value = resList;
|
nextTick(() => {
|
initChart()
|
pieInit(resList)
|
})
|
});
|
};
|
watch(
|
() => props.dateSelect,
|
newVal => {
|
params.date_enum = newVal;
|
getIndustryJobNumPieChart();
|
},
|
{ immediate: true }
|
);
|
const pieInit = resList => {
|
|
// if (!jcchart.value || !resList?.length) return
|
const validData = resList?.filter(item => item.name).sort((a, b) => b.value - a.value); // 从大到小排序
|
const colors = [
|
'#F87E04', // 橙色
|
'#FFC400', // 黄色
|
'#08BC44', // 绿色
|
'#07B5FF', // 蓝色
|
'#A98DFF', // 紫色
|
'#9ABFFF', // 浅蓝
|
];
|
|
const optionData = {
|
yAxisData: validData.map(item => item.name),
|
seriesData: validData.map(item => item.value),
|
};
|
|
|
const option = {
|
title: {
|
text: resList.length ? '' :'暂无数据',
|
left: 'center',
|
top: 'center',
|
textStyle: {
|
color: '#999',
|
fontSize: '1.6rem',
|
fontWeight: 'normal'
|
}
|
},
|
tooltip: {
|
trigger: 'axis',
|
axisPointer: { type: 'shadow' },
|
formatter: '{b}: {c}',
|
},
|
grid: {
|
left: '3%',
|
right: '4%',
|
bottom: '3%',
|
containLabel: true,
|
},
|
xAxis: {
|
type: 'value',
|
splitLine: { lineStyle: { color: '#E5E5E5' } },
|
axisLabel: { color: '#7C8091',fontSize:'1.2rem' },
|
boundaryGap: [0, 0.01],
|
},
|
yAxis: {
|
type: 'category',
|
data: optionData.yAxisData,
|
axisLabel: { color: '#7C8091' ,fontSize:'1.2rem'},
|
axisLine: { lineStyle: { color: '#D1D1D1' } },
|
axisTick: { show: false },
|
// 确保排序后的数据从上到下显示(最大值在顶部)
|
inverse: true,
|
show:optionData.seriesData?.length ? true : false
|
},
|
series: [
|
{
|
type: 'bar',
|
data: optionData.seriesData,
|
itemStyle: {
|
color: params => {
|
// 前6项使用固定颜色循环,之后使用渐变
|
return params.dataIndex < colors.length
|
? colors[params.dataIndex]
|
: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
|
{ offset: 0, color: '#93BAFF' },
|
{ offset: 1, color: '#C5DEFF' },
|
]);
|
},
|
},
|
barWidth: '30%',
|
label: {
|
show: true,
|
position: 'right',
|
formatter: '{c}',
|
},
|
},
|
],
|
};
|
|
jcchart.value.setOption(option, true);
|
};
|
|
onMounted(() => {
|
getIndustryJobNumPieChart();
|
});
|
onBeforeUnmount(() => {
|
if (jcchart.value) {
|
jcchart.value.dispose()
|
jcchart.value = null
|
}
|
})
|
</script>
|
|
<style scoped lang="scss">
|
.machineNest {
|
width: 100%;
|
.custom-text {
|
font-size: 14px;
|
color: #7c8091;
|
}
|
.nestTop {
|
.card-title {
|
display: flex;
|
margin-left: 57px;
|
margin-bottom: 15px;
|
align-items: center;
|
img {
|
width: 36px;
|
height: 40px;
|
}
|
}
|
.cardtotal {
|
display: flex;
|
align-items: center;
|
margin-left: 9px;
|
p {
|
font-weight: bold;
|
font-size: 14px;
|
color: #363636;
|
}
|
span {
|
font-weight: 400;
|
font-size: 14px;
|
color: #7c8091;
|
}
|
.total-number {
|
font-family: 'Source Han Sans CN';
|
font-weight: bold;
|
font-size: 32px;
|
color: #2a54ff;
|
}
|
}
|
.status-grid {
|
margin-left: 30px;
|
display: grid;
|
grid-template-columns: repeat(2, 1fr);
|
row-gap: 17px;
|
.status-item {
|
display: flex;
|
text-align: center;
|
align-items: center;
|
justify-content: center;
|
background: #f6f8fe;
|
margin-right: 10px;
|
padding: 10px;
|
img {
|
width: 40px;
|
height: 40px;
|
margin-right: 13px;
|
}
|
.status-label {
|
font-size: 14px;
|
color: #383838;
|
}
|
.status-value {
|
font-family: 'Source Han Sans CN';
|
font-weight: bold;
|
font-size: 20px;
|
}
|
}
|
}
|
}
|
.nestCenter {
|
width: 100%;
|
height: 600px;
|
.chart {
|
width: 100%;
|
height: 100%;
|
}
|
}
|
}
|
</style>
|