fix: 修复样式和组件问题并增强数据图表功能

修复多个组件中的::v-deep语法错误和el-row的gutter属性绑定
将el-button的type="text"更新为link类型
在AppMain.vue中添加div包裹keep-alive以解决过渡问题
增强DataAnalysis组件的数据处理能力,添加计算属性和默认值
添加fetchChuRuKuCountBarData调用以完善库存管理功能
This commit is contained in:
re-JZzzz
2025-10-09 20:22:04 +08:00
parent 94cd3f867d
commit febbcb3241
8 changed files with 71 additions and 23 deletions

View File

@ -19,7 +19,7 @@
</template>
<script setup>
import { ref, onMounted, onUnmounted, watch } from 'vue';
import { ref, onMounted, onUnmounted, watch, computed } from 'vue';
import * as echarts from 'echarts';
// 定义props
@ -27,7 +27,6 @@ const props = defineProps({
lineData: {
type: Object,
default: () => ({
// 默认值,防止传入数据为空时图表显示异常
days: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
rukuCounnts: [5, 40, 20, 75, 60, 80, 40, 55, 30, 65, 5, 80],
chukuCounnts: [30, 40, 30, 30, 30, 15, 55, 50, 40, 60, 25, 90]
@ -36,8 +35,7 @@ const props = defineProps({
barData: {
type: Object,
default: () => ({
// 默认值,防止传入数据为空时图表显示异常
shebeiTypes: ['设备1', '设备2', '设备3', '设备4', '设备5'],
shebeiTypes: ['光伏组件', '逆变器', '汇流箱', '支架', '电缆'],
rukuCount: [5, 40, 20, 75, 60],
chukuCount: [30, 40, 30, 30, 30]
})
@ -52,6 +50,53 @@ const barChartRef = ref(null);
let lineChart = null;
let barChart = null;
// 计算属性处理传入的lineData确保数据有效
const processedLineData = computed(() => {
// 检查传入的数据是否有效
if (!props.lineData ||
!props.lineData.days ||
props.lineData.days.length === 0 ||
!Array.isArray(props.lineData.rukuCounnts) ||
!Array.isArray(props.lineData.chukuCounnts)) {
return {
days: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
rukuCounnts: [5, 40, 20, 75, 60, 80, 40, 55, 30, 65, 5, 80],
chukuCounnts: [30, 40, 30, 30, 30, 15, 55, 50, 40, 60, 25, 90]
};
}
// 检查rukuCounnts和chukuCounnts是否全为0
const isRukuAllZero = props.lineData.rukuCounnts.every(item => item === 0);
const isChukuAllZero = props.lineData.chukuCounnts.every(item => item === 0);
if (isRukuAllZero && isChukuAllZero) {
return {
days: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
rukuCounnts: [5, 40, 20, 75, 60, 80, 40, 55, 30, 65, 5, 80],
chukuCounnts: [30, 40, 30, 30, 30, 15, 55, 50, 40, 60, 25, 90]
};
}
return props.lineData;
});
// 计算属性处理传入的barData确保数据有效
const processedBarData = computed(() => {
// 检查传入的数据是否有效
if (!props.barData ||
!props.barData.shebeiTypes ||
props.barData.shebeiTypes.length === 0 ||
!Array.isArray(props.barData.rukuCount) ||
!Array.isArray(props.barData.chukuCount)) {
return {
shebeiTypes: ['光伏组件', '逆变器', '汇流箱', '支架', '电缆'],
rukuCount: [5, 40, 20, 75, 60],
chukuCount: [30, 40, 30, 30, 30]
};
}
return props.barData;
});
onMounted(() => {
// 初始化折线图
initLineChart();
@ -99,7 +144,7 @@ const initLineChart = () => {
},
xAxis: {
type: 'category',
data: props.lineData.days
data: processedLineData.value.days
},
yAxis: {
type: 'value'
@ -108,7 +153,7 @@ const initLineChart = () => {
{
name: '入库数量',
type: 'line',
data: props.lineData.rukuCounnts,
data: processedLineData.value.rukuCounnts,
symbol: 'none',
smooth: true,
lineStyle: {
@ -127,7 +172,7 @@ const initLineChart = () => {
{
name: '出库数量',
type: 'line',
data: props.lineData.chukuCounnts,
data: processedLineData.value.chukuCounnts,
symbol: 'none',
smooth: true,
lineStyle: {
@ -177,7 +222,7 @@ const initBarChart = () => {
},
xAxis: {
type: 'category',
data: props.barData.shebeiTypes,
data: processedBarData.value.shebeiTypes,
axisLabel: {
interval: 0, // 强制显示所有标签
rotate: 30, // 标签旋转30度
@ -193,7 +238,7 @@ const initBarChart = () => {
{
name: '入库数量',
type: 'bar',
data: props.barData.rukuCount,
data: processedBarData.value.rukuCount,
itemStyle: {
color: 'rgba(22, 93, 255, 1)' // 入库数量颜色
},
@ -204,7 +249,7 @@ const initBarChart = () => {
{
name: '出库数量',
type: 'bar',
data: props.barData.chukuCount,
data: processedBarData.value.chukuCount,
itemStyle: {
color: 'rgba(15, 198, 194, 1)' // 出库数量颜色
},
@ -228,8 +273,8 @@ const handleResize = () => {
}
};
// 监听lineData变化,更新折线
watch(() => props.lineData, () => {
// 监听数据变化,更新图
watch([() => props.lineData, () => props.barData], () => {
initLineChart();
initBarChart();
}, { deep: true });