2022-01-15 21:05:11 +08:00
|
|
|
<template>
|
2022-03-10 21:35:49 +08:00
|
|
|
<VChart :theme="themeColor" :option="option.options" autoresize />
|
2022-01-15 21:05:11 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-03-12 11:29:57 +08:00
|
|
|
import { PropType, watch, reactive } from 'vue';
|
2022-02-02 18:17:45 +08:00
|
|
|
import VChart from 'vue-echarts'
|
2022-03-12 11:29:57 +08:00
|
|
|
import { use } from 'echarts/core'
|
2022-02-02 18:17:45 +08:00
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
import { LineChart } from 'echarts/charts'
|
2022-02-24 17:23:20 +08:00
|
|
|
import config, { includes } from './config'
|
2022-02-21 21:16:44 +08:00
|
|
|
import { mergeTheme } from '@/packages/public/chart'
|
2022-03-09 20:27:53 +08:00
|
|
|
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
2022-03-10 20:54:02 +08:00
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
2022-03-10 21:35:49 +08:00
|
|
|
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
|
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
|
|
|
|
},
|
2022-02-24 17:23:20 +08:00
|
|
|
chartConfig: {
|
2022-02-02 18:17:45 +08:00
|
|
|
type: Object as PropType<config>,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
})
|
2022-01-15 21:05:11 +08:00
|
|
|
|
2022-02-02 18:17:45 +08:00
|
|
|
use([
|
|
|
|
CanvasRenderer,
|
|
|
|
LineChart,
|
|
|
|
GridComponent,
|
|
|
|
TooltipComponent,
|
2022-03-09 20:27:53 +08:00
|
|
|
LegendComponent
|
2022-02-02 18:17:45 +08:00
|
|
|
])
|
2022-01-15 21:05:11 +08:00
|
|
|
|
2022-03-10 20:54:02 +08:00
|
|
|
const chartEditStore = useChartEditStore()
|
2022-03-10 21:35:49 +08:00
|
|
|
const option = reactive({
|
|
|
|
options: {}
|
|
|
|
})
|
|
|
|
|
2022-03-12 11:29:57 +08:00
|
|
|
// 初始化与渐变色处理
|
|
|
|
watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => {
|
|
|
|
if (!document.location.hash.includes('preview')) {
|
|
|
|
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
|
|
|
|
props.chartConfig.option.series.forEach((value: any) => {
|
|
|
|
value.lineStyle.shadowColor = themeColor[2]
|
|
|
|
value.lineStyle.color.colorStops.forEach((v: {color: string}, i:number) => {
|
|
|
|
v.color = themeColor[i]
|
|
|
|
})
|
2022-03-11 10:22:54 +08:00
|
|
|
})
|
2022-03-12 11:29:57 +08:00
|
|
|
}
|
2022-03-11 10:22:54 +08:00
|
|
|
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
immediate: true
|
|
|
|
})
|
|
|
|
</script>
|