Commit 89225bce1c42020af66bf64484943e83b91161e4

Authored by fengwotao
1 parent 837f7254

feat(src/packages): 图表双折线支持导入多个数据源

... ... @@ -7,11 +7,38 @@ import cloneDeep from 'lodash/cloneDeep'
7 7 import dataJson from './data.json'
8 8
9 9 export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
10   -
  10 +export const seriesItem = {
  11 + type: 'line',
  12 + smooth: false,
  13 + symbolSize: 5, //设定实心点的大小
  14 + label: {
  15 + show: true,
  16 + position: 'top',
  17 + color: '#fff',
  18 + fontSize: 12
  19 + },
  20 + lineStyle: {
  21 + width: 3,
  22 + type: 'solid'
  23 + },
  24 + areaStyle: {
  25 + opacity: 0.8,
  26 + color: new graphic.LinearGradient(0, 0, 0, 1, [
  27 + {
  28 + offset: 0,
  29 + color: chartColorsSearch[defaultTheme][3]
  30 + },
  31 + {
  32 + offset: 1,
  33 + color: 'rgba(0,0,0,0)'
  34 + }
  35 + ])
  36 + }
  37 +}
11 38 // 其它配置项比如新增(动画)
12 39 const otherConfig = {
13 40 // 轮播动画
14   - isCarousel: false,
  41 + isCarousel: false
15 42 }
16 43 const option = {
17 44 ...otherConfig,
... ... @@ -31,63 +58,7 @@ const option = {
31 58 type: 'value'
32 59 },
33 60 dataset: { ...dataJson },
34   - series: [
35   - {
36   - type: 'line',
37   - smooth: false,
38   - symbolSize: 5, //设定实心点的大小
39   - label: {
40   - show: true,
41   - position: 'top',
42   - color: '#fff',
43   - fontSize: 12
44   - },
45   - lineStyle: {
46   - width: 3,
47   - type: 'solid'
48   - },
49   - areaStyle: {
50   - opacity: 0.8,
51   - color: new graphic.LinearGradient(0, 0, 0, 1, [
52   - {
53   - offset: 0,
54   - color: chartColorsSearch[defaultTheme][3]
55   - },
56   - {
57   - offset: 1,
58   - color: 'rgba(0,0,0,0)'
59   - }
60   - ])
61   - }
62   - },
63   - {
64   - type: 'line',
65   - smooth: false,
66   - label: {
67   - show: true,
68   - position: 'top',
69   - color: '#fff',
70   - fontSize: 12
71   - },
72   - lineStyle: {
73   - width: 3,
74   - type: 'solid'
75   - },
76   - areaStyle: {
77   - opacity: 0.8,
78   - color: new graphic.LinearGradient(0, 0, 0, 1, [
79   - {
80   - offset: 0,
81   - color: chartColorsSearch[defaultTheme][4]
82   - },
83   - {
84   - offset: 1,
85   - color: 'rgba(0,0,0,0)'
86   - }
87   - ])
88   - }
89   - }
90   - ]
  61 + series: [seriesItem, seriesItem]
91 62 }
92 63
93 64 export default class Config extends PublicConfigClass implements CreateComponentType {
... ...
... ... @@ -12,13 +12,13 @@
12 12 </template>
13 13
14 14 <script setup lang="ts">
15   -import { reactive, watch, PropType, onMounted } from 'vue'
  15 +import { reactive, watch, PropType, onMounted, ref, nextTick } from 'vue'
16 16 import VChart from 'vue-echarts'
17 17 import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
18 18 import { use, graphic } from 'echarts/core'
19 19 import { CanvasRenderer } from 'echarts/renderers'
20 20 import { LineChart } from 'echarts/charts'
21   -import config, { includes } from './config'
  21 +import config, { includes, seriesItem } from './config'
22 22 import { mergeTheme } from '@/packages/public/chart'
23 23 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
24 24 import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
... ... @@ -27,6 +27,7 @@ import { useChartDataFetch } from '@/hooks'
27 27 import { isPreview, colorGradientCustomMerge } from '@/utils'
28 28 import dataJson from './data.json'
29 29 import { useFullScreen } from '../../utls/fullScreen'
  30 +import isObject from 'lodash/isObject'
30 31
31 32 const props = defineProps({
32 33 themeSetting: {
... ... @@ -106,12 +107,12 @@ watch(
106 107 }
107 108 )
108 109
109   -watch(
110   - () => props.chartConfig.option.dataset,
111   - () => {
112   - option.value = props.chartConfig.option
113   - }
114   -)
  110 +// watch(
  111 +// () => props.chartConfig.option.dataset,
  112 +// () => {
  113 +// option.value = props.chartConfig.option
  114 +// }
  115 +// )
115 116 let seriesDataNum = -1
116 117 let seriesDataMaxLength = 0
117 118 let intervalInstance: any = null
... ... @@ -194,7 +195,36 @@ const updateVChart = (newData: any) => {
194 195 })
195 196 }
196 197
197   -const {vChartRef} = useChartDataFetch(props.chartConfig, useChartEditStore, (newData) => {
  198 +const replaceMergeArr = ref<string[]>()
  199 +
  200 +// dataset 无法变更条数的补丁
  201 +watch(
  202 + () => props.chartConfig.option.dataset,
  203 + (newData: { dimensions: any }, oldData) => {
  204 + try {
  205 + option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
  206 + if (!isObject(newData) || !('dimensions' in newData)) return
  207 + if (Array.isArray(newData?.dimensions)) {
  208 + const seriesArr = []
  209 + for (let i = 0; i < newData.dimensions.length - 1; i++) {
  210 + seriesArr.push(seriesItem)
  211 + }
  212 + replaceMergeArr.value = ['series']
  213 + props.chartConfig.option.series = seriesArr
  214 + nextTick(() => {
  215 + replaceMergeArr.value = []
  216 + })
  217 + }
  218 + } catch (error) {
  219 + console.log(error)
  220 + }
  221 + },
  222 + {
  223 + deep: false
  224 + }
  225 +)
  226 +
  227 +const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, newData => {
198 228 // addPieInterval(newData)
199 229 updateVChart(newData)
200 230 })
... ...
... ... @@ -11,7 +11,7 @@ export const hideAsideComponentsObj = {
11 11 Lines: [
12 12 'VLineCommon', //折线图
13 13 'VLineGradients', //双折线渐变面积图
14   - 'ExternalVCOverrideLineGradients' //重写双折线渐变面积图
  14 + // 'ExternalVCOverrideLineGradients' //重写双折线渐变面积图
15 15 ],
16 16 Pies: [
17 17 'VPieCircle' //饼图-环形
... ... @@ -22,7 +22,10 @@ export const hideAsideComponentsObj = {
22 22 Mores: [
23 23 'VProcess', //NaiveUI-进度
24 24 'VImage', //图片
25   - 'VImageCarousel' //轮播图
  25 + 'VImageCarousel', //轮播图
  26 + 'VVideo', //视频
  27 + 'VIframe', //远程网页
  28 + 'VWaterPolo' //水球图
26 29 ],
27 30 Texts: [
28 31 'VTextGradient', //渐变文字
... ... @@ -35,7 +38,7 @@ export const hideAsideComponentsObj = {
35 38 'VLineLinearSingle', //单折线渐变图
36 39 'VLineGradientSingle', //单折线渐变面积图
37 40 'VLineGradients', //双折线渐变面积图
38   - 'ExternalVCOverrideLineGradients', //重写双折线渐变面积图
  41 + // 'ExternalVCOverrideLineGradients', //重写双折线渐变面积图
39 42 'VPieCircle', //饼图-环形
40 43 'VMapBase', //地图(可选省份)
41 44 'VProcess', //NaiveUI-进度
... ... @@ -45,6 +48,7 @@ export const hideAsideComponentsObj = {
45 48 'VVideo', //视频
46 49 'VIframe', //远程网页
47 50 'VImage', //图片
48   - 'VImageCarousel' //轮播图
  51 + 'VImageCarousel', //轮播图
  52 + 'VWaterPolo' //水球图
49 53 ]
50 54 }
... ...