aldehyde 0.2.283 → 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 (203) hide show
  1. package/lib/controls/entity-select/entity-select.d.ts +2 -2
  2. package/lib/controls/entity-select/entity-select.d.ts.map +1 -1
  3. package/lib/controls/entity-select/entity-select.js +14 -12
  4. package/lib/controls/entity-select/entity-select.js.map +1 -1
  5. package/lib/controls/entry-control.d.ts.map +1 -1
  6. package/lib/controls/entry-control.js +4 -0
  7. package/lib/controls/entry-control.js.map +1 -1
  8. package/lib/controls/select/index.d.ts.map +1 -1
  9. package/lib/controls/select/index.js +1 -0
  10. package/lib/controls/select/index.js.map +1 -1
  11. package/lib/controls/view-control.d.ts.map +1 -1
  12. package/lib/controls/view-control.js +1 -0
  13. package/lib/controls/view-control.js.map +1 -1
  14. package/lib/detail/view/act-dtmpl-view.d.ts.map +1 -1
  15. package/lib/detail/view/act-dtmpl-view.js +3 -2
  16. package/lib/detail/view/act-dtmpl-view.js.map +1 -1
  17. package/lib/detail/view/dtmpl-view.js +1 -1
  18. package/lib/detail/view/dtmpl-view.js.map +1 -1
  19. package/lib/form/form-Item-group.d.ts.map +1 -1
  20. package/lib/form/form-Item-group.js +0 -1
  21. package/lib/form/form-Item-group.js.map +1 -1
  22. package/lib/lowcode-components/bar-chart/index.d.ts +10 -6
  23. package/lib/lowcode-components/bar-chart/index.d.ts.map +1 -1
  24. package/lib/lowcode-components/bar-chart/index.js +91 -11
  25. package/lib/lowcode-components/bar-chart/index.js.map +1 -1
  26. package/lib/lowcode-components/base-map/index.d.ts +10 -6
  27. package/lib/lowcode-components/base-map/index.d.ts.map +1 -1
  28. package/lib/lowcode-components/base-map/index.js +86 -7
  29. package/lib/lowcode-components/base-map/index.js.map +1 -1
  30. package/lib/lowcode-components/base-table/index.d.ts +53 -0
  31. package/lib/lowcode-components/base-table/index.d.ts.map +1 -0
  32. package/lib/lowcode-components/base-table/index.js +158 -0
  33. package/lib/lowcode-components/base-table/index.js.map +1 -0
  34. package/lib/lowcode-components/base-table/index.less +59 -0
  35. package/lib/lowcode-components/capsule-bar-chart/index.d.ts +43 -0
  36. package/lib/lowcode-components/capsule-bar-chart/index.d.ts.map +1 -0
  37. package/lib/lowcode-components/capsule-bar-chart/index.js +179 -0
  38. package/lib/lowcode-components/capsule-bar-chart/index.js.map +1 -0
  39. package/lib/lowcode-components/circular-progress-chart/index.d.ts +26 -0
  40. package/lib/lowcode-components/circular-progress-chart/index.d.ts.map +1 -0
  41. package/lib/lowcode-components/circular-progress-chart/index.js +179 -0
  42. package/lib/lowcode-components/circular-progress-chart/index.js.map +1 -0
  43. package/lib/lowcode-components/column-chart/index.d.ts +11 -6
  44. package/lib/lowcode-components/column-chart/index.d.ts.map +1 -1
  45. package/lib/lowcode-components/column-chart/index.js +115 -16
  46. package/lib/lowcode-components/column-chart/index.js.map +1 -1
  47. package/lib/lowcode-components/data-number/index.d.ts +10 -0
  48. package/lib/lowcode-components/data-number/index.d.ts.map +1 -1
  49. package/lib/lowcode-components/data-number/index.js +80 -6
  50. package/lib/lowcode-components/data-number/index.js.map +1 -1
  51. package/lib/lowcode-components/decoration/decoration1/index.d.ts +19 -0
  52. package/lib/lowcode-components/decoration/decoration1/index.d.ts.map +1 -0
  53. package/lib/lowcode-components/decoration/decoration1/index.js +58 -0
  54. package/lib/lowcode-components/decoration/decoration1/index.js.map +1 -0
  55. package/lib/lowcode-components/decoration/decoration1/index.less +8 -0
  56. package/lib/lowcode-components/decoration/decoration10/index.d.ts +20 -0
  57. package/lib/lowcode-components/decoration/decoration10/index.d.ts.map +1 -0
  58. package/lib/lowcode-components/decoration/decoration10/index.js +29 -0
  59. package/lib/lowcode-components/decoration/decoration10/index.js.map +1 -0
  60. package/lib/lowcode-components/decoration/decoration10/index.less +6 -0
  61. package/lib/lowcode-components/decoration/decoration11/index.d.ts +20 -0
  62. package/lib/lowcode-components/decoration/decoration11/index.d.ts.map +1 -0
  63. package/lib/lowcode-components/decoration/decoration11/index.js +81 -0
  64. package/lib/lowcode-components/decoration/decoration11/index.js.map +1 -0
  65. package/lib/lowcode-components/decoration/decoration11/index.less +6 -0
  66. package/lib/lowcode-components/decoration/decoration2/index.d.ts +19 -0
  67. package/lib/lowcode-components/decoration/decoration2/index.d.ts.map +1 -0
  68. package/lib/lowcode-components/decoration/decoration2/index.js +23 -0
  69. package/lib/lowcode-components/decoration/decoration2/index.js.map +1 -0
  70. package/lib/lowcode-components/decoration/decoration2/index.less +7 -0
  71. package/lib/lowcode-components/decoration/decoration3/index.d.ts +19 -0
  72. package/lib/lowcode-components/decoration/decoration3/index.d.ts.map +1 -0
  73. package/lib/lowcode-components/decoration/decoration3/index.js +39 -0
  74. package/lib/lowcode-components/decoration/decoration3/index.js.map +1 -0
  75. package/lib/lowcode-components/decoration/decoration3/index.less +8 -0
  76. package/lib/lowcode-components/decoration/decoration4/index.d.ts +19 -0
  77. package/lib/lowcode-components/decoration/decoration4/index.d.ts.map +1 -0
  78. package/lib/lowcode-components/decoration/decoration4/index.js +20 -0
  79. package/lib/lowcode-components/decoration/decoration4/index.js.map +1 -0
  80. package/lib/lowcode-components/decoration/decoration4/index.less +30 -0
  81. package/lib/lowcode-components/decoration/decoration5/index.d.ts +19 -0
  82. package/lib/lowcode-components/decoration/decoration5/index.d.ts.map +1 -0
  83. package/lib/lowcode-components/decoration/decoration5/index.js +56 -0
  84. package/lib/lowcode-components/decoration/decoration5/index.js.map +1 -0
  85. package/lib/lowcode-components/decoration/decoration5/index.less +4 -0
  86. package/lib/lowcode-components/decoration/decoration6/index.d.ts +19 -0
  87. package/lib/lowcode-components/decoration/decoration6/index.d.ts.map +1 -0
  88. package/lib/lowcode-components/decoration/decoration6/index.js +55 -0
  89. package/lib/lowcode-components/decoration/decoration6/index.js.map +1 -0
  90. package/lib/lowcode-components/decoration/decoration6/index.less +8 -0
  91. package/lib/lowcode-components/decoration/decoration7/index.d.ts +20 -0
  92. package/lib/lowcode-components/decoration/decoration7/index.d.ts.map +1 -0
  93. package/lib/lowcode-components/decoration/decoration7/index.js +28 -0
  94. package/lib/lowcode-components/decoration/decoration7/index.js.map +1 -0
  95. package/lib/lowcode-components/decoration/decoration7/index.less +5 -0
  96. package/lib/lowcode-components/decoration/decoration8/index.d.ts +20 -0
  97. package/lib/lowcode-components/decoration/decoration8/index.d.ts.map +1 -0
  98. package/lib/lowcode-components/decoration/decoration8/index.js +31 -0
  99. package/lib/lowcode-components/decoration/decoration8/index.js.map +1 -0
  100. package/lib/lowcode-components/decoration/decoration8/index.less +15 -0
  101. package/lib/lowcode-components/decoration/decoration9/index.d.ts +20 -0
  102. package/lib/lowcode-components/decoration/decoration9/index.d.ts.map +1 -0
  103. package/lib/lowcode-components/decoration/decoration9/index.js +52 -0
  104. package/lib/lowcode-components/decoration/decoration9/index.js.map +1 -0
  105. package/lib/lowcode-components/decoration/decoration9/index.less +5 -0
  106. package/lib/lowcode-components/effectScatter-map/index.d.ts +10 -6
  107. package/lib/lowcode-components/effectScatter-map/index.d.ts.map +1 -1
  108. package/lib/lowcode-components/effectScatter-map/index.js +87 -9
  109. package/lib/lowcode-components/effectScatter-map/index.js.map +1 -1
  110. package/lib/lowcode-components/gauge-chart/index.d.ts +10 -6
  111. package/lib/lowcode-components/gauge-chart/index.d.ts.map +1 -1
  112. package/lib/lowcode-components/gauge-chart/index.js +65 -8
  113. package/lib/lowcode-components/gauge-chart/index.js.map +1 -1
  114. package/lib/lowcode-components/index.d.ts +30 -0
  115. package/lib/lowcode-components/index.d.ts.map +1 -1
  116. package/lib/lowcode-components/index.js +25 -28
  117. package/lib/lowcode-components/index.js.map +1 -1
  118. package/lib/lowcode-components/line-chart/index.d.ts +10 -6
  119. package/lib/lowcode-components/line-chart/index.d.ts.map +1 -1
  120. package/lib/lowcode-components/line-chart/index.js +91 -11
  121. package/lib/lowcode-components/line-chart/index.js.map +1 -1
  122. package/lib/lowcode-components/liquid-chart/index.d.ts +10 -6
  123. package/lib/lowcode-components/liquid-chart/index.d.ts.map +1 -1
  124. package/lib/lowcode-components/liquid-chart/index.js +64 -7
  125. package/lib/lowcode-components/liquid-chart/index.js.map +1 -1
  126. package/lib/lowcode-components/lowcode-view/component/assets.d.ts.map +1 -1
  127. package/lib/lowcode-components/lowcode-view/component/assets.js +134 -0
  128. package/lib/lowcode-components/lowcode-view/component/assets.js.map +1 -1
  129. package/lib/lowcode-components/lowcode-view/component/component-container.d.ts.map +1 -1
  130. package/lib/lowcode-components/lowcode-view/component/component-container.js +30 -29
  131. package/lib/lowcode-components/lowcode-view/component/component-container.js.map +1 -1
  132. package/lib/lowcode-components/pie-chart/index.d.ts +11 -6
  133. package/lib/lowcode-components/pie-chart/index.d.ts.map +1 -1
  134. package/lib/lowcode-components/pie-chart/index.js +102 -15
  135. package/lib/lowcode-components/pie-chart/index.js.map +1 -1
  136. package/lib/lowcode-components/text-scroller/index.d.ts +23 -0
  137. package/lib/lowcode-components/text-scroller/index.d.ts.map +1 -0
  138. package/lib/lowcode-components/text-scroller/index.js +96 -0
  139. package/lib/lowcode-components/text-scroller/index.js.map +1 -0
  140. package/lib/lowcode-components/text-scroller/index.less +29 -0
  141. package/lib/table/act-table.d.ts.map +1 -1
  142. package/lib/table/act-table.js.map +1 -1
  143. package/lib/table/query-table.js +5 -5
  144. package/lib/table/query-table.js.map +1 -1
  145. package/lib/table/relation-table.d.ts.map +1 -1
  146. package/lib/table/relation-table.js +0 -2
  147. package/lib/table/relation-table.js.map +1 -1
  148. package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
  149. package/lib/tmpl/control-type-supportor.js +1 -0
  150. package/lib/tmpl/control-type-supportor.js.map +1 -1
  151. package/package.json +1 -1
  152. package/src/aldehyde/controls/entity-select/entity-select.tsx +15 -15
  153. package/src/aldehyde/controls/entry-control.tsx +12 -0
  154. package/src/aldehyde/controls/select/index.tsx +1 -0
  155. package/src/aldehyde/controls/view-control.tsx +1 -0
  156. package/src/aldehyde/detail/view/act-dtmpl-view.tsx +22 -23
  157. package/src/aldehyde/detail/view/dtmpl-view.tsx +1 -1
  158. package/src/aldehyde/form/form-Item-group.tsx +0 -1
  159. package/src/aldehyde/lowcode-components/bar-chart/index.tsx +100 -19
  160. package/src/aldehyde/lowcode-components/base-map/index.tsx +94 -15
  161. package/src/aldehyde/lowcode-components/base-table/index.less +59 -0
  162. package/src/aldehyde/lowcode-components/base-table/index.tsx +233 -0
  163. package/src/aldehyde/lowcode-components/capsule-bar-chart/index.tsx +219 -0
  164. package/src/aldehyde/lowcode-components/circular-progress-chart/index.tsx +201 -0
  165. package/src/aldehyde/lowcode-components/column-chart/index.tsx +128 -24
  166. package/src/aldehyde/lowcode-components/data-number/index.tsx +89 -7
  167. package/src/aldehyde/lowcode-components/data.d.ts +6 -0
  168. package/src/aldehyde/lowcode-components/decoration/decoration1/index.less +8 -0
  169. package/src/aldehyde/lowcode-components/decoration/decoration1/index.tsx +153 -0
  170. package/src/aldehyde/lowcode-components/decoration/decoration10/index.less +6 -0
  171. package/src/aldehyde/lowcode-components/decoration/decoration10/index.tsx +89 -0
  172. package/src/aldehyde/lowcode-components/decoration/decoration11/index.less +6 -0
  173. package/src/aldehyde/lowcode-components/decoration/decoration11/index.tsx +133 -0
  174. package/src/aldehyde/lowcode-components/decoration/decoration2/index.less +7 -0
  175. package/src/aldehyde/lowcode-components/decoration/decoration2/index.tsx +61 -0
  176. package/src/aldehyde/lowcode-components/decoration/decoration3/index.less +8 -0
  177. package/src/aldehyde/lowcode-components/decoration/decoration3/index.tsx +87 -0
  178. package/src/aldehyde/lowcode-components/decoration/decoration4/index.less +30 -0
  179. package/src/aldehyde/lowcode-components/decoration/decoration4/index.tsx +53 -0
  180. package/src/aldehyde/lowcode-components/decoration/decoration5/index.less +4 -0
  181. package/src/aldehyde/lowcode-components/decoration/decoration5/index.tsx +116 -0
  182. package/src/aldehyde/lowcode-components/decoration/decoration6/index.less +8 -0
  183. package/src/aldehyde/lowcode-components/decoration/decoration6/index.tsx +121 -0
  184. package/src/aldehyde/lowcode-components/decoration/decoration7/index.less +5 -0
  185. package/src/aldehyde/lowcode-components/decoration/decoration7/index.tsx +70 -0
  186. package/src/aldehyde/lowcode-components/decoration/decoration8/index.less +15 -0
  187. package/src/aldehyde/lowcode-components/decoration/decoration8/index.tsx +122 -0
  188. package/src/aldehyde/lowcode-components/decoration/decoration9/index.less +5 -0
  189. package/src/aldehyde/lowcode-components/decoration/decoration9/index.tsx +196 -0
  190. package/src/aldehyde/lowcode-components/effectScatter-map/index.tsx +93 -19
  191. package/src/aldehyde/lowcode-components/gauge-chart/index.tsx +73 -16
  192. package/src/aldehyde/lowcode-components/index.ts +40 -29
  193. package/src/aldehyde/lowcode-components/line-chart/index.tsx +105 -22
  194. package/src/aldehyde/lowcode-components/liquid-chart/index.tsx +70 -15
  195. package/src/aldehyde/lowcode-components/lowcode-view/component/assets.ts +134 -0
  196. package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +29 -28
  197. package/src/aldehyde/lowcode-components/pie-chart/index.tsx +111 -25
  198. package/src/aldehyde/lowcode-components/text-scroller/index.less +29 -0
  199. package/src/aldehyde/lowcode-components/text-scroller/index.tsx +122 -0
  200. package/src/aldehyde/table/act-table.tsx +0 -1
  201. package/src/aldehyde/table/query-table.tsx +5 -5
  202. package/src/aldehyde/table/relation-table.tsx +0 -2
  203. package/src/aldehyde/tmpl/control-type-supportor.tsx +1 -0
@@ -0,0 +1,233 @@
1
+ import React, { ForwardedRef, forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
2
+ import _ from "lodash";
3
+ import HcserviceV3 from "../../tmpl/hcservice-v3";
4
+ import { DataConfigProps } from "../data";
5
+ import './index.less';
6
+
7
+ const defColumns = [
8
+ { title: "姓名", dataIndex: "name" },
9
+ { title: "年龄", dataIndex: "age" },
10
+ { title: "性别", dataIndex: "sex" }
11
+ ];
12
+
13
+ const defData = [
14
+ { name: "张三", age: 18, sex: "男" },
15
+ { name: "李四", age: 20, sex: "女" },
16
+ { name: "王五", age: 22, sex: "男" }
17
+ ];
18
+
19
+ export interface ITableColumn {
20
+ dataIndex: string;
21
+ title: string;
22
+ colWidth?: number;
23
+ valueAlign?: 'left' | 'center' | 'right';
24
+ }
25
+
26
+ export interface ITableHeaderStyle {
27
+ show?: boolean;
28
+ height?: number;
29
+ background?: string;
30
+ color?: string;
31
+ fontSize?: number;
32
+ fontWeight?: number;
33
+ fontFamily?: string;
34
+ }
35
+
36
+ export interface ITableBodyStyle {
37
+ background?: string;
38
+ color?: string;
39
+ fontSize?: number;
40
+ fontWeight?: number;
41
+ fontFamily?: string;
42
+ pageSize?: number;
43
+ }
44
+
45
+ export interface ComponentStyle {
46
+ columns?: ITableColumn[];
47
+ data?: object[];
48
+ header?: ITableHeaderStyle;
49
+ body?: ITableBodyStyle;
50
+ carousel?: { speed: number, enable: boolean };
51
+ }
52
+
53
+ export interface ComponentProps {
54
+ style?: ComponentStyle;
55
+ isDesignMode?: boolean; // 是否编辑模式
56
+ data?: DataConfigProps;
57
+ request?: { pollingInterval: number, polling: boolean, pageSize: number };
58
+ }
59
+
60
+ export interface ComponentRef {
61
+ updateConfig: (newConfig: ComponentProps) => void;
62
+ destroy: () => void;
63
+ }
64
+
65
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
66
+ const { style, isDesignMode, data: propsData, request } = props;
67
+ const [headerStyle, setHeaderStyle] = useState<ITableHeaderStyle>({ ...style?.header });
68
+ const [bodyStyle, setBodyStyle] = useState<ITableBodyStyle>({ ...style?.body });
69
+ const [carousel, setCarousel] = useState<{ speed: number, enable: boolean }>({ ...style?.carousel });
70
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData });
71
+ const [columns, setColumns] = useState<ITableColumn[]>(isDesignMode ? defColumns : []);
72
+ const [data, setData] = useState<{ [key: string]: any }[]>(isDesignMode ? defData : []);
73
+ const tableRef = useRef<HTMLDivElement | null>(null);
74
+ const theadRef = useRef<HTMLTableSectionElement | null>(null);
75
+ const resizeObserverRef = useRef<ResizeObserver | null>(null);
76
+ const contentHeightRef = useRef<number>(0);
77
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
78
+
79
+ const handleDestroy = () => {
80
+ resizeObserverRef.current && resizeObserverRef.current.disconnect();
81
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
82
+ }
83
+
84
+ useImperativeHandle(ref, () => ({
85
+ updateConfig: (newConfig) => {
86
+ const { style, data: newDataConfig } = newConfig;
87
+ setHeaderStyle({ ...style?.header });
88
+ setBodyStyle({ ...style?.body });
89
+ setCarousel({ ...style?.carousel });
90
+ setDataConfig({ ...newDataConfig });
91
+ },
92
+ destroy: handleDestroy
93
+ }));
94
+
95
+
96
+ useEffect(() => {
97
+ return () => {
98
+ handleDestroy();
99
+ }
100
+ }, []);
101
+
102
+ const changeTableTrHeight = () => {
103
+ const { pageSize = 0 } = bodyStyle;
104
+ if (pageSize && data?.length) {
105
+ const tableBodyTds = tableRef.current?.getElementsByClassName('base-table-tr') || [];
106
+ const tdHeight = contentHeightRef.current / pageSize;
107
+ for (let i = 0; i < tableBodyTds.length; i++) {
108
+ tableBodyTds[i].style.height = `${tdHeight}px`;
109
+ }
110
+ }
111
+ };
112
+
113
+ useEffect(() => {
114
+ resizeObserverRef.current && resizeObserverRef.current.disconnect();
115
+ if (tableRef.current && data?.length) {
116
+ contentHeightRef.current = tableRef.current.clientHeight - (theadRef.current?.clientHeight || 0);
117
+ resizeObserverRef.current = new ResizeObserver(_.debounce((entries) => {
118
+ for (const entry of entries) {
119
+ const { height } = entry.contentRect;
120
+ contentHeightRef.current = height - (theadRef.current?.clientHeight || 0);
121
+ }
122
+ changeTableTrHeight();
123
+ }, 100));
124
+ // 开始观察
125
+ resizeObserverRef.current.observe(tableRef.current);
126
+ changeTableTrHeight();
127
+ }
128
+ }, [headerStyle?.show, data]);
129
+
130
+ useEffect(() => {
131
+ if (bodyStyle.pageSize) {
132
+ changeTableTrHeight();
133
+ }
134
+ }, [bodyStyle.pageSize]);
135
+
136
+ // 获取数据源表格配置
137
+ const getLtmplConfig = async () => {
138
+ const { ltmplConfig } = await HcserviceV3.requestLtmplConfig(dataConfig?.serverKey || null, dataConfig?.sourceId) || {};
139
+ const temColumns = ltmplConfig?.columns?.map((item) => ({ ...item, dataIndex: item.id }))?.filter((item) => !item.hidden);
140
+ setColumns(temColumns || []);
141
+ };
142
+
143
+ // 请求数据
144
+ const getData = async () => {
145
+ const pageInfo = { pageNo: 1, pageSize: request?.pageSize || 100 };
146
+ const queryKey = await HcserviceV3.requestLtmplQueryKey(dataConfig?.serverKey || null, dataConfig?.sourceId, pageInfo);
147
+ if (!queryKey?.key) {
148
+ setData([]);
149
+ return;
150
+ }
151
+ const { entities } = await HcserviceV3.requestQueryData(dataConfig?.serverKey || null, queryKey.key, pageInfo);
152
+ const temData = entities?.map((item) => item?.fieldMap) || [];
153
+ setData(temData);
154
+ };
155
+
156
+ // 初始化请求数据
157
+ const getInitData = async () => {
158
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
159
+ await getData();
160
+ if (request?.polling) {
161
+ pollingIntervalRef.current = setInterval(() => { getData(); }, request?.pollingInterval * 1000 || 60000);
162
+ }
163
+ };
164
+
165
+ // 静态数据处理
166
+ useEffect(() => {
167
+ if (dataConfig?.sourceType === 'staticData') {
168
+ const { columns: temColumns, data } = dataConfig?.staticData || {};
169
+ setColumns(temColumns || defColumns);
170
+ setData(temColumns ? data : defData);
171
+ }
172
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
173
+
174
+ /**
175
+ * 数据源数据请求
176
+ * 1、编辑态请求表头信息,不请求数据
177
+ */
178
+ useEffect(() => {
179
+ if (dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
180
+ setData([]);
181
+ getLtmplConfig();
182
+ !isDesignMode && getInitData();
183
+ } else if (dataConfig?.sourceType === 'sourceId') {
184
+ setData([]);
185
+ setColumns([]);
186
+ }
187
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
188
+
189
+ const renderEmpty = () => <div className={'base-table-empty'} style={{ ...bodyStyle }}>暂无数据</div>;
190
+
191
+ return (
192
+ <div className={'base-table'} ref={tableRef} >
193
+ {columns?.length === 0 ? renderEmpty() :
194
+ <table>
195
+ {headerStyle?.show &&
196
+ <thead style={{ ...headerStyle }} ref={theadRef}>
197
+ <tr>
198
+ {columns?.map((column: ITableColumn, index: number) => <th key={index}
199
+ style={{
200
+ width: column.colWidth,
201
+ fontWeight: headerStyle?.fontWeight,
202
+ textAlign: column.valueAlign,
203
+ }}>{column.title}</th>)}
204
+ </tr>
205
+ </thead>
206
+ }
207
+ {data?.length === 0 ? <tbody >
208
+ <tr >
209
+ <td colSpan={columns?.length}>{renderEmpty()}</td>
210
+ </tr>
211
+ </tbody> : <>
212
+ <tbody style={{ ...bodyStyle, animation: carousel.enable && data?.length > bodyStyle.pageSize ? `scroll ${carousel.speed || 3}s linear infinite` : `none` }} className="scroll-body" >
213
+ {data?.map((item: Record<string, any>, index: number) => <tr key={index} className={'base-table-tr'}>
214
+ {columns?.map((column: ITableColumn, i: number) =>
215
+ <td key={i} style={{ textAlign: column.valueAlign }}>{item[column.dataIndex]}</td>)}
216
+ </tr>)}
217
+ </tbody>
218
+ {data?.length > bodyStyle.pageSize &&
219
+ <tbody style={{ ...bodyStyle, animation: carousel.enable ? `scroll ${carousel.speed || 3}s linear infinite` : `none` }} className="scroll-body" >
220
+ {data?.map((item: Record<string, any>, index: number) => <tr key={index} className={'base-table-tr'}>
221
+ {columns?.map((column: ITableColumn, i: number) =>
222
+ <td key={i} style={{ textAlign: column.valueAlign }}>{item[column.dataIndex]}</td>)}
223
+ </tr>)}
224
+ </tbody>
225
+ }
226
+ </>}
227
+ </table>
228
+ }
229
+ </div>
230
+ );
231
+ })
232
+
233
+ export default Index;
@@ -0,0 +1,219 @@
1
+ import * as echarts from 'echarts';
2
+ import React, { useEffect, useRef, useState, ForwardedRef, forwardRef, useImperativeHandle } from 'react';
3
+ import _ from 'lodash';
4
+ import HydrocarbonService from "../../tmpl/hcservice-v3";
5
+ import { DataConfigProps } from "../data";
6
+
7
+ const defSeriesConfig = {
8
+ itemStyle: {
9
+ borderRadius: 20
10
+ },
11
+ showBackground: true,
12
+ backgroundStyle: {
13
+ color: "transparent",
14
+ borderColor: "rgba(255, 255, 255, 0.5)",
15
+ borderWidth: 0.3,
16
+ borderRadius: 20,
17
+ shadowColor: 'rgba(255, 255, 255, 0.5)',
18
+ shadowBlur: 8,
19
+ }
20
+ };
21
+
22
+ const defOption = {
23
+ title: {
24
+ text: '暂无数据',
25
+ left: 'center',
26
+ top: 'middle',
27
+ show: false, // 无数据时显示
28
+ },
29
+ tooltip: { trigger: "axis" },
30
+ grid: { top: 30, let: 30, right: 20, bottom: 30 },
31
+ yAxis: {
32
+ type: 'category',
33
+ boundaryGap: true,
34
+ axisTick: { show: true },
35
+ },
36
+ xAxis: {
37
+ type: 'value',
38
+ axisTick: { show: true },
39
+ },
40
+ legend: { show: false },
41
+ barMaxWidth: 20,
42
+ series: [
43
+ {
44
+ data: [[525, "1990"], [459, "1991"], [357, "1992"], [414, "1993"], [234, "1994"]],
45
+ type: 'bar',
46
+ ...defSeriesConfig
47
+ }
48
+ ]
49
+ };
50
+
51
+ const legends = {
52
+ top: { top: 0 },
53
+ bottom: { bottom: 0 },
54
+ left: { left: 5, top: "center" },
55
+ right: { right: 5, top: "center" },
56
+ leftTop: { left: 5 },
57
+ rightTop: { right: 5 },
58
+ leftBottom: { left: 5, bottom: 0 },
59
+ rightBottom: { right: 5, bottom: 0 },
60
+ };
61
+
62
+ // 处理数据格式
63
+ const handleData = (data: { config: { [key: string]: string }, value: { [key: string]: any }[] }[]) => {
64
+ if (!data?.length) {
65
+ return [];
66
+ }
67
+ const temData = data.map((r) => {
68
+ const { config, value } = r;
69
+ const vNames = Object.keys(config).filter((r) => r.startsWith("v")).sort((a, b) => parseInt(a.substring(1)) - parseInt(b.substring(1)));
70
+ return {
71
+ name: config.d1,
72
+ data: vNames.map((r) => ({
73
+ name: config[r],
74
+ data: value.map((v) => [v[r], v["d1"]]),
75
+ }))
76
+ };
77
+ });
78
+ return temData[0]?.data || [];
79
+ };
80
+
81
+ export interface ComponentStyle {
82
+ tooltip?: { show: boolean };
83
+ color?: string[];
84
+ grid?: { top: number, let: number, right: number, bottom: number };
85
+ xAxis?: { [key: string]: any };
86
+ yAxis?: { [key: string]: any };
87
+ legend?: { [key: string]: any };
88
+ barMaxWidth?: number;
89
+ label?: { [key: string]: any };
90
+ }
91
+
92
+ export interface ComponentProps {
93
+ style?: ComponentStyle;
94
+ base: { width: number, height: number },
95
+ data?: DataConfigProps;
96
+ isDesignMode?: boolean; // 是否编辑模式
97
+ }
98
+
99
+ export interface ComponentRef {
100
+ updateConfig: (newConfig: ComponentProps) => void;
101
+ destroy: () => void;
102
+ }
103
+
104
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
105
+ const { style, data: propsData, isDesignMode } = props;
106
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
107
+ const [size, setSize] = useState<{ width: number, height: number }>();
108
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
109
+ const [data, setData] = useState<{ name: string, data: any }[]>([]);
110
+ const chartRef = useRef<HTMLDivElement>(null);
111
+ const chart = useRef<any>(null);
112
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
113
+
114
+ const handleDestroy = () => {
115
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
116
+ window.removeEventListener('resize', handleResize);
117
+ chart.current.dispose();
118
+ };
119
+
120
+ useImperativeHandle(ref, () => ({
121
+ updateConfig: (newConfig) => {
122
+ const { base, style: newStyle, data: newDataConfig } = newConfig;
123
+ setConfig({ ...(newStyle || {}) });
124
+ setSize({ width: base.width, height: base.height });
125
+ setDataConfig(newDataConfig);
126
+ },
127
+ destroy: handleDestroy,
128
+ }));
129
+
130
+ // 窗口大小变化时重新调整图表大小
131
+ const handleResize = () => {
132
+ chart.current.resize({ animation: { duration: 500 } });
133
+ };
134
+
135
+ useEffect(() => {
136
+ chart.current = echarts.init(chartRef.current);
137
+ window.addEventListener('resize', handleResize);
138
+ return () => {
139
+ handleDestroy();
140
+ }
141
+ }, []);
142
+
143
+
144
+ // 请求数据
145
+ const getData = async () => {
146
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
147
+ const temData = handleData(value);
148
+ setData(temData);
149
+ return config;
150
+ };
151
+
152
+ // 初始化请求数据
153
+ const getInitData = async () => {
154
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
155
+ const config = await getData();
156
+ if (config?.requestType === "polling") {
157
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
158
+ }
159
+ };
160
+
161
+ // 静态数据处理
162
+ useEffect(() => {
163
+ if (dataConfig?.sourceType === 'staticData') {
164
+ setData(handleData(dataConfig.staticData));
165
+ }
166
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
167
+
168
+ /**
169
+ * 数据源数据请求
170
+ * 1、编辑态不请求数据
171
+ */
172
+ useEffect(() => {
173
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
174
+ getInitData();
175
+ } else if (dataConfig?.sourceType === 'sourceId') {
176
+ setData([]);
177
+ }
178
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
179
+
180
+ const renderChart = () => {
181
+ const { grid, barMaxWidth, legend, tooltip, color, xAxis, yAxis, label } = config
182
+ const option = _.cloneDeep(defOption);
183
+ // 编辑态无数据显示默认数据
184
+ const temData = isDesignMode && !data?.length ? option.series : data;
185
+ option.barMaxWidth = barMaxWidth;
186
+ option.grid = grid;
187
+ option.legend = { ...legend, ...legends[legend?.position] };
188
+ option.tooltip = { trigger: "axis", ...tooltip };
189
+ option.xAxis = { ...option.xAxis, ...xAxis, axisTick: { show: xAxis?.axisLine?.show } };
190
+ option.yAxis = { ...option.yAxis, ...yAxis, axisTick: { show: yAxis?.axisLine?.show } };
191
+ option.title.show = !temData?.length;
192
+ option.series = temData.map((r) => ({
193
+ type: "bar",
194
+ ...defSeriesConfig,
195
+ ...r,
196
+ label: label,
197
+ itemStyle: {
198
+ borderRadius: 20, color: (params) => color[params.dataIndex] || "#63b2ee"
199
+ },
200
+ }));
201
+ chart.current.setOption(option, true);
202
+ }
203
+ useEffect(() => {
204
+ if (config) {
205
+ renderChart();
206
+ }
207
+ }, [config, data]);
208
+
209
+ useEffect(() => {
210
+ if (size) {
211
+ handleResize();
212
+ }
213
+ }, [size]);
214
+
215
+ return <div ref={chartRef} style={{ width: '100%', height: '100%' }} />;
216
+ });
217
+
218
+ export default Index;
219
+
@@ -0,0 +1,201 @@
1
+ import * as echarts from 'echarts';
2
+ import React, { useEffect, useRef, useState, ForwardedRef, forwardRef, useImperativeHandle } from 'react';
3
+ import _ from 'lodash';
4
+ import HydrocarbonService from "../../tmpl/hcservice-v3";
5
+ import { DataConfigProps } from "../data";
6
+
7
+ const defOption = {
8
+ title: {
9
+ show: true,
10
+ text: "30 %",
11
+ x: 'center',
12
+ y: 'center',
13
+ textStyle: {
14
+ color: '#ffffff',
15
+ fontSize: 24,
16
+ },
17
+ },
18
+ angleAxis: {
19
+ axisLine: {
20
+ show: false,
21
+ },
22
+ axisLabel: {
23
+ show: false,
24
+ },
25
+ splitLine: {
26
+ show: false,
27
+ },
28
+ axisTick: {
29
+ show: false,
30
+ },
31
+ min: 0,
32
+ max: 100,
33
+ startAngle: 90,
34
+ },
35
+ radiusAxis: {
36
+ type: 'category',
37
+ axisLine: {
38
+ show: false,
39
+ },
40
+ axisTick: {
41
+ show: false,
42
+ },
43
+ axisLabel: {
44
+ show: true,
45
+ },
46
+ data: [],
47
+ },
48
+ polar: {
49
+ radius: '150%',
50
+ center: ['50%', '50%'],
51
+ },
52
+ series: [
53
+ // 极坐标系下柱状图
54
+ { // 实际值
55
+ type: 'bar',
56
+ data: [30],
57
+ z: 1,
58
+ coordinateSystem: 'polar',
59
+ barWidth: 24,
60
+ roundCap: 1,
61
+ color: "#446bf5"
62
+ },
63
+ { // 背景图形
64
+ type: 'bar',
65
+ data: [100],
66
+ z: 0,
67
+ silent: true,
68
+ coordinateSystem: 'polar',
69
+ barWidth: 24,
70
+ roundCap: true,
71
+ color: '#E8EDF3',
72
+ barGap: '-100%',
73
+ },
74
+ ],
75
+ };
76
+
77
+ export interface ComponentStyle {
78
+ title?: { [key: string]: any };
79
+ barWidth?: number;
80
+ color?: string;
81
+ backgroundColor?: string;
82
+ }
83
+
84
+ export interface ComponentProps {
85
+ style?: ComponentStyle;
86
+ base: { width: number, height: number },
87
+ data?: DataConfigProps;
88
+ isDesignMode?: boolean; // 是否编辑模式
89
+ }
90
+
91
+ export interface ComponentRef {
92
+ updateConfig: (newConfig: ComponentProps) => void;
93
+ destroy: () => void;
94
+ }
95
+
96
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
97
+ const { style, data: propsData, isDesignMode } = props;
98
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
99
+ const [size, setSize] = useState<{ width: number, height: number }>();
100
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
101
+ const [data, setData] = useState<number>(0);
102
+ const chartRef = useRef<HTMLDivElement>(null);
103
+ const chart = useRef<any>(null);
104
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
105
+
106
+ const handleDestroy = () => {
107
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
108
+ window.removeEventListener('resize', handleResize);
109
+ chart.current.dispose();
110
+ };
111
+
112
+ useImperativeHandle(ref, () => ({
113
+ updateConfig: (newConfig) => {
114
+ const { base, style: newStyle, data: newDataConfig } = newConfig;
115
+ setConfig({ ...(newStyle || {}) });
116
+ setSize({ width: base.width, height: base.height });
117
+ setDataConfig(newDataConfig);
118
+ },
119
+ destroy: handleDestroy,
120
+ }));
121
+
122
+ // 窗口大小变化时重新调整图表大小
123
+ const handleResize = () => {
124
+ chart.current.resize({ animation: { duration: 500 } });
125
+ };
126
+
127
+ useEffect(() => {
128
+ chart.current = echarts.init(chartRef.current);
129
+ window.addEventListener('resize', handleResize);
130
+ return () => {
131
+ handleDestroy();
132
+ }
133
+ }, []);
134
+
135
+ // 请求数据
136
+ const getData = async () => {
137
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
138
+ const temData = value?.[0]?.value?.[0]?.v1 || 0;
139
+ setData(temData * 100);
140
+ return config;
141
+ };
142
+
143
+ // 初始化请求数据
144
+ const getInitData = async () => {
145
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
146
+ const config = await getData();
147
+ if (config?.requestType === "polling") {
148
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
149
+ }
150
+ };
151
+
152
+ // 静态数据处理
153
+ useEffect(() => {
154
+ if (dataConfig?.sourceType === 'staticData') {
155
+ const { value } = dataConfig.staticData || {};
156
+ setData((value || 0) * 100);
157
+ }
158
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
159
+
160
+ /**
161
+ * 数据源数据请求
162
+ * 1、编辑态不请求数据
163
+ */
164
+ useEffect(() => {
165
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
166
+ getInitData();
167
+ } else if (dataConfig?.sourceType === 'sourceId') {
168
+ setData(0);
169
+ }
170
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
171
+
172
+ const renderChart = () => {
173
+ const { title, color, backgroundColor, barWidth } = config;
174
+ const option = _.cloneDeep(defOption);
175
+ // 编辑态数据源类型显示默认数据30
176
+ const temData = isDesignMode && dataConfig?.sourceType === 'sourceId' ? 30 : (data || 0);
177
+ option.title = { ...option.title, ...title, text: `${temData || "-"}%` };
178
+ option.series = option.series.map((item: any, index) => {
179
+ index === 0 && (item.data = [temData]);
180
+ item.color = index === 0 ? color : backgroundColor;
181
+ item.barWidth = barWidth;
182
+ return item;
183
+ });
184
+ chart.current.setOption(option, true);
185
+ }
186
+ useEffect(() => {
187
+ if (config) {
188
+ renderChart();
189
+ }
190
+ }, [config, data]);
191
+
192
+ useEffect(() => {
193
+ if (size) {
194
+ handleResize();
195
+ }
196
+ }, [size]);
197
+
198
+ return <div ref={chartRef} style={{ width: '100%', height: '100%' }} />;
199
+ });
200
+
201
+ export default Index;