添加近1月时间范围选项,优化历史数据图表调试日志

master
huangjinysf 3 months ago
parent ce0c6f0588
commit 96db660ae1

@ -116,11 +116,13 @@
<!-- 右侧历史数据图表 -->
<div class="history-chart-panel">
<div class="chart-controls">
<div class="detail-title">历史数据分析</div>
<el-select v-model="selectedTimeRange" @change="onTimeRangeChange" style="width: 120px">
<el-option label="近1天" value="近1天" />
<el-option label="近3天" value="近3天" />
<el-option label="近1周" value="近1周" />
<el-option label="近1月" value="近1月" />
</el-select>
</div>
@ -408,7 +410,7 @@ const selectedEquipmentCode = ref('');
//
const historyDataLoading = ref(false);
const historyData = ref([]);
const selectedTimeRange = ref('近1');
const selectedTimeRange = ref('近1');
const activeChartTab = ref('totalNumber');
const hasHistoryData = ref(false);
@ -424,30 +426,25 @@ let totalGrossWeightChart = null;
//
const showAxleDetails = (record, equipmentCode) => {
console.log('显示轴详情对话框, record:', record);
selectedAxle.value = { ...record };
selectedEquipmentCode.value = equipmentCode;
dialogVisible.value = true;
// 线
if (record.update_time && record.specification && record.wire_disc) {
console.log('获取历史数据, model:', record.model, 'specification:', record.specification, 'wire_disc:', record.wire_disc);
fetchHistoryData(record.model, record.specification, record.wire_disc);
} else {
console.log('不获取历史数据, update_time:', record.update_time, 'specification:', record.specification, 'wire_disc:', record.wire_disc);
hasHistoryData.value = false;
}
//
nextTick(() => {
console.log('初始化图表');
initCharts();
});
};
//
const handleClose = () => {
console.log('关闭对话框');
dialogVisible.value = false;
//
if (totalNumberChart) {
@ -466,18 +463,15 @@ const handleClose = () => {
//
watch(dialogVisible, (newValue) => {
console.log('对话框状态变化:', newValue);
if (newValue) {
//
setTimeout(() => {
console.log('对话框打开,延迟初始化图表');
initCharts();
//
if (hasHistoryData.value && historyData.value.length > 0) {
//
setTimeout(() => {
console.log('对话框打开,延迟更新图表');
updateCharts();
}, 300);
}
@ -487,7 +481,6 @@ watch(dialogVisible, (newValue) => {
//
const onTimeRangeChange = () => {
console.log('时间范围改变, 新范围:', selectedTimeRange.value);
if (selectedAxle.value && selectedAxle.value.update_time &&
selectedAxle.value.specification && selectedAxle.value.wire_disc) {
fetchHistoryData(
@ -500,33 +493,25 @@ const onTimeRangeChange = () => {
//
const handleTabClick = (tab) => {
console.log('选项卡切换, 当前选项卡:', tab.props.name);
// 使setTimeoutDOM
setTimeout(() => {
if (tab.props.name === 'totalNumber' && !totalNumberChart && totalNumberChartRef.value) {
console.log('选项卡切换时初始化总箱数图表');
totalNumberChart = echarts.init(totalNumberChartRef.value);
updateCharts();
} else if (tab.props.name === 'totalNetWeight' && !totalNetWeightChart && totalNetWeightChartRef.value) {
console.log('选项卡切换时初始化总净重图表');
totalNetWeightChart = echarts.init(totalNetWeightChartRef.value);
updateCharts();
} else if (tab.props.name === 'totalGrossWeight' && !totalGrossWeightChart && totalGrossWeightChartRef.value) {
console.log('选项卡切换时初始化总毛重图表');
totalGrossWeightChart = echarts.init(totalGrossWeightChartRef.value);
updateCharts();
}
//
if (tab.props.name === 'totalNumber' && totalNumberChart) {
console.log('重新渲染总箱数图表');
totalNumberChart.resize();
} else if (tab.props.name === 'totalNetWeight' && totalNetWeightChart) {
console.log('重新渲染总净重图表');
totalNetWeightChart.resize();
} else if (tab.props.name === 'totalGrossWeight' && totalGrossWeightChart) {
console.log('重新渲染总毛重图表');
totalGrossWeightChart.resize();
}
}, 100);
@ -534,45 +519,33 @@ const handleTabClick = (tab) => {
//
const fetchHistoryData = (model, specification, wireDisc) => {
console.log('开始获取历史数据, model:', model, 'specification:', specification, 'wireDisc:', wireDisc);
historyDataLoading.value = true;
//
const dateRange = getDateRangeByTimeRange(selectedTimeRange.value);
console.log('日期范围:', dateRange);
// API URL
let apiUrl = `${API_CONFIG.BASE_URL}/api/plan/wms/history?model=${model}&specification=${specification}&wire_disc=${wireDisc}&start_date=${dateRange.start_date}&end_date=${dateRange.end_date}`;
console.log('API URL:', apiUrl);
fetch(apiUrl)
.then(response => {
console.log('API响应状态:', response.status);
return response.json();
})
.then(response => response.json())
.then(data => {
console.log('API响应数据:', data);
if (data.code === 200 && data.data && data.data.records) {
historyData.value = data.data.records;
hasHistoryData.value = historyData.value.length > 0;
console.log('历史数据获取成功, 记录数:', historyData.value.length);
if (hasHistoryData.value) {
console.log('准备更新图表');
// 使setTimeoutDOM
setTimeout(() => {
console.log('延迟初始化图表');
initCharts();
//
setTimeout(() => {
console.log('延迟更新图表');
updateCharts();
}, 300);
}, 300);
}
} else {
console.log('历史数据格式不正确或无记录');
historyData.value = [];
hasHistoryData.value = false;
}
@ -589,11 +562,6 @@ const fetchHistoryData = (model, specification, wireDisc) => {
//
const initCharts = () => {
console.log('初始化图表开始');
console.log('totalNumberChartRef.value:', totalNumberChartRef.value);
console.log('totalNetWeightChartRef.value:', totalNetWeightChartRef.value);
console.log('totalGrossWeightChartRef.value:', totalGrossWeightChartRef.value);
//
if (totalNumberChart) {
totalNumberChart.dispose();
@ -610,34 +578,21 @@ const initCharts = () => {
//
if (totalNumberChartRef.value) {
console.log('初始化总箱数图表');
totalNumberChart = echarts.init(totalNumberChartRef.value);
} else {
console.error('totalNumberChartRef.value不存在');
}
if (totalNetWeightChartRef.value) {
console.log('初始化总净重图表');
totalNetWeightChart = echarts.init(totalNetWeightChartRef.value);
} else {
console.error('totalNetWeightChartRef.value不存在');
}
if (totalGrossWeightChartRef.value) {
console.log('初始化总毛重图表');
totalGrossWeightChart = echarts.init(totalGrossWeightChartRef.value);
} else {
console.error('totalGrossWeightChartRef.value不存在');
}
console.log('初始化图表结束, totalNumberChart:', totalNumberChart, 'totalNetWeightChart:', totalNetWeightChart, 'totalGrossWeightChart:', totalGrossWeightChart);
};
//
const updateCharts = () => {
console.log('更新图表开始, historyData.value:', historyData.value);
if (!historyData.value || historyData.value.length === 0) {
console.log('无历史数据,不更新图表');
return;
}
@ -651,34 +606,21 @@ const updateCharts = () => {
const totalNetWeightData = historyData.value.map(item => item.total_net_weight);
const totalGrossWeightData = historyData.value.map(item => item.total_gross_weight);
console.log('准备好的数据:', {
timeData,
totalNumberData,
totalNetWeightData,
totalGrossWeightData
});
//
nextTick(() => {
console.log('在nextTick中更新图表');
//
if (!totalNumberChart && totalNumberChartRef.value) {
console.log('重新初始化总箱数图表');
totalNumberChart = echarts.init(totalNumberChartRef.value);
}
if (!totalNetWeightChart && totalNetWeightChartRef.value) {
console.log('重新初始化总净重图表');
totalNetWeightChart = echarts.init(totalNetWeightChartRef.value);
}
if (!totalGrossWeightChart && totalGrossWeightChartRef.value) {
console.log('重新初始化总毛重图表');
totalGrossWeightChart = echarts.init(totalGrossWeightChartRef.value);
}
//
if (totalNumberChart) {
console.log('更新总箱数图表');
const totalNumberOption = {
title: {
text: '总箱数变化趋势',
@ -719,15 +661,11 @@ const updateCharts = () => {
}
}]
};
console.log('设置总箱数图表选项');
totalNumberChart.setOption(totalNumberOption, true); // true
} else {
console.error('总箱数图表实例不存在');
}
//
if (totalNetWeightChart) {
console.log('更新总净重图表');
const totalNetWeightOption = {
title: {
text: '总净重变化趋势',
@ -773,15 +711,11 @@ const updateCharts = () => {
}
}]
};
console.log('设置总净重图表选项');
totalNetWeightChart.setOption(totalNetWeightOption, true); // true
} else {
console.error('总净重图表实例不存在');
}
//
if (totalGrossWeightChart) {
console.log('更新总毛重图表');
const totalGrossWeightOption = {
title: {
text: '总毛重变化趋势',
@ -827,13 +761,8 @@ const updateCharts = () => {
}
}]
};
console.log('设置总毛重图表选项');
totalGrossWeightChart.setOption(totalGrossWeightOption, true); // true
} else {
console.error('总毛重图表实例不存在');
}
console.log('图表更新完成');
});
};
</script>

Loading…
Cancel
Save