Commit 20ffa0ac9162ac8e24432e0407f3bf7d8a98670e
1 parent
2668cfc3
perf(src/packages): 信息里更多新增自定义echarts组件
Showing
5 changed files
with
144 additions
and
0 deletions
1 | +import { PublicConfigClass } from '@/packages/public' | ||
2 | +import { CreateComponentType } from '@/packages/index.d' | ||
3 | +import { chartInitConfig } from '@/settings/designSetting' | ||
4 | +import { CustomEchartsConfig } from './index' | ||
5 | +import cloneDeep from 'lodash/cloneDeep' | ||
6 | + | ||
7 | +export const option = { | ||
8 | + //数据源设置 | ||
9 | + dataset: "{}" | ||
10 | +} | ||
11 | + | ||
12 | +export default class Config extends PublicConfigClass implements CreateComponentType { | ||
13 | + public key = CustomEchartsConfig.key | ||
14 | + public attr = { ...chartInitConfig, w: 1200, h: 800, zIndex: -1 } | ||
15 | + public chartConfig = cloneDeep(CustomEchartsConfig) | ||
16 | + public option = cloneDeep(option) | ||
17 | +} |
1 | +<template> | ||
2 | + <collapse-item name="数据源" :expanded="true"> | ||
3 | + <monaco-editor v-model:modelValue="optionData.dataset" width="460px" height="380px" language="json" /> | ||
4 | + </collapse-item> | ||
5 | +</template> | ||
6 | + | ||
7 | +<script setup lang="ts"> | ||
8 | +import { PropType } from 'vue' | ||
9 | +import { option } from './config' | ||
10 | +import { CollapseItem } from '@/components/Pages/ChartItemSetting' | ||
11 | +import { MonacoEditor } from '@/components/Pages/MonacoEditor' | ||
12 | + | ||
13 | +defineProps({ | ||
14 | + optionData: { | ||
15 | + type: Object as PropType<typeof option>, | ||
16 | + required: true | ||
17 | + } | ||
18 | +}) | ||
19 | + | ||
20 | + | ||
21 | +</script> |
1 | +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d' | ||
2 | +import { ChatCategoryEnum, ChatCategoryEnumName } from '@/packages/components/Informations/index.d' | ||
3 | +import { useWidgetKey } from '@/packages/external/useWidgetKey' | ||
4 | + | ||
5 | +const { key, conKey, chartKey } = useWidgetKey('CustomEcharts', true) | ||
6 | + | ||
7 | +export const CustomEchartsConfig: ConfigType = { | ||
8 | + key, | ||
9 | + chartKey, | ||
10 | + conKey, | ||
11 | + title: '自定义echarts组件', | ||
12 | + category: ChatCategoryEnum.MORE, | ||
13 | + categoryName: ChatCategoryEnumName.MORE, | ||
14 | + package: PackagesCategoryEnum.INFORMATIONS, | ||
15 | + chartFrame: ChartFrameEnum.COMMON, | ||
16 | + image: 'iframe.png' | ||
17 | +} |
1 | +<template> | ||
2 | + <v-chart | ||
3 | + ref="vChartRef" | ||
4 | + :init-options="initOptions" | ||
5 | + :theme="themeColor" | ||
6 | + :option="option" | ||
7 | + :manual-update="isPreview()" | ||
8 | + :update-options="{ | ||
9 | + replaceMerge: replaceMergeArr | ||
10 | + }" | ||
11 | + autoresize | ||
12 | + ></v-chart> | ||
13 | +</template> | ||
14 | + | ||
15 | +<script setup lang="ts"> | ||
16 | +import { ref, computed, PropType, watch } from 'vue' | ||
17 | +import VChart from 'vue-echarts' | ||
18 | +import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook' | ||
19 | +import { use } from 'echarts/core' | ||
20 | +import { CanvasRenderer } from 'echarts/renderers' | ||
21 | +import { BarChart } from 'echarts/charts' | ||
22 | +import config from './config' | ||
23 | +import { mergeTheme } from '@/packages/public/chart' | ||
24 | +import { useChartDataFetch } from '@/hooks' | ||
25 | +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | ||
26 | +import { isPreview } from '@/utils' | ||
27 | +import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components' | ||
28 | + | ||
29 | +const props = defineProps({ | ||
30 | + themeSetting: { | ||
31 | + type: Object, | ||
32 | + required: true | ||
33 | + }, | ||
34 | + themeColor: { | ||
35 | + type: Object, | ||
36 | + required: true | ||
37 | + }, | ||
38 | + chartConfig: { | ||
39 | + type: Object as PropType<config>, | ||
40 | + required: true | ||
41 | + } | ||
42 | +}) | ||
43 | + | ||
44 | +const initOptions = useCanvasInitOptions(props.chartConfig.option.dataset, props.themeSetting) | ||
45 | + | ||
46 | +use([DatasetComponent, CanvasRenderer, BarChart, GridComponent, TooltipComponent, LegendComponent]) | ||
47 | + | ||
48 | +const replaceMergeArr = ref<string[]>() | ||
49 | + | ||
50 | +const option = computed(() => { | ||
51 | + return mergeTheme(props.chartConfig.option.dataset, props.themeSetting, []) | ||
52 | +}) | ||
53 | + | ||
54 | +const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore) | ||
55 | + | ||
56 | +const updateVChart = (dataset: any) => { | ||
57 | + new Promise(resolve => { | ||
58 | + setTimeout(() => { | ||
59 | + resolve( | ||
60 | + vChartRef.value?.setOption( | ||
61 | + { | ||
62 | + ...dataset | ||
63 | + }, | ||
64 | + { | ||
65 | + notMerge: true | ||
66 | + } | ||
67 | + ) | ||
68 | + ) | ||
69 | + }, 100) | ||
70 | + }) | ||
71 | +} | ||
72 | + | ||
73 | +watch( | ||
74 | + () => props.chartConfig.option.dataset, | ||
75 | + newValue => { | ||
76 | + try { | ||
77 | + updateVChart(eval('(' + newValue + ')')) | ||
78 | + } catch (e) { | ||
79 | + console.log(e) | ||
80 | + } | ||
81 | + }, | ||
82 | + { | ||
83 | + immediate: true, | ||
84 | + deep: true | ||
85 | + } | ||
86 | +) | ||
87 | +</script> |
@@ -41,6 +41,7 @@ import { Decorates10Config } from '@/packages/components/external/Decorates/Deco | @@ -41,6 +41,7 @@ import { Decorates10Config } from '@/packages/components/external/Decorates/Deco | ||
41 | import { CameraConfig } from '@/packages/components/external/Informations/Mores/Camera' | 41 | import { CameraConfig } from '@/packages/components/external/Informations/Mores/Camera' |
42 | import { SingleCameraConfig } from '@/packages/components/external/Informations/Mores/SingleCamera' | 42 | import { SingleCameraConfig } from '@/packages/components/external/Informations/Mores/SingleCamera' |
43 | import { OverrideILoadConfigurationframeConfig } from '@/packages/components/external/Informations/Mores/OverrideILoadConfigurationframe' | 43 | import { OverrideILoadConfigurationframeConfig } from '@/packages/components/external/Informations/Mores/OverrideILoadConfigurationframe' |
44 | +import { CustomEchartsConfig } from '@/packages/components/external/Informations/Mores/CustomEcharts' | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * 重写动态注入 | 47 | * 重写动态注入 |
@@ -83,6 +84,7 @@ export function useInjectLib(packagesList: EPackagesType) { | @@ -83,6 +84,7 @@ export function useInjectLib(packagesList: EPackagesType) { | ||
83 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, CameraConfig)//新增信息下的多个摄像头 | 84 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, CameraConfig)//新增信息下的多个摄像头 |
84 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, SingleCameraConfig)//新增信息下的单个摄像头 | 85 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, SingleCameraConfig)//新增信息下的单个摄像头 |
85 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideILoadConfigurationframeConfig)//新增信息下的加载组态 | 86 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideILoadConfigurationframeConfig)//新增信息下的加载组态 |
87 | + addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, CustomEchartsConfig)//新增信息下的自定义ecahrts组件 | ||
86 | // | 88 | // |
87 | 89 | ||
88 | //图表 | 90 | //图表 |