fix: 解决动态返回dataset的字段数量不会自动适配的问题

This commit is contained in:
奔跑的面条 2024-05-27 21:13:45 +08:00
parent 7e424bfcda
commit 526d01b16c
9 changed files with 40 additions and 19 deletions

View File

@ -36,7 +36,7 @@ export const useChartDataFetch = (
const echartsUpdateHandle = (dataset: any) => {
if (chartFrame === ChartFrameEnum.ECHARTS) {
if (vChartRef.value) {
setOption(vChartRef.value, { dataset: dataset })
setOption(vChartRef.value, { dataset: dataset }, false)
}
}
}

View File

@ -1,8 +1,14 @@
<template>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option" :manual-update="isPreview()"
<v-chart
ref="vChartRef"
:init-options="initOptions"
:theme="themeColor"
:option="option"
:update-options="{
replaceMerge: replaceMergeArr
}" autoresize></v-chart>
}"
autoresize
></v-chart>
</template>
<script setup lang="ts">
@ -85,5 +91,7 @@ watch(
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -4,7 +4,6 @@
:init-options="initOptions"
:theme="themeColor"
:option="option"
:manual-update="isPreview()"
:update-options="{
replaceMerge: replaceMergeArr
}"
@ -23,7 +22,6 @@ import { mergeTheme } from '@/packages/public/chart'
import config, { includes, seriesItem } from './config'
import { useChartDataFetch } from '@/hooks'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { isPreview } from '@/utils'
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
import isObject from 'lodash/isObject'
import cloneDeep from 'lodash/cloneDeep'
@ -79,5 +77,7 @@ watch(
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -4,7 +4,9 @@
:init-options="initOptions"
:theme="themeColor"
:option="option"
:manual-update="isPreview()"
:update-options="{
replaceMerge: replaceMergeArr
}"
autoresize
></v-chart>
</template>
@ -88,5 +90,7 @@ watch(
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -4,7 +4,6 @@
:init-options="initOptions"
:theme="themeColor"
:option="option"
:manual-update="isPreview()"
:update-options="{
replaceMerge: replaceMergeArr
}"
@ -79,5 +78,7 @@ watch(
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -1,5 +1,5 @@
<template>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option.value" autoresize>
</v-chart>
</template>
@ -82,5 +82,7 @@ watch(
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -1,5 +1,5 @@
<template>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize></v-chart>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option.value" autoresize></v-chart>
</template>
<script setup lang="ts">
@ -80,5 +80,7 @@ watch(
option.value = props.chartConfig.option
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -1,5 +1,5 @@
<template>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize>
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option.value" autoresize>
</v-chart>
</template>
@ -79,5 +79,7 @@ watch(
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
props.chartConfig.option.dataset = newData
})
</script>

View File

@ -40,9 +40,11 @@ export const setData = (option: any, data: EchartsDataType) => {
* @param instance
* @param data
*/
export const setOption = <T extends typeof VChart | undefined, D>(instance: T, data: D) => {
export const setOption = <T extends typeof VChart | undefined, D>(instance: T, data: D, notMerge = true) => {
if (!instance) return
const option = instance.getOption()
option.dataset = null
instance.setOption(data)
instance.setOption(data, {
notMerge: notMerge
})
}