fix: 解决不能预览渐变色的问题

This commit is contained in:
MTrun
2022-03-12 11:29:57 +08:00
parent 3560effe2c
commit 0ee76c1579
6 changed files with 57 additions and 59 deletions
@@ -1,6 +1,7 @@
import { echartOptionProfixHandle, publicConfig } from '@/packages/public'
import { LineCommonConfig } from './index'
import { CreateComponentType } from '@/packages/index.d'
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
export const includes = ['legend', 'xAxis', 'yAxis']
@@ -36,16 +37,16 @@ export const option = {
colorStops: [
{
offset: 0,
color: '#42a5f5' // 0% 处的颜色
color: chartColorsSearch[defaultTheme][0] // 0% 处的颜色
},
{
offset: 1,
color: '#48D8BF' // 100% 处的颜色
color: chartColorsSearch[defaultTheme][1] // 100% 处的颜色
}
],
globalCoord: false // 缺省为 false
},
shadowColor: 'rgba(68, 181, 226, 0.3)',
shadowColor: chartColorsSearch[defaultTheme][2],
shadowBlur: 10,
shadowOffsetY: 20
},
@@ -3,9 +3,9 @@
</template>
<script setup lang="ts">
import { computed, PropType, watch, reactive, watchEffect } from 'vue';
import { PropType, watch, reactive } from 'vue';
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import config, { includes } from './config'
@@ -42,19 +42,17 @@ const option = reactive({
options: {}
})
watchEffect(()=> {
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
})
// 渐变色处理
watch(()=>chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => {
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]
// 初始化与渐变色处理
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]
})
})
})
}
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
},
{