aldehyde 0.2.284 → 0.2.285

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/lib/controls/entry-control.d.ts.map +1 -1
  2. package/lib/controls/entry-control.js +4 -0
  3. package/lib/controls/entry-control.js.map +1 -1
  4. package/lib/controls/select/index.d.ts.map +1 -1
  5. package/lib/controls/select/index.js +1 -0
  6. package/lib/controls/select/index.js.map +1 -1
  7. package/lib/controls/view-control.d.ts.map +1 -1
  8. package/lib/controls/view-control.js +1 -0
  9. package/lib/controls/view-control.js.map +1 -1
  10. package/lib/detail/view/act-dtmpl-view.d.ts.map +1 -1
  11. package/lib/detail/view/act-dtmpl-view.js +3 -2
  12. package/lib/detail/view/act-dtmpl-view.js.map +1 -1
  13. package/lib/lowcode-components/bar-chart/index.d.ts +10 -6
  14. package/lib/lowcode-components/bar-chart/index.d.ts.map +1 -1
  15. package/lib/lowcode-components/bar-chart/index.js +91 -11
  16. package/lib/lowcode-components/bar-chart/index.js.map +1 -1
  17. package/lib/lowcode-components/base-map/index.d.ts +10 -6
  18. package/lib/lowcode-components/base-map/index.d.ts.map +1 -1
  19. package/lib/lowcode-components/base-map/index.js +86 -7
  20. package/lib/lowcode-components/base-map/index.js.map +1 -1
  21. package/lib/lowcode-components/base-table/index.d.ts +53 -0
  22. package/lib/lowcode-components/base-table/index.d.ts.map +1 -0
  23. package/lib/lowcode-components/base-table/index.js +158 -0
  24. package/lib/lowcode-components/base-table/index.js.map +1 -0
  25. package/lib/lowcode-components/base-table/index.less +59 -0
  26. package/lib/lowcode-components/capsule-bar-chart/index.d.ts +43 -0
  27. package/lib/lowcode-components/capsule-bar-chart/index.d.ts.map +1 -0
  28. package/lib/lowcode-components/capsule-bar-chart/index.js +179 -0
  29. package/lib/lowcode-components/capsule-bar-chart/index.js.map +1 -0
  30. package/lib/lowcode-components/circular-progress-chart/index.d.ts +26 -0
  31. package/lib/lowcode-components/circular-progress-chart/index.d.ts.map +1 -0
  32. package/lib/lowcode-components/circular-progress-chart/index.js +179 -0
  33. package/lib/lowcode-components/circular-progress-chart/index.js.map +1 -0
  34. package/lib/lowcode-components/column-chart/index.d.ts +11 -6
  35. package/lib/lowcode-components/column-chart/index.d.ts.map +1 -1
  36. package/lib/lowcode-components/column-chart/index.js +115 -16
  37. package/lib/lowcode-components/column-chart/index.js.map +1 -1
  38. package/lib/lowcode-components/data-number/index.d.ts +10 -0
  39. package/lib/lowcode-components/data-number/index.d.ts.map +1 -1
  40. package/lib/lowcode-components/data-number/index.js +80 -6
  41. package/lib/lowcode-components/data-number/index.js.map +1 -1
  42. package/lib/lowcode-components/effectScatter-map/index.d.ts +10 -6
  43. package/lib/lowcode-components/effectScatter-map/index.d.ts.map +1 -1
  44. package/lib/lowcode-components/effectScatter-map/index.js +87 -9
  45. package/lib/lowcode-components/effectScatter-map/index.js.map +1 -1
  46. package/lib/lowcode-components/gauge-chart/index.d.ts +10 -6
  47. package/lib/lowcode-components/gauge-chart/index.d.ts.map +1 -1
  48. package/lib/lowcode-components/gauge-chart/index.js +65 -8
  49. package/lib/lowcode-components/gauge-chart/index.js.map +1 -1
  50. package/lib/lowcode-components/index.d.ts +8 -0
  51. package/lib/lowcode-components/index.d.ts.map +1 -1
  52. package/lib/lowcode-components/index.js +6 -1
  53. package/lib/lowcode-components/index.js.map +1 -1
  54. package/lib/lowcode-components/line-chart/index.d.ts +10 -6
  55. package/lib/lowcode-components/line-chart/index.d.ts.map +1 -1
  56. package/lib/lowcode-components/line-chart/index.js +91 -11
  57. package/lib/lowcode-components/line-chart/index.js.map +1 -1
  58. package/lib/lowcode-components/liquid-chart/index.d.ts +10 -6
  59. package/lib/lowcode-components/liquid-chart/index.d.ts.map +1 -1
  60. package/lib/lowcode-components/liquid-chart/index.js +64 -7
  61. package/lib/lowcode-components/liquid-chart/index.js.map +1 -1
  62. package/lib/lowcode-components/lowcode-view/component/assets.d.ts.map +1 -1
  63. package/lib/lowcode-components/lowcode-view/component/assets.js +46 -0
  64. package/lib/lowcode-components/lowcode-view/component/assets.js.map +1 -1
  65. package/lib/lowcode-components/lowcode-view/component/component-container.d.ts.map +1 -1
  66. package/lib/lowcode-components/lowcode-view/component/component-container.js +30 -29
  67. package/lib/lowcode-components/lowcode-view/component/component-container.js.map +1 -1
  68. package/lib/lowcode-components/pie-chart/index.d.ts +11 -6
  69. package/lib/lowcode-components/pie-chart/index.d.ts.map +1 -1
  70. package/lib/lowcode-components/pie-chart/index.js +102 -15
  71. package/lib/lowcode-components/pie-chart/index.js.map +1 -1
  72. package/lib/lowcode-components/text-scroller/index.d.ts +23 -0
  73. package/lib/lowcode-components/text-scroller/index.d.ts.map +1 -0
  74. package/lib/lowcode-components/text-scroller/index.js +96 -0
  75. package/lib/lowcode-components/text-scroller/index.js.map +1 -0
  76. package/lib/lowcode-components/text-scroller/index.less +29 -0
  77. package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
  78. package/lib/tmpl/control-type-supportor.js +1 -0
  79. package/lib/tmpl/control-type-supportor.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/aldehyde/controls/entry-control.tsx +12 -0
  82. package/src/aldehyde/controls/select/index.tsx +1 -0
  83. package/src/aldehyde/controls/view-control.tsx +1 -0
  84. package/src/aldehyde/detail/view/act-dtmpl-view.tsx +22 -23
  85. package/src/aldehyde/lowcode-components/bar-chart/index.tsx +100 -19
  86. package/src/aldehyde/lowcode-components/base-map/index.tsx +94 -15
  87. package/src/aldehyde/lowcode-components/base-table/index.less +59 -0
  88. package/src/aldehyde/lowcode-components/base-table/index.tsx +233 -0
  89. package/src/aldehyde/lowcode-components/capsule-bar-chart/index.tsx +219 -0
  90. package/src/aldehyde/lowcode-components/circular-progress-chart/index.tsx +201 -0
  91. package/src/aldehyde/lowcode-components/column-chart/index.tsx +128 -24
  92. package/src/aldehyde/lowcode-components/data-number/index.tsx +89 -7
  93. package/src/aldehyde/lowcode-components/data.d.ts +6 -0
  94. package/src/aldehyde/lowcode-components/effectScatter-map/index.tsx +93 -19
  95. package/src/aldehyde/lowcode-components/gauge-chart/index.tsx +73 -16
  96. package/src/aldehyde/lowcode-components/index.ts +10 -1
  97. package/src/aldehyde/lowcode-components/line-chart/index.tsx +105 -22
  98. package/src/aldehyde/lowcode-components/liquid-chart/index.tsx +70 -15
  99. package/src/aldehyde/lowcode-components/lowcode-view/component/assets.ts +46 -0
  100. package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +29 -28
  101. package/src/aldehyde/lowcode-components/pie-chart/index.tsx +111 -25
  102. package/src/aldehyde/lowcode-components/text-scroller/index.less +29 -0
  103. package/src/aldehyde/lowcode-components/text-scroller/index.tsx +122 -0
  104. package/src/aldehyde/tmpl/control-type-supportor.tsx +1 -0
@@ -1,14 +1,48 @@
1
1
  import * as echarts from 'echarts';
2
2
  import React, { useEffect, useRef, useState, ForwardedRef, forwardRef, useImperativeHandle } from 'react';
3
- import lodash from 'lodash';
3
+ import _ from 'lodash';
4
+ import HydrocarbonService from "../../tmpl/hcservice-v3";
5
+ import { DataConfigProps } from "../data";
6
+
7
+ const defColumnValue = [
8
+ {
9
+ data: [["1990", 52], ["1991", 45], ["1992", 35], ["1993", 41], ["1994", 23], ["1995", 25], ["1996", 15]],
10
+ type: 'bar',
11
+ }
12
+ ];
13
+
14
+ const defStackValue = [
15
+ {
16
+ data: [["1990", 3], ["1991", 4], ["1992", 3.5], ["1993", 5], ["1994", 4.9], ["1995", 6], ["1996", 7]],
17
+ type: 'bar',
18
+ name: "Val1",
19
+ stack: "stack"
20
+ },
21
+ {
22
+ data: [["1990", 3], ["1991", 4], ["1992", 3.5], ["1993", 5], ["1994", 4.9], ["1995", 6], ["1996", 7]],
23
+ type: 'bar',
24
+ name: "Val2",
25
+ stack: "stack"
26
+ }
27
+ ];
28
+
29
+ const defDatas = {
30
+ ColumnChart: defColumnValue,
31
+ StackColumnChart: defStackValue,
32
+ };
4
33
 
5
34
  const defOption = {
35
+ title: {
36
+ text: '暂无数据',
37
+ left: 'center',
38
+ top: 'middle',
39
+ show: false, // 无数据时显示
40
+ },
6
41
  tooltip: { trigger: "axis" },
7
42
  grid: { top: 30, let: 30, right: 20, bottom: 30 },
8
43
  xAxis: {
9
44
  type: 'category',
10
45
  boundaryGap: true,
11
- data: ['1990', '1991', '1992', '1993', '1994', '1995', '1996'],
12
46
  axisTick: { show: true },
13
47
  },
14
48
  yAxis: {
@@ -16,12 +50,7 @@ const defOption = {
16
50
  },
17
51
  legend: { show: false },
18
52
  barMaxWidth: 30,
19
- series: [
20
- {
21
- data: [525, 459, 357, 414, 234, 250, 156],
22
- type: 'bar',
23
- }
24
- ]
53
+ series: defColumnValue
25
54
  };
26
55
 
27
56
  const legends = {
@@ -35,7 +64,26 @@ const legends = {
35
64
  rightBottom: { right: 5, bottom: 0 },
36
65
  };
37
66
 
38
- export interface ChartComponentStyle {
67
+ // 处理数据格式
68
+ const handleData = (data: { config: { [key: string]: string }, value: { [key: string]: any }[] }[]) => {
69
+ if (!data?.length) {
70
+ return [];
71
+ }
72
+ const temData = data.map((r) => {
73
+ const { config, value } = r;
74
+ const vNames = Object.keys(config).filter((r) => r.startsWith("v")).sort((a, b) => parseInt(a.substring(1)) - parseInt(b.substring(1)));
75
+ return {
76
+ name: config.d1,
77
+ data: vNames.map((r) => ({
78
+ name: config[r],
79
+ data: value.map((v) => [v["d1"], v[r]]),
80
+ }))
81
+ };
82
+ });
83
+ return temData[0]?.data || [];
84
+ };
85
+
86
+ export interface ComponentStyle {
39
87
  tooltip?: { show: boolean };
40
88
  color?: string[];
41
89
  grid?: { top: number, let: number, right: number, bottom: number };
@@ -45,27 +93,42 @@ export interface ChartComponentStyle {
45
93
  barMaxWidth?: number;
46
94
  }
47
95
 
48
- export interface ChartComponentProps {
49
- style?: ChartComponentStyle;
50
- base: { width: number, height: number }
96
+ export interface ComponentProps {
97
+ style?: ComponentStyle;
98
+ base: { width: number, height: number, type: string },
99
+ data?: DataConfigProps;
100
+ isDesignMode?: boolean; // 是否编辑模式
51
101
  }
52
102
 
53
- export interface BaseTextComponentRef {
54
- updateConfig: (newConfig: ChartComponentProps) => void;
103
+ export interface ComponentRef {
104
+ updateConfig: (newConfig: ComponentProps) => void;
105
+ destroy: () => void;
55
106
  }
56
107
 
57
- const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseTextComponentRef>) => {
58
- const [config, setConfig] = useState<ChartComponentStyle>(props.style || {});
59
- const [size, setSize] = useState<{ width: number, height: number }>()
108
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
109
+ const { style, base: { type: componentType }, data: propsData, isDesignMode } = props;
110
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
111
+ const [size, setSize] = useState<{ width: number, height: number }>();
112
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
113
+ const [data, setData] = useState<{ name: string, data: any }[]>([]);
60
114
  const chartRef = useRef<HTMLDivElement>(null);
61
115
  const chart = useRef<any>(null);
116
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
117
+
118
+ const handleDestroy = () => {
119
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
120
+ window.removeEventListener('resize', handleResize);
121
+ chart.current.dispose();
122
+ };
62
123
 
63
124
  useImperativeHandle(ref, () => ({
64
125
  updateConfig: (newConfig) => {
65
- const { base, style } = newConfig;
66
- setConfig({ ...(style || {}) });
126
+ const { base, style: newStyle, data: newDataConfig } = newConfig;
127
+ setConfig({ ...(newStyle || {}) });
67
128
  setSize({ width: base.width, height: base.height });
129
+ setDataConfig(newDataConfig);
68
130
  },
131
+ destroy: handleDestroy,
69
132
  }));
70
133
 
71
134
  // 窗口大小变化时重新调整图表大小
@@ -77,23 +140,64 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
77
140
  chart.current = echarts.init(chartRef.current);
78
141
  window.addEventListener('resize', handleResize);
79
142
  return () => {
80
- window.removeEventListener('resize', handleResize);
81
- chart.current.dispose();
143
+ handleDestroy();
82
144
  }
83
145
  }, []);
84
146
 
147
+
148
+ // 请求数据
149
+ const getData = async () => {
150
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
151
+ const temData = handleData(value);
152
+ setData(temData);
153
+ return config;
154
+ };
155
+
156
+ // 初始化请求数据
157
+ const getInitData = async () => {
158
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
159
+ const config = await getData();
160
+ if (config?.requestType === "polling") {
161
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
162
+ }
163
+ };
164
+
165
+ // 静态数据处理
166
+ useEffect(() => {
167
+ if (dataConfig?.sourceType === 'staticData') {
168
+ setData(handleData(dataConfig.staticData));
169
+ }
170
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
171
+
172
+ /**
173
+ * 数据源数据请求
174
+ * 1、编辑态不请求数据
175
+ */
176
+ useEffect(() => {
177
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
178
+ getInitData();
179
+ } else if (dataConfig?.sourceType === 'sourceId') {
180
+ setData([]);
181
+ }
182
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
183
+
85
184
  const renderChart = () => {
86
185
  const { grid, barMaxWidth, legend, tooltip, color, xAxis, yAxis, } = config
87
- const option = lodash.cloneDeep(defOption);
186
+ const option = _.cloneDeep(defOption);
187
+ // 编辑态无数据显示默认数据
188
+ const temData = isDesignMode && !data?.length ? defDatas[componentType] || [] : data;
88
189
  option.barMaxWidth = barMaxWidth;
89
190
  option.grid = grid;
90
191
  option.legend = { ...legend, ...legends[legend?.position] };
91
192
  option.tooltip = { trigger: "axis", ...tooltip };
92
193
  option.xAxis = { ...option.xAxis, ...xAxis, axisTick: { show: xAxis?.axisLine?.show } };
93
194
  option.yAxis = { ...option.yAxis, ...yAxis };
94
- option.series = option.series.map((r, index) => ({
195
+ option.title.show = !temData?.length;
196
+ option.series = temData.map((r, index) => ({
197
+ type: "bar",
95
198
  ...r,
96
199
  itemStyle: { color: color[index] },
200
+ stack: componentType === 'StackColumnChart' ? 'stack' : undefined,
97
201
  }));
98
202
  chart.current.setOption(option, true);
99
203
  }
@@ -101,7 +205,7 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
101
205
  if (config) {
102
206
  renderChart();
103
207
  }
104
- }, [config]);
208
+ }, [config, data]);
105
209
 
106
210
  useEffect(() => {
107
211
  if (size) {
@@ -1,7 +1,24 @@
1
1
 
2
- import React, { ForwardedRef, forwardRef, useImperativeHandle, useState } from 'react';
2
+ import React, { ForwardedRef, forwardRef, useEffect, useImperativeHandle, useMemo, useState, useRef } from 'react';
3
+ import HydrocarbonService from "../../tmpl/hcservice-v3";
4
+ import { DataConfigProps } from "../data";
3
5
  import './index.less';
4
6
 
7
+ const rules = {
8
+ eq: '==',
9
+ ne: '!=',
10
+ gt: '>',
11
+ gte: '>=',
12
+ lt: '<',
13
+ lte: '<=',
14
+ };
15
+
16
+ interface EnumeProps {
17
+ rule: string,
18
+ num: number,
19
+ value: string
20
+ }
21
+
5
22
  export interface ComponentStyle {
6
23
  color?: string;
7
24
  fontSize?: number;
@@ -14,28 +31,93 @@ export interface ComponentStyle {
14
31
  letterSpacing?: number;
15
32
  lineHeight?: number;
16
33
  defaultValue?: number;
34
+ enume?: EnumeProps[];
17
35
  }
18
36
 
19
37
  export interface ComponentProps {
20
38
  style?: ComponentStyle;
39
+ data?: DataConfigProps;
40
+ isDesignMode?: boolean; // 是否编辑模式
21
41
  }
22
42
 
23
43
  export interface ComponentRef {
24
44
  updateConfig: (newConfig: ComponentProps) => void;
45
+ destroy: () => void;
25
46
  }
26
47
 
27
48
  const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
28
- const [config, setConfig] = useState<ComponentStyle>(props.style || {});
29
- const [data, setData] = useState<number>(props.style?.defaultValue || 0);
49
+ const { style, data: propsData, isDesignMode } = props;
50
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
51
+ const [enume, setEnume] = useState<EnumeProps[]>(style?.enume || []);
52
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
53
+ const [data, setData] = useState<number>(style?.defaultValue);
54
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
55
+
56
+ const handleDestroy = () => {
57
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
58
+ };
59
+
30
60
 
31
- useImperativeHandle(ref, () => ({
32
- updateConfig: (newConfig) => {
33
- const { style: { defaultValue, ...style } } = newConfig;
61
+ useImperativeHandle(ref, () => ({ // 暴露到外部func
62
+ updateConfig: (newConfig) => { // 组件更新配置
63
+ const { style: { defaultValue, enume: newEnume, ...style }, data: newDataConfig } = newConfig;
34
64
  setConfig({ ...(style || {}) });
35
65
  setData(defaultValue || 0);
66
+ setEnume([...(newEnume || [])]);
67
+ setDataConfig(newDataConfig);
36
68
  },
69
+ destroy: handleDestroy
37
70
  }));
38
71
 
72
+ // 请求数据
73
+ const getData = async () => {
74
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
75
+ const temData = value?.[0]?.value?.[0]?.v1;
76
+ setData(temData);
77
+ return config;
78
+ }
79
+
80
+ // 初始化请求数据
81
+ const getInitData = async () => {
82
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
83
+ const config = await getData();
84
+ if (config?.requestType === "polling") {
85
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
86
+ }
87
+ }
88
+
89
+ useEffect(() => {
90
+ return () => {
91
+ handleDestroy();
92
+ }
93
+ }, []);
94
+
95
+ // 静态数据处理
96
+ useEffect(() => {
97
+ if (dataConfig?.sourceType === 'staticData') {
98
+ const { value } = dataConfig.staticData || {};
99
+ setData(value);
100
+ }
101
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
102
+
103
+ /**
104
+ * 数据源数据请求
105
+ * 1、编辑态不请求数据
106
+ */
107
+ useEffect(() => {
108
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
109
+ getInitData();
110
+ }
111
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
112
+
113
+ const value = useMemo(() => {
114
+ if (enume?.length > 0) { // 枚举
115
+ const temEnume = enume.filter(item => item.rule && (item.num || item.num === 0));
116
+ return temEnume.find((item) => eval(`${data} ${rules[item.rule]} ${item.num}`))?.value || data;
117
+ } else {
118
+ return data;
119
+ }
120
+ }, [data, enume]);
39
121
 
40
122
  return (
41
123
  <div
@@ -46,7 +128,7 @@ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>
46
128
  WebkitTextStrokeColor: config?.strokeColor,
47
129
  }}
48
130
  >
49
- {data}
131
+ {value}
50
132
  </div>
51
133
  );
52
134
  });
@@ -0,0 +1,6 @@
1
+ export interface DataConfigProps {
2
+ sourceType: string;
3
+ serverKey?: string;
4
+ sourceId?: string;
5
+ staticData?: any;
6
+ }
@@ -2,6 +2,11 @@ import * as echarts from 'echarts';
2
2
  import React, { useEffect, useRef, useState, ForwardedRef, forwardRef, useImperativeHandle } from 'react';
3
3
  import _ from 'lodash';
4
4
  import chinaJson from "../assets/china.json";
5
+ import HydrocarbonService from "../../tmpl/hcservice-v3";
6
+ import { DataConfigProps } from "../data";
7
+
8
+ const defData = [{ name: '北京', value: [116.41, 40.19, 100] }];
9
+
5
10
 
6
11
  const defOption = {
7
12
  tooltip: {
@@ -34,7 +39,8 @@ const defOption = {
34
39
  map: 'china',
35
40
  geoIndex: 0,
36
41
  aspectScale: 0.75, //长宽比
37
- data: []
42
+ data: [],
43
+ tooltip: { show: false }
38
44
  },
39
45
  {
40
46
  type: 'effectScatter',
@@ -51,38 +57,72 @@ const defOption = {
51
57
  },
52
58
  zlevel: 1,
53
59
  encode: { value: 2 },
54
- data: [{ name: '北京', value: [116.46, 39.92, 100] }]
60
+ data: defData
55
61
  }
56
62
  ]
57
63
  };
58
64
 
59
- export interface ChartComponentStyle {
65
+ // 处理数据格式
66
+ const handleData = (data: { config: { [key: string]: string }, value: { [key: string]: any }[] }[]) => {
67
+ if (!data?.length) {
68
+ return [];
69
+ }
70
+ const temData = data.map((r) => {
71
+ const { config, value } = r;
72
+ const vNames = Object.keys(config).filter((r) => r.startsWith("v")).sort((a, b) => parseInt(a.substring(1)) - parseInt(b.substring(1)));
73
+ return {
74
+ name: config.d1,
75
+ data: vNames.map((r) => ({
76
+ name: config[r],
77
+ value: value[0]?.[r],
78
+ }))
79
+ };
80
+ });
81
+ return temData[0]?.data || [];
82
+ };
83
+
84
+ export interface ComponentStyle {
60
85
  tooltip?: { show: boolean };
61
86
  geo?: { [key: string]: any };
62
87
  effectScatter?: { [key: string]: any };
63
88
  }
64
89
 
65
- export interface ChartComponentProps {
66
- style?: ChartComponentStyle;
67
- base: { width: number, height: number }
90
+ export interface ComponentProps {
91
+ style?: ComponentStyle;
92
+ base: { width: number, height: number },
93
+ data?: DataConfigProps;
94
+ isDesignMode?: boolean; // 是否编辑模式
68
95
  }
69
96
 
70
- export interface BaseTextComponentRef {
71
- updateConfig: (newConfig: ChartComponentProps) => void;
97
+ export interface ComponentRef {
98
+ updateConfig: (newConfig: ComponentProps) => void;
99
+ destroy: () => void;
72
100
  }
73
101
 
74
- const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseTextComponentRef>) => {
75
- const [config, setConfig] = useState<ChartComponentStyle>(props.style || {});
76
- const [size, setSize] = useState<{ width: number, height: number }>()
102
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
103
+ const { style, data: propsData, isDesignMode } = props;
104
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
105
+ const [size, setSize] = useState<{ width: number, height: number }>();
106
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
107
+ const [data, setData] = useState<{ name: string, value: number[] }[]>([]);
77
108
  const chartRef = useRef<HTMLDivElement>(null);
78
109
  const chart = useRef<any>(null);
110
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
111
+
112
+ const handleDestroy = () => {
113
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
114
+ window.removeEventListener('resize', handleResize);
115
+ chart.current.dispose();
116
+ };
79
117
 
80
118
  useImperativeHandle(ref, () => ({
81
119
  updateConfig: (newConfig) => {
82
- const { base, style } = newConfig;
83
- setConfig({ ...(style || {}) });
120
+ const { base, style: newStyle, data: newDataConfig } = newConfig;
121
+ setConfig({ ...(newStyle || {}) });
84
122
  setSize({ width: base.width, height: base.height });
123
+ setDataConfig(newDataConfig);
85
124
  },
125
+ destroy: handleDestroy,
86
126
  }));
87
127
 
88
128
  // 窗口大小变化时重新调整图表大小
@@ -95,21 +135,55 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
95
135
  chart.current = echarts.init(chartRef.current, null, { renderer: 'svg' });
96
136
  window.addEventListener('resize', handleResize);
97
137
  return () => {
98
- window.removeEventListener('resize', handleResize);
99
- chart.current.dispose();
138
+ handleDestroy();
100
139
  }
101
140
  }, []);
102
141
 
142
+ // 请求数据
143
+ const getData = async () => {
144
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
145
+ setData(handleData(value));
146
+ return config;
147
+ };
148
+
149
+ // 初始化请求数据
150
+ const getInitData = async () => {
151
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
152
+ const config = await getData();
153
+ if (config?.requestType === "polling") {
154
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
155
+ }
156
+ };
157
+
158
+ // 静态数据处理
159
+ useEffect(() => {
160
+ if (dataConfig?.sourceType === 'staticData') {
161
+ setData(dataConfig.staticData || []);
162
+ }
163
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
164
+
165
+ /**
166
+ * 数据源数据请求
167
+ * 1、编辑态不请求数据
168
+ */
169
+ useEffect(() => {
170
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
171
+ getInitData();
172
+ } else if (dataConfig?.sourceType === 'sourceId') {
173
+ setData([]);
174
+ }
175
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
176
+
103
177
  const renderChart = () => {
104
178
  const { tooltip, geo, effectScatter } = config
105
179
  const option = _.cloneDeep(defOption);
180
+ // 编辑态无数据显示默认数据
181
+ const temData = isDesignMode && !data?.length ? defData : data;
106
182
  option.tooltip = { trigger: "item", ...tooltip };
107
183
  option.geo = { ...option.geo, ...geo, ...geo.normal };
108
184
  option.series = option.series.map((item: any) => {
109
185
  if (item.type === 'effectScatter') {
110
- return {
111
- ...item, ...effectScatter
112
- };
186
+ return { ...item, ...effectScatter, data: temData };
113
187
  }
114
188
  return item;
115
189
  });
@@ -119,7 +193,7 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
119
193
  if (config) {
120
194
  renderChart();
121
195
  }
122
- }, [config]);
196
+ }, [config, data]);
123
197
 
124
198
  useEffect(() => {
125
199
  if (size) {