|
|
@@ -6,6 +6,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { reactive, watch, PropType } from 'vue'
|
|
|
import VChart from 'vue-echarts'
|
|
|
+import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
|
|
|
import { use, graphic } from 'echarts/core'
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
import { LineChart } from 'echarts/charts'
|
|
|
@@ -15,7 +16,7 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore
|
|
|
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
|
|
|
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
|
|
import { useChartDataFetch } from '@/hooks'
|
|
|
-import { isPreview } from '@/utils'
|
|
|
+import { isPreview, colorGradientCustomMerge} from '@/utils'
|
|
|
|
|
|
const props = defineProps({
|
|
|
themeSetting: {
|
|
|
@@ -32,6 +33,8 @@ const props = defineProps({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+const initOptions = useCanvasInitOptions(props.chartConfig.option, props.themeSetting)
|
|
|
+
|
|
|
use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
|
|
|
const chartEditStore = useChartEditStore()
|
|
|
|
|
|
@@ -41,41 +44,45 @@ const option = reactive({
|
|
|
|
|
|
// 渐变色处理
|
|
|
watch(
|
|
|
- () => chartEditStore.getEditCanvasConfig.chartThemeColor,
|
|
|
- (newColor: keyof typeof chartColorsSearch) => {
|
|
|
- try {
|
|
|
- if (!isPreview()) {
|
|
|
- const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
|
|
|
- props.chartConfig.option.series.forEach((value: any, index: number) => {
|
|
|
- value.areaStyle.color = new graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
- {
|
|
|
- offset: 0,
|
|
|
- color: themeColor[3]
|
|
|
- },
|
|
|
- {
|
|
|
- offset: 1,
|
|
|
- color: 'rgba(0,0,0, 0)'
|
|
|
- }
|
|
|
- ])
|
|
|
- })
|
|
|
+ () => chartEditStore.getEditCanvasConfig.chartThemeColor,
|
|
|
+ (newColor: keyof typeof chartColorsSearch) => {
|
|
|
+ try {
|
|
|
+ if (!isPreview()) {
|
|
|
+ const themeColor =
|
|
|
+ colorGradientCustomMerge(chartEditStore.getEditCanvasConfig.chartCustomThemeColorInfo)[newColor] ||
|
|
|
+ colorGradientCustomMerge(chartEditStore.getEditCanvasConfig.chartCustomThemeColorInfo)[defaultTheme]
|
|
|
+ props.chartConfig.option.series.forEach((value: any, index: number) => {
|
|
|
+ value.areaStyle.color = new graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
+ {
|
|
|
+ offset: 0,
|
|
|
+ color: themeColor[3]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ offset: 1,
|
|
|
+ color: 'rgba(0,0,0, 0)'
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ })
|
|
|
+ }
|
|
|
+ option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
+ props.chartConfig.option = option.value
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
}
|
|
|
- option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
- props.chartConfig.option = option.value
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
+ },
|
|
|
+ {
|
|
|
+ immediate: true
|
|
|
}
|
|
|
- },
|
|
|
- {
|
|
|
- immediate: true
|
|
|
- }
|
|
|
)
|
|
|
|
|
|
watch(
|
|
|
- () => props.chartConfig.option.dataset,
|
|
|
- () => {
|
|
|
- option.value = props.chartConfig.option
|
|
|
- }
|
|
|
+ () => props.chartConfig.option.dataset,
|
|
|
+ () => {
|
|
|
+ option.value = props.chartConfig.option
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
-const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
|
|
|
+const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
|
|
|
+ props.chartConfig.option.dataset = newData
|
|
|
+})
|
|
|
</script>
|