perf: 优化图标展示,修复 dataset 的问题(我TM就不该相信这个半成品),优化性能监听

This commit is contained in:
奔跑的面条 2022-09-11 22:53:00 +08:00
parent dbd49a05bd
commit 18947db22b
34 changed files with 562 additions and 302 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -62,16 +62,15 @@ export const useChartDataFetch = (
if (res && res.data) { if (res && res.data) {
try { try {
const filter = targetComponent.filter const filter = targetComponent.filter
// 更新回调函数
if (updateCallback) {
updateCallback(newFunctionHandle(res.data, filter))
} else {
// eCharts 组件配合 vChart 库更新方式 // eCharts 组件配合 vChart 库更新方式
if (chartFrame === ChartFrameEnum.ECHARTS) { if (chartFrame === ChartFrameEnum.ECHARTS) {
if (vChartRef.value) { if (vChartRef.value) {
vChartRef.value.setOption({ dataset: newFunctionHandle(res.data, filter) }) vChartRef.value.setOption({ dataset: newFunctionHandle(res.data, filter) })
} }
} }
// 更新回调函数
if (updateCallback) {
updateCallback(newFunctionHandle(res.data, filter))
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)

View File

@ -6,6 +6,15 @@ import dataJson from './data.json'
export const includes = ['legend', 'xAxis', 'yAxis'] export const includes = ['legend', 'xAxis', 'yAxis']
export const seriesItem = {
type: 'bar',
barWidth: null,
itemStyle: {
color: null,
borderRadius: 0
}
}
export const option = { export const option = {
tooltip: { tooltip: {
show: true, show: true,
@ -27,24 +36,7 @@ export const option = {
type: 'value' type: 'value'
}, },
dataset: { ...dataJson }, dataset: { ...dataJson },
series: [ series: [seriesItem, seriesItem]
{
type: 'bar',
barWidth: null,
itemStyle: {
color: null,
borderRadius: 0
}
},
{
type: 'bar',
barWidth: null,
itemStyle: {
color: null,
borderRadius: 0
}
}
]
} }
export default class Config extends publicConfig implements CreateComponentType { export default class Config extends publicConfig implements CreateComponentType {

View File

@ -1,25 +1,29 @@
<template> <template>
<v-chart ref="vChartRef" :theme="themeColor" :option="option" :manual-update="isPreview()" autoresize></v-chart> <v-chart
ref="vChartRef"
:theme="themeColor"
:option="option"
:manual-update="isPreview()"
:update-options="{
replaceMerge: replaceMergeArr
}"
autoresize
></v-chart>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, PropType } from 'vue' import { ref, nextTick, computed, watch, PropType } from 'vue'
import VChart from 'vue-echarts' import VChart from 'vue-echarts'
import { use } from 'echarts/core' import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { BarChart } from 'echarts/charts' import { BarChart } from 'echarts/charts'
import { includes } from './config' import config, { includes, seriesItem } from './config'
import { mergeTheme } from '@/packages/public/chart' import { mergeTheme } from '@/packages/public/chart'
import { useChartDataFetch } from '@/hooks' import { useChartDataFetch } from '@/hooks'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { isPreview } from '@/utils' import { isPreview } from '@/utils'
import { import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
DatasetComponent,
GridComponent,
TooltipComponent,
LegendComponent
} from 'echarts/components'
const props = defineProps({ const props = defineProps({
themeSetting: { themeSetting: {
@ -31,23 +35,39 @@ const props = defineProps({
required: true required: true
}, },
chartConfig: { chartConfig: {
type: Object as PropType<CreateComponentType>, type: Object as PropType<config>,
required: true required: true
} }
}) })
use([ use([DatasetComponent, CanvasRenderer, BarChart, GridComponent, TooltipComponent, LegendComponent])
DatasetComponent,
CanvasRenderer, const replaceMergeArr = ref<string[]>()
BarChart,
GridComponent,
TooltipComponent,
LegendComponent
])
const option = computed(() => { const option = computed(() => {
return mergeTheme(props.chartConfig.option, props.themeSetting, includes) return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
}) })
// dataset
watch(
() => props.chartConfig.option.dataset,
(newData, oldData) => {
if (newData.dimensions.length !== oldData.dimensions.length) {
const seriesArr = []
for (let i = 0; i < newData.dimensions.length - 1; i++) {
seriesArr.push(seriesItem)
}
replaceMergeArr.value = ['series']
props.chartConfig.option.series = seriesArr
nextTick(() => {
replaceMergeArr.value = []
})
}
},
{
deep: false
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore) const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script> </script>

View File

@ -6,50 +6,40 @@ import dataJson from './data.json'
export const includes = ['legend', 'xAxis', 'yAxis'] export const includes = ['legend', 'xAxis', 'yAxis']
export const seriesItem = {
type: 'bar',
barWidth: null,
itemStyle: {
color: null,
borderRadius: 0
}
}
export const option = { export const option = {
tooltip: { tooltip: {
show: true, show: true,
trigger: 'axis', trigger: 'axis',
axisPointer: { axisPointer: {
show: true, show: true,
type: 'shadow', type: 'shadow'
}, }
}, },
legend: { legend: {
show: true, show: true
}, },
xAxis: { xAxis: {
show: true, show: true,
type: 'value', type: 'value',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
}, },
yAxis: { yAxis: {
show: true, show: true,
type: 'category', type: 'category'
}, },
dataset: { ...dataJson }, dataset: { ...dataJson },
series: [ series: [seriesItem, seriesItem]
{
type: 'bar',
barWidth: null,
itemStyle: {
color: null,
borderRadius: 0,
},
},
{
type: 'bar',
barWidth: null,
itemStyle: {
color: null,
borderRadius: 0,
},
},
],
} }
export default class Config extends publicConfig export default class Config extends publicConfig implements CreateComponentType {
implements CreateComponentType {
public key = BarCrossrangeConfig.key public key = BarCrossrangeConfig.key
public chartConfig = cloneDeep(BarCrossrangeConfig) public chartConfig = cloneDeep(BarCrossrangeConfig)
// 图表配置项 // 图表配置项

View File

@ -1,24 +1,28 @@
<template> <template>
<v-chart ref="vChartRef" :theme="themeColor" :option="option" :manual-update="isPreview()" autoresize></v-chart> <v-chart
ref="vChartRef"
:theme="themeColor"
:option="option"
:manual-update="isPreview()"
:update-options="{
replaceMerge: replaceMergeArr
}"
autoresize
></v-chart>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, PropType } from 'vue' import { ref, nextTick, computed, watch, PropType } from 'vue'
import VChart from 'vue-echarts' import VChart from 'vue-echarts'
import { use } from 'echarts/core' import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { BarChart } from 'echarts/charts' import { BarChart } from 'echarts/charts'
import { mergeTheme } from '@/packages/public/chart' import { mergeTheme } from '@/packages/public/chart'
import config, { includes } from './config' import config, { includes, seriesItem } from './config'
import { useChartDataFetch } from '@/hooks' import { useChartDataFetch } from '@/hooks'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { isPreview } from '@/utils' import { isPreview } from '@/utils'
import { import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
DatasetComponent,
GridComponent,
TooltipComponent,
LegendComponent,
} from 'echarts/components'
const props = defineProps({ const props = defineProps({
themeSetting: { themeSetting: {
@ -35,18 +39,34 @@ const props = defineProps({
} }
}) })
use([ use([DatasetComponent, CanvasRenderer, BarChart, GridComponent, TooltipComponent, LegendComponent])
DatasetComponent,
CanvasRenderer, const replaceMergeArr = ref<string[]>()
BarChart,
GridComponent,
TooltipComponent,
LegendComponent,
])
const option = computed(() => { const option = computed(() => {
return mergeTheme(props.chartConfig.option, props.themeSetting, includes) return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
}) })
// dataset
watch(
() => props.chartConfig.option.dataset,
(newData, oldData) => {
if (newData?.dimensions.length !== oldData?.dimensions.length) {
const seriesArr = []
for (let i = 0; i < newData.dimensions.length - 1; i++) {
seriesArr.push(seriesItem)
}
replaceMergeArr.value = ['series']
props.chartConfig.option.series = seriesArr
nextTick(() => {
replaceMergeArr.value = []
})
}
},
{
deep: false
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore) const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script> </script>

View File

@ -6,6 +6,18 @@ import dataJson from './data.json'
export const includes = ['legend', 'xAxis', 'yAxis'] export const includes = ['legend', 'xAxis', 'yAxis']
export const seriesItem = {
type: 'line',
lineStyle: {
type: 'solid',
width: 3,
itemStyle: {
color: null,
borderRadius: 0
}
}
}
export const option = { export const option = {
tooltip: { tooltip: {
show: true, show: true,
@ -19,43 +31,17 @@ export const option = {
}, },
xAxis: { xAxis: {
show: true, show: true,
type: 'category', type: 'category'
}, },
yAxis: { yAxis: {
show: true, show: true,
type: 'value' type: 'value'
}, },
dataset: { ...dataJson }, dataset: { ...dataJson },
series: [ series: [seriesItem, seriesItem]
{
type: 'line',
lineStyle: {
type: 'solid',
width: 3,
color: {
type: 'linear',
colorStops: [
{
offset: 0,
color: chartColorsSearch[defaultTheme][0] // 0% 处的颜色
},
{
offset: 1,
color: chartColorsSearch[defaultTheme][1] // 100% 处的颜色
}
],
globalCoord: false // 缺省为 false
},
shadowColor: chartColorsSearch[defaultTheme][2],
shadowBlur: 10,
shadowOffsetY: 20
},
}
]
} }
export default class Config extends publicConfig export default class Config extends publicConfig implements CreateComponentType {
implements CreateComponentType {
public key: string = LineCommonConfig.key public key: string = LineCommonConfig.key
public chartConfig = LineCommonConfig public chartConfig = LineCommonConfig
// 图表配置项 // 图表配置项

View File

@ -6,20 +6,6 @@
:expanded="true" :expanded="true"
> >
<SettingItemBox name="线条"> <SettingItemBox name="线条">
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="item.lineStyle.color.colorStops[0].color"
></n-color-picker>
</SettingItem>
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="item.lineStyle.color.colorStops[1].color"
></n-color-picker>
</SettingItem>
<SettingItem name="宽度"> <SettingItem name="宽度">
<n-input-number <n-input-number
v-model:value="item.lineStyle.width" v-model:value="item.lineStyle.width"
@ -37,26 +23,6 @@
></n-select> ></n-select>
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="阴影" :alone="true">
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="item.lineStyle.shadowColor"
></n-color-picker>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="设置">
<SettingItem name="阴影">
<n-button
size="small"
@click="item.lineStyle.shadowColor = 'rgba(0, 0, 0, 0)'"
>
去除阴影
</n-button>
</SettingItem>
</SettingItemBox>
</CollapseItem> </CollapseItem>
<!-- Echarts 全局设置 --> <!-- Echarts 全局设置 -->
<global-setting :optionData="optionData" :in-chart="true"></global-setting> <global-setting :optionData="optionData" :in-chart="true"></global-setting>

View File

@ -1,33 +1,40 @@
{ {
"dimensions": ["product", "data1"], "dimensions": ["product", "data1", "data2"],
"source": [ "source": [
{ {
"product": "Mon", "product": "Mon",
"data1": 120 "data1": 120,
"data2": 130
}, },
{ {
"product": "Tue", "product": "Tue",
"data1": 200 "data1": 200,
"data2": 130
}, },
{ {
"product": "Wed", "product": "Wed",
"data1": 150 "data1": 150,
"data2": 312
}, },
{ {
"product": "Thu", "product": "Thu",
"data1": 80 "data1": 80,
"data2": 268
}, },
{ {
"product": "Fri", "product": "Fri",
"data1": 70 "data1": 70,
"data2": 155
}, },
{ {
"product": "Sat", "product": "Sat",
"data1": 110 "data1": 110,
"data2": 117
}, },
{ {
"product": "Sun", "product": "Sun",
"data1": 130 "data1": 130,
"data2": 160
} }
] ]
} }

View File

@ -2,25 +2,28 @@
<v-chart <v-chart
ref="vChartRef" ref="vChartRef"
:theme="themeColor" :theme="themeColor"
:option="option.value" :option="option"
:manual-update="isPreview()" :manual-update="isPreview()"
autoresize> :update-options="{
replaceMerge: replaceMergeArr
}"
autoresize
>
</v-chart> </v-chart>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { PropType, watch, reactive } from 'vue'; import { PropType, computed, watch, ref, nextTick } from 'vue'
import VChart from 'vue-echarts' import VChart from 'vue-echarts'
import { use } from 'echarts/core' import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts' import { LineChart } from 'echarts/charts'
import config, { includes } from './config' import config, { includes, seriesItem } from './config'
import { mergeTheme } from '@/packages/public/chart' import { mergeTheme } from '@/packages/public/chart'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' 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 { useChartDataFetch } from '@/hooks'
import { isPreview } from '@/utils' import { isPreview } from '@/utils'
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
const props = defineProps({ const props = defineProps({
themeSetting: { themeSetting: {
@ -37,41 +40,34 @@ const props = defineProps({
} }
}) })
use([ use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
DatasetComponent,
CanvasRenderer,
LineChart,
GridComponent,
TooltipComponent,
LegendComponent
])
const chartEditStore = useChartEditStore() const replaceMergeArr = ref<string[]>()
const option = reactive({
value: {} const option = computed(() => {
return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
}) })
// // dataset
watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => { watch(
if (!isPreview()) { () => props.chartConfig.option.dataset,
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme] (newData, oldData) => {
props.chartConfig.option.series.forEach((value: any) => { if (newData?.dimensions.length !== oldData?.dimensions.length) {
value.lineStyle.shadowColor = themeColor[2] const seriesArr = []
value.lineStyle.color.colorStops.forEach((v: { color: string }, i: number) => { for (let i = 0; i < newData.dimensions.length - 1; i++) {
v.color = themeColor[i] seriesArr.push(seriesItem)
}) }
replaceMergeArr.value = ['series']
props.chartConfig.option.series = seriesArr
nextTick(() => {
replaceMergeArr.value = []
}) })
} }
option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes) },
props.chartConfig.option = option.value {
}, { deep: false
immediate: true, }
}) )
watch(() => props.chartConfig.option.dataset, () => {
option.value = props.chartConfig.option
})
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore) const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script> </script>

View File

@ -6,7 +6,7 @@ export const LineGradientSingleConfig: ConfigType = {
key: 'LineGradientSingle', key: 'LineGradientSingle',
chartKey: 'VLineGradientSingle', chartKey: 'VLineGradientSingle',
conKey: 'VCLineGradientSingle', conKey: 'VCLineGradientSingle',
title: '单折线面积图', title: '单折线渐变面积图',
category: ChatCategoryEnum.LINE, category: ChatCategoryEnum.LINE,
categoryName: ChatCategoryEnumName.LINE, categoryName: ChatCategoryEnumName.LINE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,

View File

@ -1,10 +1,5 @@
<template> <template>
<v-chart <v-chart ref="vChartRef" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize>
ref="vChartRef"
:theme="themeColor"
:option="option.value"
:manual-update="isPreview()"
autoresize>
</v-chart> </v-chart>
</template> </template>
@ -37,14 +32,7 @@ const props = defineProps({
} }
}) })
use([ use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
DatasetComponent,
CanvasRenderer,
LineChart,
GridComponent,
TooltipComponent,
LegendComponent,
])
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const option = reactive({ const option = reactive({
@ -52,7 +40,9 @@ const option = reactive({
}) })
// //
watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => { watch(
() => chartEditStore.getEditCanvasConfig.chartThemeColor,
(newColor: keyof typeof chartColorsSearch) => {
if (!isPreview()) { if (!isPreview()) {
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme] const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
props.chartConfig.option.series.forEach((value: any, index: number) => { props.chartConfig.option.series.forEach((value: any, index: number) => {
@ -70,14 +60,21 @@ watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof
} }
option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes) option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
props.chartConfig.option = option.value props.chartConfig.option = option.value
}, { },
{
immediate: true immediate: true
}) }
)
watch(
watch(() => props.chartConfig.option.dataset, () => { () => props.chartConfig.option.dataset,
() => {
option.value = props.chartConfig.option option.value = props.chartConfig.option
}) },
{
deep: false
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore) const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script> </script>

View File

@ -6,7 +6,7 @@ export const LineGradientsConfig: ConfigType = {
key: 'LineGradients', key: 'LineGradients',
chartKey: 'VLineGradients', chartKey: 'VLineGradients',
conKey: 'VCLineGradients', conKey: 'VCLineGradients',
title: '双折线面积图', title: '双折线渐变面积图',
category: ChatCategoryEnum.LINE, category: ChatCategoryEnum.LINE,
categoryName: ChatCategoryEnumName.LINE, categoryName: ChatCategoryEnumName.LINE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,

View File

@ -31,14 +31,7 @@ const props = defineProps({
} }
}) })
use([ use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
DatasetComponent,
CanvasRenderer,
LineChart,
GridComponent,
TooltipComponent,
LegendComponent,
])
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const option = reactive({ const option = reactive({
@ -46,7 +39,9 @@ const option = reactive({
}) })
// //
watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => { watch(
() => chartEditStore.getEditCanvasConfig.chartThemeColor,
(newColor: keyof typeof chartColorsSearch) => {
if (!isPreview()) { if (!isPreview()) {
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme] const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
props.chartConfig.option.series.forEach((value: any, index: number) => { props.chartConfig.option.series.forEach((value: any, index: number) => {
@ -64,13 +59,18 @@ watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof
} }
option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes) option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
props.chartConfig.option = option.value props.chartConfig.option = option.value
}, { },
{
immediate: true immediate: true
}) }
)
watch(() => props.chartConfig.option.dataset, () => { watch(
() => props.chartConfig.option.dataset,
() => {
option.value = props.chartConfig.option option.value = props.chartConfig.option
}) }
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore) const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script> </script>

View File

@ -0,0 +1,63 @@
import { echartOptionProfixHandle, publicConfig } from '@/packages/public'
import { LineLinearSingleConfig } from './index'
import { CreateComponentType } from '@/packages/index.d'
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
import dataJson from './data.json'
export const includes = ['legend', 'xAxis', 'yAxis']
export const option = {
tooltip: {
show: true,
trigger: 'axis',
axisPointer: {
type: 'line'
}
},
legend: {
show: true
},
xAxis: {
show: true,
type: 'category',
},
yAxis: {
show: true,
type: 'value'
},
dataset: { ...dataJson },
series: [
{
type: 'line',
lineStyle: {
type: 'solid',
width: 3,
color: {
type: 'linear',
colorStops: [
{
offset: 0,
color: chartColorsSearch[defaultTheme][0] // 0% 处的颜色
},
{
offset: 1,
color: chartColorsSearch[defaultTheme][1] // 100% 处的颜色
}
],
globalCoord: false // 缺省为 false
},
shadowColor: chartColorsSearch[defaultTheme][2],
shadowBlur: 10,
shadowOffsetY: 20
},
}
]
}
export default class Config extends publicConfig
implements CreateComponentType {
public key: string = LineLinearSingleConfig.key
public chartConfig = LineLinearSingleConfig
// 图表配置项
public option = echartOptionProfixHandle(option, includes)
}

View File

@ -0,0 +1,86 @@
<template>
<CollapseItem
v-for="(item, index) in seriesList"
:key="index"
:name="`样式`"
:expanded="true"
>
<SettingItemBox name="线条">
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="item.lineStyle.color.colorStops[0].color"
></n-color-picker>
</SettingItem>
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="item.lineStyle.color.colorStops[1].color"
></n-color-picker>
</SettingItem>
<SettingItem name="宽度">
<n-input-number
v-model:value="item.lineStyle.width"
:min="1"
:max="100"
size="small"
placeholder="自动计算"
></n-input-number>
</SettingItem>
<SettingItem name="类型">
<n-select
v-model:value="item.lineStyle.type"
size="small"
:options="lineConf.lineStyle.type"
></n-select>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="阴影" :alone="true">
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="item.lineStyle.shadowColor"
></n-color-picker>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="设置">
<SettingItem name="阴影">
<n-button
size="small"
@click="item.lineStyle.shadowColor = 'rgba(0, 0, 0, 0)'"
>
去除阴影
</n-button>
</SettingItem>
</SettingItemBox>
</CollapseItem>
<!-- Echarts 全局设置 -->
<global-setting :optionData="optionData" :in-chart="true"></global-setting>
</template>
<script setup lang="ts">
import { PropType, computed } from 'vue'
import { lineConf } from '@/packages/chartConfiguration/echarts/index'
import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
import {
GlobalSetting,
CollapseItem,
SettingItemBox,
SettingItem
} from '@/components/Pages/ChartItemSetting'
const props = defineProps({
optionData: {
type: Object as PropType<GlobalThemeJsonType>,
required: true
}
})
const seriesList = computed(() => {
return props.optionData.series
})
</script>

View File

@ -0,0 +1,33 @@
{
"dimensions": ["product", "data1"],
"source": [
{
"product": "Mon",
"data1": 120
},
{
"product": "Tue",
"data1": 200
},
{
"product": "Wed",
"data1": 150
},
{
"product": "Thu",
"data1": 80
},
{
"product": "Fri",
"data1": 70
},
{
"product": "Sat",
"data1": 110
},
{
"product": "Sun",
"data1": 130
}
]
}

View File

@ -0,0 +1,15 @@
import image from '@/assets/images/chart/charts/line_linear_single.png'
import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d'
import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const LineLinearSingleConfig: ConfigType = {
key: 'LineLinearSingle',
chartKey: 'VLineLinearSingle',
conKey: 'VCLineLinearSingle',
title: '单折线渐变图',
category: ChatCategoryEnum.LINE,
categoryName: ChatCategoryEnumName.LINE,
package: PackagesCategoryEnum.CHARTS,
chartFrame: ChartFrameEnum.ECHARTS,
image
}

View File

@ -0,0 +1,74 @@
<template>
<v-chart ref="vChartRef" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize>
</v-chart>
</template>
<script setup lang="ts">
import { PropType, watch, reactive } from 'vue'
import VChart from 'vue-echarts'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import config, { includes } from './config'
import { mergeTheme } from '@/packages/public/chart'
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'
const props = defineProps({
themeSetting: {
type: Object,
required: true
},
themeColor: {
type: Object,
required: true
},
chartConfig: {
type: Object as PropType<config>,
required: true
}
})
use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
const chartEditStore = useChartEditStore()
const option = reactive({
value: {}
})
//
watch(
() => chartEditStore.getEditCanvasConfig.chartThemeColor,
(newColor: keyof typeof chartColorsSearch) => {
if (!isPreview()) {
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.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
props.chartConfig.option = option.value
},
{
immediate: true
}
)
watch(
() => props.chartConfig.option.dataset,
() => {
option.value = props.chartConfig.option
},
{
deep: false
}
)
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
</script>

View File

@ -1,5 +1,6 @@
import { LineCommonConfig } from './LineCommon/index' import { LineCommonConfig } from './LineCommon/index'
import { LineLinearSingleConfig } from './LineLinearSingle/index'
import { LineGradientSingleConfig } from './LineGradientSingle/index' import { LineGradientSingleConfig } from './LineGradientSingle/index'
import { LineGradientsConfig } from './LineGradients/index' import { LineGradientsConfig } from './LineGradients/index'
export default [LineCommonConfig, LineGradientSingleConfig, LineGradientsConfig] export default [LineCommonConfig, LineLinearSingleConfig, LineGradientSingleConfig, LineGradientsConfig]

View File

@ -82,7 +82,8 @@ watch(
dataSetHandle(newData) dataSetHandle(newData)
}, },
{ {
immediate: true immediate: true,
deep: false
} }
) )

View File

@ -58,6 +58,9 @@ watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
(newData: any) => { (newData: any) => {
option.dataset = toNumber(newData, 2) option.dataset = toNumber(newData, 2)
},
{
deep: false
} }
) )
// //

View File

@ -9,12 +9,12 @@
], ],
"seriesData": [ "seriesData": [
{ {
"value": [4200, 3000, 20000, 35000, 50000, 18000], "name": "data1",
"name": "data1" "value": [4200, 3000, 20000, 35000, 50000, 18000]
}, },
{ {
"value": [5000, 14000, 28000, 26000, 42000, 21000], "name": "data2",
"name": "data2" "value": [5000, 14000, 28000, 26000, 42000, 21000]
} }
] ]
} }

View File

@ -59,7 +59,7 @@ watch(
dataSetHandle(newData) dataSetHandle(newData)
}, },
{ {
immediate: true deep: false
} }
) )

View File

@ -79,7 +79,8 @@ watch(
option.value = props.chartConfig.option option.value = props.chartConfig.option
}, },
{ {
immediate: true immediate: true,
deep: false
} }
) )

View File

@ -50,7 +50,8 @@ watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
newData => dataHandle(newData), newData => dataHandle(newData),
{ {
immediate: true immediate: true,
deep: false
} }
) )

View File

@ -6,8 +6,13 @@
</span> </span>
</template> </template>
<span :style="`color:${numberColor};font-size:${numberSize}px`"> <span :style="`color:${numberColor};font-size:${numberSize}px`">
<n-number-animation :from="option.from" :to="option.dataset" :duration="dur * 1000" :show-separator="showSeparator" <n-number-animation
:precision="precision"></n-number-animation> :from="option.from"
:to="option.dataset"
:duration="dur * 1000"
:show-separator="showSeparator"
:precision="precision"
></n-number-animation>
</span> </span>
<template #suffix> <template #suffix>
<span :style="`color:${suffixColor};font-size:${numberSize}px`"> <span :style="`color:${suffixColor};font-size:${numberSize}px`">
@ -26,25 +31,16 @@ import { useChartDataFetch } from '@/hooks'
const props = defineProps({ const props = defineProps({
chartConfig: { chartConfig: {
type: Object as PropType<CreateComponentType>, type: Object as PropType<CreateComponentType>,
required: true, required: true
}, }
}) })
const option = reactive({ const option = reactive({
from: 0, from: 0,
dataset: 0, dataset: 0
}) })
const { w, h } = toRefs(props.chartConfig.attr) const { w, h } = toRefs(props.chartConfig.attr)
let { let { dur, showSeparator, prefixText, prefixColor, suffixText, suffixColor, precision, numberSize, numberColor } =
dur, toRefs(props.chartConfig.option)
showSeparator,
prefixText,
prefixColor,
suffixText,
suffixColor,
precision,
numberSize,
numberColor,
} = toRefs(props.chartConfig.option)
const updateNumber = (newData: number) => { const updateNumber = (newData: number) => {
// //
@ -56,14 +52,19 @@ watch(
() => props.chartConfig.option.from, () => props.chartConfig.option.from,
() => { () => {
option.from = props.chartConfig.option.from option.from = props.chartConfig.option.from
}, { immediate: true } },
{ immediate: true }
) )
watch( watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
() => { () => {
option.dataset = props.chartConfig.option.dataset option.dataset = props.chartConfig.option.dataset
}, { immediate: true } },
{
immediate: true,
deep: false
}
) )
useChartDataFetch(props.chartConfig, useChartEditStore, updateNumber) useChartDataFetch(props.chartConfig, useChartEditStore, updateNumber)

View File

@ -46,7 +46,8 @@ watch(
option.dataset = newData option.dataset = newData
}, },
{ {
immediate: true immediate: true,
deep: false
} }
) )

View File

@ -57,8 +57,10 @@ watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
(newData: any) => { (newData: any) => {
option.dataset = newData option.dataset = newData
}, { },
immediate: true {
immediate: true,
deep: false
} }
) )

View File

@ -32,7 +32,8 @@ watch(
option.dataset = newData option.dataset = newData
}, },
{ {
immediate: true immediate: true,
deep: false
} }
) )

View File

@ -169,6 +169,9 @@ watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
() => { () => {
onRestart() onRestart()
},
{
deep: false
} }
) )

View File

@ -79,7 +79,7 @@
<!-- 骨架图 --> <!-- 骨架图 -->
<go-skeleton :load="loading" :repeat="3"></go-skeleton> <go-skeleton :load="loading" :repeat="3"></go-skeleton>
<!-- 请求配置model --> <!-- 请求配置model -->
<chart-data-request v-model:modelShow="requestShow"></chart-data-request> <chart-data-request v-model:modelShow="requestShow" @sendHandle="sendHandle"></chart-data-request>
</div> </div>
</template> </template>

View File

@ -33,7 +33,7 @@ import { useTargetData } from '../../../hooks/useTargetData.hook'
import { RequestGlobalConfig } from './components/RequestGlobalConfig' import { RequestGlobalConfig } from './components/RequestGlobalConfig'
import { RequestTargetConfig } from './components/RequestTargetConfig' import { RequestTargetConfig } from './components/RequestTargetConfig'
const emit = defineEmits(['update:modelShow']) const emit = defineEmits(['update:modelShow', 'sendHandle'])
const { targetData } = useTargetData() const { targetData } = useTargetData()
// //
@ -50,6 +50,7 @@ defineProps({
const closeHandle = () => { const closeHandle = () => {
emit('update:modelShow', false) emit('update:modelShow', false)
emit('sendHandle')
} }
</script> </script>