|
1
|
1
|
<template>
|
|
2
|
2
|
<v-chart
|
|
3
|
|
- ref="vChartRef"
|
|
4
|
|
- :init-options="initOptions"
|
|
5
|
|
- :theme="themeColor"
|
|
6
|
|
- :option="option"
|
|
7
|
|
- :manual-update="isPreview()"
|
|
8
|
|
- :update-options="{
|
|
|
3
|
+ ref="vChartRef"
|
|
|
4
|
+ :init-options="initOptions"
|
|
|
5
|
+ :theme="themeColor"
|
|
|
6
|
+ :option="option"
|
|
|
7
|
+ :manual-update="isPreview()"
|
|
|
8
|
+ :update-options="{
|
|
9
|
9
|
replaceMerge: replaceMergeArr
|
|
10
|
10
|
}"
|
|
11
|
|
- autoresize
|
|
12
|
|
- @mouseover="handleHighlight"
|
|
13
|
|
- @mouseout="handleDownplay"
|
|
|
11
|
+ autoresize
|
|
|
12
|
+ @mouseover="handleHighlight"
|
|
|
13
|
+ @mouseout="handleDownplay"
|
|
14
|
14
|
>
|
|
15
|
15
|
</v-chart>
|
|
16
|
16
|
</template>
|
|
17
|
17
|
|
|
18
|
18
|
<script setup lang="ts">
|
|
19
|
|
-import { ref, nextTick, computed, watch, PropType, onMounted } from 'vue'
|
|
|
19
|
+import {ref, nextTick, computed, watch, PropType, onMounted} from 'vue'
|
|
20
|
20
|
import VChart from 'vue-echarts'
|
|
21
|
|
-import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
|
|
22
|
|
-import { use } from 'echarts/core'
|
|
23
|
|
-import { CanvasRenderer } from 'echarts/renderers'
|
|
24
|
|
-import { BarChart } from 'echarts/charts'
|
|
25
|
|
-import config, { includes, seriesItem } from './config'
|
|
26
|
|
-import { mergeTheme } from '@/packages/public/chart'
|
|
27
|
|
-import { useChartDataFetch } from '@/hooks'
|
|
28
|
|
-import { CreateComponentType } from '@/packages/index.d'
|
|
29
|
|
-import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
30
|
|
-import { isPreview } from '@/utils'
|
|
31
|
|
-import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
|
|
21
|
+import {useCanvasInitOptions} from '@/hooks/useCanvasInitOptions.hook'
|
|
|
22
|
+import {use} from 'echarts/core'
|
|
|
23
|
+import {CanvasRenderer} from 'echarts/renderers'
|
|
|
24
|
+import {BarChart} from 'echarts/charts'
|
|
|
25
|
+import config, {includes, seriesItem} from './config'
|
|
|
26
|
+import {mergeTheme} from '@/packages/public/chart'
|
|
|
27
|
+import {useChartDataFetch} from '@/hooks'
|
|
|
28
|
+import {CreateComponentType} from '@/packages/index.d'
|
|
|
29
|
+import {useChartEditStore} from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
30
|
+import {isPreview} from '@/utils'
|
|
|
31
|
+import {DatasetComponent, GridComponent, TooltipComponent, LegendComponent} from 'echarts/components'
|
|
32
|
32
|
import isObject from 'lodash/isObject'
|
|
33
|
33
|
import dataJson from './data.json'
|
|
34
|
|
-import { useFullScreen } from '../../utls/fullScreen'
|
|
|
34
|
+import {useFullScreen} from '../../utls/fullScreen'
|
|
35
|
35
|
|
|
36
|
36
|
const props = defineProps({
|
|
37
|
37
|
themeSetting: {
|
|
...
|
...
|
@@ -69,7 +69,7 @@ const toolBoxOption = { |
|
69
|
69
|
onclick: () => {
|
|
70
|
70
|
const getEchartDom = vChartRef.value?.getDom()
|
|
71
|
71
|
const domName = document.getElementById(getEchartDom.id) as HTMLElement
|
|
72
|
|
- const htmlName = document.querySelector('html') as HTMLHtmlElement
|
|
|
72
|
+ const htmlName = document.querySelector('html') as HTMLHtmlElement
|
|
73
|
73
|
useFullScreen(domName, htmlName)
|
|
74
|
74
|
}
|
|
75
|
75
|
}
|
|
...
|
...
|
@@ -77,33 +77,33 @@ const toolBoxOption = { |
|
77
|
77
|
}
|
|
78
|
78
|
props.chartConfig.option = {
|
|
79
|
79
|
...props.chartConfig.option,
|
|
80
|
|
- ...{ toolbox: toolBoxOption }
|
|
|
80
|
+ ...{toolbox: toolBoxOption}
|
|
81
|
81
|
}
|
|
82
|
82
|
|
|
83
|
83
|
// dataset 无法变更条数的补丁
|
|
84
|
84
|
watch(
|
|
85
|
|
- () => props.chartConfig.option.dataset,
|
|
86
|
|
- (newData: { dimensions: any }, oldData) => {
|
|
87
|
|
- try {
|
|
88
|
|
- if (!isObject(newData) || !('dimensions' in newData)) return
|
|
89
|
|
- if (Array.isArray(newData?.dimensions)) {
|
|
90
|
|
- const seriesArr = []
|
|
91
|
|
- for (let i = 0; i < newData.dimensions.length - 1; i++) {
|
|
92
|
|
- seriesArr.push(seriesItem)
|
|
|
85
|
+ () => props.chartConfig.option.dataset,
|
|
|
86
|
+ (newData: { dimensions: any }, oldData) => {
|
|
|
87
|
+ try {
|
|
|
88
|
+ if (!isObject(newData) || !('dimensions' in newData)) return
|
|
|
89
|
+ if (Array.isArray(newData?.dimensions)) {
|
|
|
90
|
+ const seriesArr = []
|
|
|
91
|
+ for (let i = 0; i < newData.dimensions.length - 1; i++) {
|
|
|
92
|
+ seriesArr.push(seriesItem)
|
|
|
93
|
+ }
|
|
|
94
|
+ replaceMergeArr.value = ['series']
|
|
|
95
|
+ props.chartConfig.option.series = seriesArr
|
|
|
96
|
+ nextTick(() => {
|
|
|
97
|
+ replaceMergeArr.value = []
|
|
|
98
|
+ })
|
|
93
|
99
|
}
|
|
94
|
|
- replaceMergeArr.value = ['series']
|
|
95
|
|
- props.chartConfig.option.series = seriesArr
|
|
96
|
|
- nextTick(() => {
|
|
97
|
|
- replaceMergeArr.value = []
|
|
98
|
|
- })
|
|
|
100
|
+ } catch (error) {
|
|
|
101
|
+ console.log(error)
|
|
99
|
102
|
}
|
|
100
|
|
- } catch (error) {
|
|
101
|
|
- console.log(error)
|
|
|
103
|
+ },
|
|
|
104
|
+ {
|
|
|
105
|
+ deep: false
|
|
102
|
106
|
}
|
|
103
|
|
- },
|
|
104
|
|
- {
|
|
105
|
|
- deep: false
|
|
106
|
|
- }
|
|
107
|
107
|
)
|
|
108
|
108
|
|
|
109
|
109
|
let seriesDataNum = -1
|
|
...
|
...
|
@@ -167,20 +167,31 @@ const handleDownplay = () => { |
|
167
|
167
|
}
|
|
168
|
168
|
|
|
169
|
169
|
watch(
|
|
170
|
|
- () => props.chartConfig.option.isCarousel,
|
|
171
|
|
- newData => {
|
|
172
|
|
- if (newData) {
|
|
173
|
|
- addPieInterval(undefined, true)
|
|
174
|
|
- props.chartConfig.option.legend.show = false
|
|
175
|
|
- } else {
|
|
176
|
|
- props.chartConfig.option.legend.show = true
|
|
177
|
|
- clearPieInterval()
|
|
|
170
|
+ () => props.chartConfig.option.isCarousel,
|
|
|
171
|
+ newData => {
|
|
|
172
|
+ if (newData) {
|
|
|
173
|
+ addPieInterval(undefined, true)
|
|
|
174
|
+ props.chartConfig.option.legend.show = false
|
|
|
175
|
+ } else {
|
|
|
176
|
+ props.chartConfig.option.legend.show = true
|
|
|
177
|
+ clearPieInterval()
|
|
|
178
|
+ }
|
|
178
|
179
|
}
|
|
179
|
|
- }
|
|
180
|
180
|
)
|
|
181
|
181
|
|
|
182
|
|
-const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: typeof dataJson) => {
|
|
|
182
|
+//fix 修复v-chart图表绑定联动组件视图不更新问题
|
|
|
183
|
+const updateVChart = (newData: any) => {
|
|
|
184
|
+ if (!newData) return
|
|
|
185
|
+ vChartRef.value?.clear()
|
|
|
186
|
+ vChartRef.value?.setOption({
|
|
|
187
|
+ ...option.value,
|
|
|
188
|
+ dataset: newData
|
|
|
189
|
+ })
|
|
|
190
|
+}
|
|
|
191
|
+
|
|
|
192
|
+const {vChartRef} = useChartDataFetch(props.chartConfig, useChartEditStore, (newData) => {
|
|
183
|
193
|
// addPieInterval(newData)
|
|
|
194
|
+ updateVChart(newData)
|
|
184
|
195
|
})
|
|
185
|
196
|
|
|
186
|
197
|
onMounted(() => {
|
...
|
...
|
|