58 lines
1.8 KiB
Vue
Raw Normal View History

2022-01-14 22:07:02 +08:00
<template>
2022-09-26 17:34:33 +08:00
<v-chart ref="vChartRef" :theme="themeColor" :option="option" :manual-update="isPreview()" autoresize></v-chart>
2022-01-14 22:07:02 +08:00
</template>
<script setup lang="ts">
2022-09-26 17:34:33 +08:00
import { computed, PropType, reactive, watch } from 'vue'
import VChart from 'vue-echarts'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { PieChart } from 'echarts/charts'
import { mergeTheme } from '@/packages/public/chart'
import config, { includes } 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'
2022-01-14 22:07:02 +08:00
2022-02-02 18:17:45 +08:00
const props = defineProps({
2022-02-21 19:45:11 +08:00
themeSetting: {
type: Object,
2022-09-26 17:34:33 +08:00
required: true
2022-02-21 19:45:11 +08:00
},
themeColor: {
type: Object,
2022-09-26 17:34:33 +08:00
required: true
2022-02-06 01:04:05 +08:00
},
chartConfig: {
2022-02-02 18:17:45 +08:00
type: Object as PropType<config>,
2022-09-26 17:34:33 +08:00
required: true
}
})
2022-01-14 22:07:02 +08:00
2022-09-26 17:34:33 +08:00
use([DatasetComponent, CanvasRenderer, PieChart, GridComponent, TooltipComponent, LegendComponent])
2022-02-02 18:17:45 +08:00
const option = computed(() => {
return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
2022-02-02 18:17:45 +08:00
})
2022-09-26 11:17:00 +08:00
watch(
() => props.chartConfig.option.type,
2022-09-26 17:34:33 +08:00
newData => {
if (newData === 'nomal') {
props.chartConfig.option.series[0].radius = '70%'
props.chartConfig.option.series[0].roseType = false
} else if (newData === 'ring') {
props.chartConfig.option.series[0].radius = ['40%', '65%']
props.chartConfig.option.series[0].roseType = false
2022-09-26 11:17:00 +08:00
} else {
2022-09-26 17:34:33 +08:00
props.chartConfig.option.series[0].radius = '70%'
props.chartConfig.option.series[0].roseType = true
2022-09-26 11:17:00 +08:00
}
},
{ deep: true, immediate: true }
2022-09-26 17:34:33 +08:00
)
2022-09-26 11:17:00 +08:00
2022-09-26 17:34:33 +08:00
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
2022-02-02 18:17:45 +08:00
</script>