index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. try {
  38. if (newData === 'nomal') {
  39. props.chartConfig.option.series[0].radius = '70%'
  40. props.chartConfig.option.series[0].roseType = false
  41. } else if (newData === 'ring') {
  42. props.chartConfig.option.series[0].radius = ['40%', '65%']
  43. props.chartConfig.option.series[0].roseType = false
  44. } else {
  45. props.chartConfig.option.series[0].radius = '70%'
  46. props.chartConfig.option.series[0].roseType = true
  47. }
  48. } catch (error) {
  49. console.log(error)
  50. }
  51. },
  52. { deep: false, immediate: true }
  53. )
  54. const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
  55. </script>