2022-01-15 22:35:32 +08:00
|
|
|
<template>
|
2022-03-28 15:44:55 +08:00
|
|
|
<v-chart
|
|
|
|
ref="vChartRef"
|
|
|
|
:theme="themeColor"
|
2022-05-03 15:36:35 +08:00
|
|
|
:option="option.value"
|
2022-03-28 15:44:55 +08:00
|
|
|
:manual-update="isPreview()"
|
|
|
|
autoresize
|
|
|
|
></v-chart>
|
2022-01-15 22:35:32 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-05-02 23:10:47 +08:00
|
|
|
import { PropType, watch, reactive } from 'vue'
|
2022-03-28 15:44:55 +08:00
|
|
|
import VChart from 'vue-echarts'
|
|
|
|
import { use } from 'echarts/core'
|
|
|
|
import 'echarts-liquidfill/src/liquidFill.js'
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
import { GridComponent } from 'echarts/components'
|
2022-05-02 23:10:47 +08:00
|
|
|
import config from './config'
|
2022-03-28 15:44:55 +08:00
|
|
|
import { isPreview } from '@/utils'
|
2022-05-02 23:10:47 +08:00
|
|
|
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
|
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
|
import { useChartDataFetch } from '@/hooks'
|
2022-01-15 22:35:32 +08:00
|
|
|
|
2022-03-28 15:44:55 +08:00
|
|
|
const props = defineProps({
|
|
|
|
themeSetting: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
themeColor: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
chartConfig: {
|
|
|
|
type: Object as PropType<config>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
use([CanvasRenderer, GridComponent])
|
2022-01-15 22:35:32 +08:00
|
|
|
|
2022-05-02 23:10:47 +08:00
|
|
|
const chartEditStore = useChartEditStore()
|
|
|
|
|
|
|
|
const option = reactive({
|
2022-05-03 15:36:35 +08:00
|
|
|
value: {},
|
2022-03-28 15:44:55 +08:00
|
|
|
})
|
2022-01-15 22:35:32 +08:00
|
|
|
|
2022-05-02 23:10:47 +08:00
|
|
|
// 渐变色处理
|
|
|
|
watch(
|
|
|
|
() => chartEditStore.getEditCanvasConfig.chartThemeColor,
|
|
|
|
(newColor: keyof typeof chartColorsSearch) => {
|
|
|
|
if (!isPreview()) {
|
|
|
|
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
|
2022-05-03 15:36:35 +08:00
|
|
|
// 背景颜色
|
|
|
|
props.chartConfig.option.series[0].backgroundStyle.color = themeColor[2]
|
|
|
|
// 水球颜色
|
2022-05-02 23:10:47 +08:00
|
|
|
props.chartConfig.option.series[0].color[0].colorStops = [
|
|
|
|
{
|
|
|
|
offset: 0,
|
|
|
|
color: themeColor[0],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
offset: 1,
|
|
|
|
color: themeColor[1],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
2022-05-03 15:36:35 +08:00
|
|
|
option.value = props.chartConfig.option
|
2022-05-02 23:10:47 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-05-02 23:33:39 +08:00
|
|
|
const updateDataset = (newData: string | number) => {
|
|
|
|
props.chartConfig.option.series[0].data = [parseFloat(`${newData}`).toFixed(2)]
|
2022-05-03 15:36:35 +08:00
|
|
|
option.value = props.chartConfig.option
|
2022-05-02 23:10:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
watch(
|
2022-05-02 23:33:39 +08:00
|
|
|
() => props.chartConfig.option.dataset,
|
2022-05-02 23:10:47 +08:00
|
|
|
newData => updateDataset(newData),
|
|
|
|
{
|
2022-05-02 23:33:39 +08:00
|
|
|
immediate: true,
|
2022-05-02 23:10:47 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-05-02 23:33:39 +08:00
|
|
|
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
|
2022-05-02 23:10:47 +08:00
|
|
|
</script>
|