74 lines
1.9 KiB
Vue
Raw Normal View History

2022-01-15 21:05:11 +08:00
<template>
<v-chart
ref="vChartRef"
:theme="themeColor"
:option="option"
:manual-update="isPreview()"
:update-options="{
replaceMerge: replaceMergeArr
}"
autoresize
>
</v-chart>
2022-01-15 21:05:11 +08:00
</template>
<script setup lang="ts">
import { PropType, computed, watch, ref, nextTick } from 'vue'
2022-02-02 18:17:45 +08:00
import VChart from 'vue-echarts'
import { use } from 'echarts/core'
2022-02-02 18:17:45 +08:00
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import config, { includes, seriesItem } from './config'
import { mergeTheme } from '@/packages/public/chart'
2022-03-10 20:54:02 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2022-03-25 19:58:39 +08:00
import { useChartDataFetch } from '@/hooks'
import { isPreview } from '@/utils'
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
2022-01-15 21:05:11 +08:00
2022-02-02 18:17:45 +08:00
const props = defineProps({
2022-02-21 19:45:11 +08:00
themeSetting: {
type: Object,
required: true
},
themeColor: {
type: Object,
2022-02-06 01:04:05 +08:00
required: true
},
chartConfig: {
2022-02-02 18:17:45 +08:00
type: Object as PropType<config>,
required: true
}
})
2022-01-15 21:05:11 +08:00
use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
2022-01-15 21:05:11 +08:00
const replaceMergeArr = ref<string[]>()
const option = computed(() => {
return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
})
// dataset 无法变更条数的补丁
watch(
() => props.chartConfig.option.dataset,
(newData, oldData) => {
if (newData?.dimensions.length !== oldData?.dimensions.length) {
const seriesArr = []
for (let i = 0; i < newData.dimensions.length - 1; i++) {
seriesArr.push(seriesItem)
}
replaceMergeArr.value = ['series']
props.chartConfig.option.series = seriesArr
nextTick(() => {
replaceMergeArr.value = []
2022-03-11 10:22:54 +08:00
})
}
},
{
deep: false
2022-03-20 18:11:26 +08:00
}
)
2022-03-25 19:58:39 +08:00
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script>