This commit is contained in:
‘937886381’
2025-11-24 14:10:46 +08:00
parent dfa4ff3f54
commit 694beb5851
54 changed files with 1612 additions and 2290 deletions

View File

@@ -5,7 +5,7 @@
<div class="kpi-content" style="padding: 14px 16px; display: flex;flex-direction: column; width: 100%;">
<!-- 2. .top 保持 flex无需固定高度自动跟随子元素拉伸 -->
<div style="display: flex; width: 100%; background-color: rgba(249, 252, 255, 1);">
<costBaseBarChart />
<costBaseBarChart :formattedList="formattedList" :seriesData="seriesData" :name="'消耗量' " :xData="xData" />
</div>
</div>
</Container>
@@ -21,162 +21,79 @@ export default {
components: { Container, costBaseBarChart },
// mixins: [resize],
props: {
leftEqInfoData: { // 接收父组件传递的设备数据数组
consumptionList: {
type: Array,
default: () => [] // 默认空数组,避免报错
default: () => []
},
name: { // 接收父组件传递的设备数据数组
name: {
type: String,
default: () => '' // 默认空数组,避免报错
default: ''
},
productionOverviewVo: { // 恢复生产概览数据(原代码注释了,需根据实际需求保留)
dateData: {
type: Object,
default: () => ({})
}
},
data() {
return {
chart: null,
parentItemList: [
{ unit: "利润总额", targetValue: 16, currentValue: 14.5, progress: 90 },
{ unit: "毛利率", targetValue: 16, currentValue: 15.2, progress: 85 },
{ unit: "单价", targetValue: 20, currentValue: 16, progress: 80 },
{ unit: "净价", targetValue: 20, currentValue: 16, progress: 80 },
{ unit: "销量", targetValue: 20, currentValue: 16, progress: 80 },
{ unit: "双镀面板", targetValue: 15, currentValue: 13.8, progress: 92 },
{ unit: "溢价产品销量", targetValue: 15, currentValue: 13.8, progress: 92 }
]
formattedList: [], // 格式化后的完整数据含处理后的time
seriesData: [], // value数组
xData: [] // 新增:存储格式化后的时间数组
}
},
watch: {
productionOverviewVo: {
handler(newValue, oldValue) {
this.updateChart()
'dateData.mode': {
handler() {
this.formatList()
},
deep: true // 若对象内属性变化需触发,需加 deep: true
immediate: true
},
consumptionList: {
handler() {
this.formatList()
},
deep: true
}
},
mounted() {
// 初始化图表(若需展示图表,需在模板中添加对应 DOM
// this.$nextTick(() => this.updateChart())
},
beforeDestroy() {
// 销毁图表,避免内存泄漏
if (this.chart) {
this.chart.dispose()
this.chart = null
}
},
methods: {
updateChart() {
// 注意:原代码中图表依赖 id 为 "productionStatusChart" 的 DOM需在模板中补充否则会报错
// 示例:在 Container 内添加 <div id="productionStatusChart" style="height: 200px;"></div>
if (!document.getElementById('productionStatusChart')) return
formatList() {
const { mode } = this.dateData
const flatList = this.consumptionList.flat().filter(item => item.time) // 扁平化+过滤无效数据
if (this.chart) this.chart.dispose()
this.chart = echarts.init(document.getElementById('productionStatusChart'))
// 处理数据同时提取formattedTime、value
this.formattedList = flatList.map(item => ({
...item,
formattedTime: this.formatTime(item.time, mode)
}))
const data = [
this.productionOverviewVo.input || 0,
this.productionOverviewVo.output || 0,
this.productionOverviewVo.ng || 0,
this.productionOverviewVo.lowValue || 0,
this.productionOverviewVo.scrap || 0,
this.productionOverviewVo.inProcess || 0,
this.productionOverviewVo.engineer || 0
]
// 提取value数组原逻辑不变
this.seriesData = this.formattedList.map(item => item.value)
const option = {
type: 'bar',
grid: { left: 51, right: 40, top: 50, bottom: 45 },
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' },
className: 'production-status-chart-tooltip'
},
xAxis: {
type: 'category',
offset: 8,
data: ['投入', '产出', '待判', '低价值', '报废', '在制', '实验片'],
axisTick: { show: false },
axisLine: { show: true, onZero: false, lineStyle: { color: '#00E8FF' } },
axisLabel: {
color: 'rgba(255,255,255,0.7)',
fontSize: 12,
interval: 0,
width: 38,
overflow: 'break'
}
},
yAxis: {
type: 'value',
name: '单位/片',
nameTextStyle: { color: 'rgba(255,255,255,0.7)', fontSize: 14, align: 'left' },
min: () => 0,
max: (value) => Math.ceil(value.max),
scale: true,
axisTick: { show: false },
axisLabel: { color: 'rgba(255,255,255,0.7)', fontSize: 12 },
splitLine: { lineStyle: { color: 'RGBA(24, 88, 100, 0.6)', type: 'dashed' } },
axisLine: { show: true, lineStyle: { color: '#00E8FF' } }
},
series: [
{
type: 'pictorialBar',
label: { show: true, position: 'top', distance: -3, color: '#89CDFF', fontSize: 11 },
symbolSize: [20, 8],
symbolOffset: [0, 5],
z: 20,
itemStyle: {
borderColor: '#3588C7',
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'RGBA(22, 89, 98, 1)' },
{ offset: 1, color: '#3588C7' }
])
},
data: data
},
{
type: 'bar',
barWidth: 20,
itemStyle: {
borderWidth: 1,
borderColor: '#3588C7',
opacity: 0.8,
color: {
x: 0, y: 0, x2: 0, y2: 1,
type: 'linear',
global: false,
colorStops: [
{ offset: 0, color: 'rgba(73,178,255,0)' },
{ offset: 0.5, color: 'rgba(0, 232, 255, .5)' },
{ offset: 1, color: 'rgba(0, 232, 255, 1)' }
]
}
},
tooltip: { show: false },
data: data
},
{
type: 'pictorialBar',
symbolSize: [20, 8],
symbolOffset: [0, -4],
z: 12,
symbolPosition: 'end',
itemStyle: {
borderColor: 'rgba(0, 232, 255, 1)',
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'RGBA(22, 89, 98, 1)' },
{ offset: 1, color: '#3588C7' }
])
},
tooltip: { show: false },
data: data
}
]
// 新增提取格式化后的时间到timeArray与valueArray顺序一一对应
this.xData = this.formattedList.map(item => item.formattedTime)
},
formatTime(timestamp, mode) {
const date = new Date(timestamp)
const padZero = (num) => num.toString().padStart(2, '0')
switch (mode) {
case 1:
// mode=1时分秒HH:MM:SS
return `${padZero(date.getHours())}:${padZero(date.getMinutes())}:${padZero(date.getSeconds())}`
case 2:
// mode=2月日MM-DD
return `${padZero(date.getMonth() + 1)}-${padZero(date.getDate())}`
case 3:
// mode=3YYYY
return date.getFullYear().toString()
default:
return `${padZero(date.getMonth() + 1)}-${padZero(date.getDate())}`
}
this.chart.setOption(option)
}
}
}