index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <v-chart ref="vChartRef" :theme="themeColor" :option="option" :manual-update="isPreview()" autoresize></v-chart>
  3. </template>
  4. <script setup lang="ts">
  5. import { computed, PropType, reactive, watch } from 'vue'
  6. import VChart from 'vue-echarts'
  7. import { use } from 'echarts/core'
  8. import { CanvasRenderer } from 'echarts/renderers'
  9. import { PieChart } from 'echarts/charts'
  10. import { mergeTheme } from '@/packages/public/chart'
  11. import config, { includes } from './config'
  12. import { useChartDataFetch } from '@/hooks'
  13. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  14. import { isPreview } from '@/utils'
  15. import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
  16. const props = defineProps({
  17. themeSetting: {
  18. type: Object,
  19. required: true
  20. },
  21. themeColor: {
  22. type: Object,
  23. required: true
  24. },
  25. chartConfig: {
  26. type: Object as PropType<config>,
  27. required: true
  28. }
  29. })
  30. use([DatasetComponent, CanvasRenderer, PieChart, GridComponent, TooltipComponent, LegendComponent])
  31. const option = computed(() => {
  32. return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
  33. })
  34. watch(
  35. () => props.chartConfig.option.type,
  36. newData => {
  37. if (newData === 'nomal') {
  38. props.chartConfig.option.series[0].radius = '70%'
  39. props.chartConfig.option.series[0].roseType = false
  40. } else if (newData === 'ring') {
  41. props.chartConfig.option.series[0].radius = ['40%', '65%']
  42. props.chartConfig.option.series[0].roseType = false
  43. } else {
  44. props.chartConfig.option.series[0].radius = '70%'
  45. props.chartConfig.option.series[0].roseType = true
  46. }
  47. },
  48. { deep: true, immediate: true }
  49. )
  50. const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
  51. </script>