mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 00:02:51 +08:00
!151 fix: 柱状图组件动态数据发送请求后,配置会被覆盖成默认配置问题
Merge pull request !151 from szy/fix/bar
This commit is contained in:
commit
9fd408e8ef
@ -1,15 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-chart
|
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option" :manual-update="isPreview()"
|
||||||
ref="vChartRef"
|
|
||||||
:init-options="initOptions"
|
|
||||||
:theme="themeColor"
|
|
||||||
:option="option"
|
|
||||||
:manual-update="isPreview()"
|
|
||||||
:update-options="{
|
:update-options="{
|
||||||
replaceMerge: replaceMergeArr
|
replaceMerge: replaceMergeArr
|
||||||
}"
|
}" autoresize></v-chart>
|
||||||
autoresize
|
|
||||||
></v-chart>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@ -62,11 +55,20 @@ watch(
|
|||||||
if (!isObject(newData) || !('dimensions' in newData)) return
|
if (!isObject(newData) || !('dimensions' in newData)) return
|
||||||
if (Array.isArray(newData?.dimensions)) {
|
if (Array.isArray(newData?.dimensions)) {
|
||||||
const seriesArr = []
|
const seriesArr = []
|
||||||
for (let i = 0; i < newData.dimensions.length - 1; i++) {
|
// 对oldData进行判断,防止传入错误数据之后对旧维度判断产生干扰
|
||||||
seriesArr.push(cloneDeep(seriesItem))
|
// 此处计算的是dimensions的Y轴维度,若是dimensions.length为0或1,则默认为1,排除X轴维度干扰
|
||||||
|
const oldDimensions = Array.isArray(oldData?.dimensions)&&oldData.dimensions.length >= 1 ? oldData.dimensions.length : 1;
|
||||||
|
const newDimensions = newData.dimensions.length >= 1 ? newData.dimensions.length : 1;
|
||||||
|
const dimensionsGap = newDimensions - oldDimensions;
|
||||||
|
if (dimensionsGap < 0) {
|
||||||
|
props.chartConfig.option.series.splice(newDimensions - 1)
|
||||||
|
} else if (dimensionsGap > 0) {
|
||||||
|
for (let i = 0; i < dimensionsGap; i++) {
|
||||||
|
seriesArr.push(cloneDeep(seriesItem))
|
||||||
|
}
|
||||||
|
props.chartConfig.option.series.push(...seriesArr)
|
||||||
}
|
}
|
||||||
replaceMergeArr.value = ['series']
|
replaceMergeArr.value = ['series']
|
||||||
props.chartConfig.option.series = seriesArr
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
replaceMergeArr.value = []
|
replaceMergeArr.value = []
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user