aldehyde 0.2.284 → 0.2.286

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 (115) 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/upload/index.js +1 -1
  8. package/lib/controls/upload/index.js.map +1 -1
  9. package/lib/controls/upload/mult-file-upload.js +1 -1
  10. package/lib/controls/upload/mult-file-upload.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/lowcode-components/bar-chart/index.d.ts +10 -6
  18. package/lib/lowcode-components/bar-chart/index.d.ts.map +1 -1
  19. package/lib/lowcode-components/bar-chart/index.js +91 -11
  20. package/lib/lowcode-components/bar-chart/index.js.map +1 -1
  21. package/lib/lowcode-components/base-map/index.d.ts +10 -6
  22. package/lib/lowcode-components/base-map/index.d.ts.map +1 -1
  23. package/lib/lowcode-components/base-map/index.js +86 -7
  24. package/lib/lowcode-components/base-map/index.js.map +1 -1
  25. package/lib/lowcode-components/base-table/index.d.ts +53 -0
  26. package/lib/lowcode-components/base-table/index.d.ts.map +1 -0
  27. package/lib/lowcode-components/base-table/index.js +158 -0
  28. package/lib/lowcode-components/base-table/index.js.map +1 -0
  29. package/lib/lowcode-components/base-table/index.less +59 -0
  30. package/lib/lowcode-components/capsule-bar-chart/index.d.ts +43 -0
  31. package/lib/lowcode-components/capsule-bar-chart/index.d.ts.map +1 -0
  32. package/lib/lowcode-components/capsule-bar-chart/index.js +179 -0
  33. package/lib/lowcode-components/capsule-bar-chart/index.js.map +1 -0
  34. package/lib/lowcode-components/circular-progress-chart/index.d.ts +26 -0
  35. package/lib/lowcode-components/circular-progress-chart/index.d.ts.map +1 -0
  36. package/lib/lowcode-components/circular-progress-chart/index.js +179 -0
  37. package/lib/lowcode-components/circular-progress-chart/index.js.map +1 -0
  38. package/lib/lowcode-components/column-chart/index.d.ts +11 -6
  39. package/lib/lowcode-components/column-chart/index.d.ts.map +1 -1
  40. package/lib/lowcode-components/column-chart/index.js +115 -16
  41. package/lib/lowcode-components/column-chart/index.js.map +1 -1
  42. package/lib/lowcode-components/data-number/index.d.ts +10 -0
  43. package/lib/lowcode-components/data-number/index.d.ts.map +1 -1
  44. package/lib/lowcode-components/data-number/index.js +80 -6
  45. package/lib/lowcode-components/data-number/index.js.map +1 -1
  46. package/lib/lowcode-components/effectScatter-map/index.d.ts +10 -6
  47. package/lib/lowcode-components/effectScatter-map/index.d.ts.map +1 -1
  48. package/lib/lowcode-components/effectScatter-map/index.js +87 -9
  49. package/lib/lowcode-components/effectScatter-map/index.js.map +1 -1
  50. package/lib/lowcode-components/gauge-chart/index.d.ts +10 -6
  51. package/lib/lowcode-components/gauge-chart/index.d.ts.map +1 -1
  52. package/lib/lowcode-components/gauge-chart/index.js +65 -8
  53. package/lib/lowcode-components/gauge-chart/index.js.map +1 -1
  54. package/lib/lowcode-components/index.d.ts +8 -0
  55. package/lib/lowcode-components/index.d.ts.map +1 -1
  56. package/lib/lowcode-components/index.js +6 -1
  57. package/lib/lowcode-components/index.js.map +1 -1
  58. package/lib/lowcode-components/line-chart/index.d.ts +10 -6
  59. package/lib/lowcode-components/line-chart/index.d.ts.map +1 -1
  60. package/lib/lowcode-components/line-chart/index.js +91 -11
  61. package/lib/lowcode-components/line-chart/index.js.map +1 -1
  62. package/lib/lowcode-components/liquid-chart/index.d.ts +10 -6
  63. package/lib/lowcode-components/liquid-chart/index.d.ts.map +1 -1
  64. package/lib/lowcode-components/liquid-chart/index.js +64 -7
  65. package/lib/lowcode-components/liquid-chart/index.js.map +1 -1
  66. package/lib/lowcode-components/lowcode-view/component/assets.d.ts.map +1 -1
  67. package/lib/lowcode-components/lowcode-view/component/assets.js +46 -0
  68. package/lib/lowcode-components/lowcode-view/component/assets.js.map +1 -1
  69. package/lib/lowcode-components/lowcode-view/component/component-container.d.ts.map +1 -1
  70. package/lib/lowcode-components/lowcode-view/component/component-container.js +30 -29
  71. package/lib/lowcode-components/lowcode-view/component/component-container.js.map +1 -1
  72. package/lib/lowcode-components/pie-chart/index.d.ts +11 -6
  73. package/lib/lowcode-components/pie-chart/index.d.ts.map +1 -1
  74. package/lib/lowcode-components/pie-chart/index.js +102 -15
  75. package/lib/lowcode-components/pie-chart/index.js.map +1 -1
  76. package/lib/lowcode-components/text-scroller/index.d.ts +23 -0
  77. package/lib/lowcode-components/text-scroller/index.d.ts.map +1 -0
  78. package/lib/lowcode-components/text-scroller/index.js +96 -0
  79. package/lib/lowcode-components/text-scroller/index.js.map +1 -0
  80. package/lib/lowcode-components/text-scroller/index.less +29 -0
  81. package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
  82. package/lib/tmpl/control-type-supportor.js +1 -0
  83. package/lib/tmpl/control-type-supportor.js.map +1 -1
  84. package/lib/tmpl/superagent.d.ts +1 -1
  85. package/lib/tmpl/superagent.d.ts.map +1 -1
  86. package/lib/tmpl/superagent.js +15 -7
  87. package/lib/tmpl/superagent.js.map +1 -1
  88. package/package.json +1 -1
  89. package/src/aldehyde/controls/entry-control.tsx +12 -0
  90. package/src/aldehyde/controls/select/index.tsx +1 -0
  91. package/src/aldehyde/controls/upload/index.tsx +1 -1
  92. package/src/aldehyde/controls/upload/mult-file-upload.tsx +1 -1
  93. package/src/aldehyde/controls/view-control.tsx +1 -0
  94. package/src/aldehyde/detail/view/act-dtmpl-view.tsx +22 -23
  95. package/src/aldehyde/lowcode-components/bar-chart/index.tsx +100 -19
  96. package/src/aldehyde/lowcode-components/base-map/index.tsx +94 -15
  97. package/src/aldehyde/lowcode-components/base-table/index.less +59 -0
  98. package/src/aldehyde/lowcode-components/base-table/index.tsx +233 -0
  99. package/src/aldehyde/lowcode-components/capsule-bar-chart/index.tsx +219 -0
  100. package/src/aldehyde/lowcode-components/circular-progress-chart/index.tsx +201 -0
  101. package/src/aldehyde/lowcode-components/column-chart/index.tsx +128 -24
  102. package/src/aldehyde/lowcode-components/data-number/index.tsx +89 -7
  103. package/src/aldehyde/lowcode-components/data.d.ts +6 -0
  104. package/src/aldehyde/lowcode-components/effectScatter-map/index.tsx +93 -19
  105. package/src/aldehyde/lowcode-components/gauge-chart/index.tsx +73 -16
  106. package/src/aldehyde/lowcode-components/index.ts +10 -1
  107. package/src/aldehyde/lowcode-components/line-chart/index.tsx +105 -22
  108. package/src/aldehyde/lowcode-components/liquid-chart/index.tsx +70 -15
  109. package/src/aldehyde/lowcode-components/lowcode-view/component/assets.ts +46 -0
  110. package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +29 -28
  111. package/src/aldehyde/lowcode-components/pie-chart/index.tsx +111 -25
  112. package/src/aldehyde/lowcode-components/text-scroller/index.less +29 -0
  113. package/src/aldehyde/lowcode-components/text-scroller/index.tsx +122 -0
  114. package/src/aldehyde/tmpl/control-type-supportor.tsx +1 -0
  115. package/src/aldehyde/tmpl/superagent.js +125 -118
@@ -22,6 +22,7 @@ import TreeEntitySelect from "./tree-select/tree-entity-select";
22
22
  import FileView from "./file-view";
23
23
  import MultiFileUpload from "./upload/mult-file-upload";
24
24
  import NavigationTree from "./tree-select/navigation-tree";
25
+ import EllipsisText from "./text/ellipsis-text";
25
26
 
26
27
  // const CheckboxGroup = Checkbox.Group;
27
28
  const RadioGroup = Radio.Group;
@@ -372,6 +373,17 @@ function renderControl(
372
373
  case "field-history": //
373
374
  entryControl = <FieldHistory {...controlProps} ></FieldHistory>;
374
375
  break;
376
+ case "text-view":
377
+ entryControl = (
378
+ <EllipsisText
379
+ isHtml={false}
380
+ value={fieldValue}
381
+ showMax={
382
+ fieldConfig.ellipsisLength ? fieldConfig.ellipsisLength : 28
383
+ }
384
+ ></EllipsisText>
385
+ );
386
+ break;
375
387
  default:
376
388
  entryControl = unSupportControl;
377
389
  break;
@@ -180,6 +180,7 @@ export default class Select extends React.PureComponent<
180
180
  );
181
181
  break;
182
182
  case "radio":
183
+ debugger
183
184
  entryControl = (
184
185
  <RadioGroup
185
186
  {...antdControlProps}
@@ -105,7 +105,7 @@ export default class Upload extends React.PureComponent<
105
105
  fileList={fileList.length == 0 ? undefined : fileList}
106
106
  disabled={disabled}
107
107
  name={"file"}
108
- headers={Super.getHeaderObj()}
108
+ headers={Super.getHeaderObj(serverKey)}
109
109
  action={(file) => HcserviceV3.postFileAction(serverKey, file)}
110
110
  beforeUpload={this.beforeUpload}
111
111
  onChange={this.handleChange}
@@ -217,7 +217,7 @@ export default class MultiFileUpload extends React.PureComponent<
217
217
  disabled={disabled}
218
218
  name={"file"}
219
219
  multiple={true}
220
- headers={Super.getHeaderObj()}
220
+ headers={Super.getHeaderObj(serverKey)}
221
221
  action={(file) => HcserviceV3.postFileAction(serverKey, file)}
222
222
  beforeUpload={this.beforeUpload}
223
223
  onChange={this.handleChange}
@@ -143,6 +143,7 @@ function renderControl(
143
143
  break;
144
144
  case "text":
145
145
  case "textarea":
146
+ case "text-view":
146
147
  case "preselect":
147
148
  if (holderType == "table") {
148
149
  viewControl = (
@@ -1,11 +1,7 @@
1
1
  import React from "react";
2
2
  import {Button, Card, Form as AntdForm, FormInstance, message, Tooltip} from "antd";
3
- import {DtmplBaseProps, DtmplConfig, DtmplData, FieldConfig} from "../../tmpl/interface";
4
- import {
5
- ReloadOutlined,
6
- ScheduleOutlined,
7
- EditOutlined,
8
- } from "@ant-design/icons";
3
+ import {DtmplBaseProps, DtmplConfig, DtmplData} from "../../tmpl/interface";
4
+ import {EditOutlined, ReloadOutlined, ScheduleOutlined,} from "@ant-design/icons";
9
5
  import HCDataSource from "../../tmpl/hc-data-source";
10
6
  import "../dtmpl.css";
11
7
  import SnapshotTimeline from "./snapshot-timeline";
@@ -30,7 +26,7 @@ export interface ActDtmplViewStat {
30
26
  snapshotOpen?: boolean;
31
27
  layout?: object;
32
28
  refreshCode?: string;
33
- actionDtmplData?:DtmplData;
29
+ actionDtmplData?: DtmplData;
34
30
  }
35
31
 
36
32
  class ActDtmplView extends React.PureComponent<
@@ -56,11 +52,11 @@ class ActDtmplView extends React.PureComponent<
56
52
  wrapperCol: {span: 16},
57
53
  },
58
54
  refreshCode: undefined,
59
- actionDtmplData:undefined,
55
+ actionDtmplData: undefined,
60
56
  };
61
57
 
62
58
  async componentDidMount() {
63
- const {sourceId,code, serverKey} = this.props;
59
+ const {sourceId, code, serverKey} = this.props;
64
60
  let dtmplConfig = await HCDataSource.requestViewDtmplConfig(
65
61
  serverKey,
66
62
  sourceId
@@ -73,14 +69,14 @@ class ActDtmplView extends React.PureComponent<
73
69
  });
74
70
  }
75
71
 
76
- loadActionDtmplData = async (dtmplConfig:DtmplConfig) => {
77
- let actionDtmplData=undefined;
78
- const {sourceId,code, serverKey} = this.props;
79
- if(dtmplConfig?.viewActions && dtmplConfig?.viewActions.length>0){
72
+ loadActionDtmplData = async (dtmplConfig: DtmplConfig) => {
73
+ let actionDtmplData = undefined;
74
+ const {sourceId, code, serverKey} = this.props;
75
+ if (dtmplConfig?.viewActions && dtmplConfig?.viewActions.length > 0) {
80
76
  actionDtmplData = await HcserviceV3.requestViewDtmplData(
81
77
  serverKey,
82
78
  sourceId,
83
- code,null
79
+ code, null
84
80
  );
85
81
  }
86
82
  this.setState({
@@ -120,7 +116,7 @@ class ActDtmplView extends React.PureComponent<
120
116
  this.setState({
121
117
  loading: true,
122
118
  });
123
- const { sourceId, code, serverKey } = this.props;
119
+ const {sourceId, code, serverKey} = this.props;
124
120
  if (code) {
125
121
  //有code是修改,没有是新增实体模板
126
122
  values["唯一编码"] = code;
@@ -135,22 +131,22 @@ class ActDtmplView extends React.PureComponent<
135
131
  loading: false,
136
132
  });
137
133
  if (res.status === "success") {
138
- if(this.props.goBackToLtmpl){
134
+ if (this.props.goBackToLtmpl) {
139
135
  this.props.goBackToLtmpl();
140
- }else{
136
+ } else {
141
137
  this.doRefresh();
142
138
  }
143
139
  }
144
140
  };
145
141
 
146
142
  doSubmit = (actionId?: number, codes?: string[], params?: object) => {
147
- const { mainCode } = this.props;
143
+ const {mainCode} = this.props;
148
144
 
149
145
  //if (actionId) {
150
- this.formRef.current.setFieldsValue({ actionId: actionId });
146
+ this.formRef.current.setFieldsValue({actionId: actionId});
151
147
  // }
152
148
  if (mainCode) {
153
- this.formRef.current.setFieldsValue({ mainCode: mainCode });
149
+ this.formRef.current.setFieldsValue({mainCode: mainCode});
154
150
  }
155
151
  if (params) {
156
152
  this.formRef.current.setFieldsValue(params);
@@ -176,12 +172,15 @@ class ActDtmplView extends React.PureComponent<
176
172
  loading,
177
173
  layout,
178
174
  snapshotOpen,
179
- refreshCode,actionDtmplData,
175
+ refreshCode, actionDtmplData,
180
176
  } = this.state;
181
177
  const {translate} = this.context;
182
178
 
183
179
  const buttons = dtmplConfig ? dtmplConfig.buttons : undefined;
184
180
  const premises = dtmplConfig ? dtmplConfig.premises : undefined;
181
+
182
+ const detailTitle = title ? title : dtmplConfig && dtmplConfig.title ? dtmplConfig.title : "详情";
183
+
185
184
  let showRightNav_ = showRightNav;
186
185
  if (dtmplConfig && dtmplConfig.groups.length < 4) {
187
186
  showRightNav_ = false;
@@ -195,12 +194,12 @@ class ActDtmplView extends React.PureComponent<
195
194
  {showHeader ? (
196
195
  <Card
197
196
  variant={"borderless"}
198
- size={"small"}
197
+ size={"small"}
199
198
  key={"detailTitle"}
200
199
  className="hoverable pageHeader"
201
200
  >
202
201
  <h3>
203
- {translate("${" + (title ? title : "详情") + "}")}
202
+ {translate("${" + detailTitle + "}")}
204
203
  {dtmplConfig ? <ToolTipBar content={dtmplConfig.tip}/> : null}
205
204
  <div className="fr">
206
205
  {buttons &&
@@ -1,14 +1,21 @@
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";
4
6
 
5
7
  const defOption = {
8
+ title: {
9
+ text: '暂无数据',
10
+ left: 'center',
11
+ top: 'middle',
12
+ show: false, // 无数据时显示
13
+ },
6
14
  tooltip: { trigger: "axis" },
7
15
  grid: { top: 30, let: 30, right: 20, bottom: 30 },
8
16
  yAxis: {
9
17
  type: 'category',
10
18
  boundaryGap: true,
11
- data: ['1990', '1991', '1992', '1993', '1994', '1995', '1996'],
12
19
  },
13
20
  xAxis: {
14
21
  type: 'value',
@@ -18,7 +25,7 @@ const defOption = {
18
25
  barMaxWidth: 30,
19
26
  series: [
20
27
  {
21
- data: [525, 459, 357, 414, 234, 250, 156],
28
+ data: [[525, "1990"], [459, "1991"], [357, "1992"], [414, "1993"], [234, "1994"], [250, "1995"], [156, "1996"]],
22
29
  type: 'bar',
23
30
  }
24
31
  ]
@@ -35,7 +42,26 @@ const legends = {
35
42
  rightBottom: { right: 5, bottom: 0 },
36
43
  };
37
44
 
38
- export interface ChartComponentStyle {
45
+ // 处理数据格式
46
+ const handleData = (data: { config: { [key: string]: string }, value: { [key: string]: any }[] }[]) => {
47
+ if (!data?.length) {
48
+ return [];
49
+ }
50
+ const temData = data.map((r) => {
51
+ const { config, value } = r;
52
+ const vNames = Object.keys(config).filter((r) => r.startsWith("v")).sort((a, b) => parseInt(a.substring(1)) - parseInt(b.substring(1)));
53
+ return {
54
+ name: config.d1,
55
+ data: vNames.map((r) => ({
56
+ name: config[r],
57
+ data: value.map((v) => [v[r], v["d1"]]),
58
+ }))
59
+ };
60
+ });
61
+ return temData[0]?.data || [];
62
+ };
63
+
64
+ export interface ComponentStyle {
39
65
  tooltip?: { show: boolean };
40
66
  color?: string[];
41
67
  grid?: { top: number, let: number, right: number, bottom: number };
@@ -45,27 +71,42 @@ export interface ChartComponentStyle {
45
71
  barMaxWidth?: number;
46
72
  }
47
73
 
48
- export interface ChartComponentProps {
49
- style?: ChartComponentStyle;
50
- base: { width: number, height: number }
74
+ export interface ComponentProps {
75
+ style?: ComponentStyle;
76
+ base: { width: number, height: number },
77
+ data?: DataConfigProps;
78
+ isDesignMode?: boolean; // 是否编辑模式
51
79
  }
52
80
 
53
- export interface BaseTextComponentRef {
54
- updateConfig: (newConfig: ChartComponentProps) => void;
81
+ export interface ComponentRef {
82
+ updateConfig: (newConfig: ComponentProps) => void;
83
+ destroy: () => void;
55
84
  }
56
85
 
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 }>()
86
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
87
+ const { style, data: propsData, isDesignMode } = props;
88
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
89
+ const [size, setSize] = useState<{ width: number, height: number }>();
90
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
91
+ const [data, setData] = useState<{ name: string, data: any }[]>([]);
60
92
  const chartRef = useRef<HTMLDivElement>(null);
61
93
  const chart = useRef<any>(null);
94
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
95
+
96
+ const handleDestroy = () => {
97
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
98
+ window.removeEventListener('resize', handleResize);
99
+ chart.current.dispose();
100
+ };
62
101
 
63
102
  useImperativeHandle(ref, () => ({
64
103
  updateConfig: (newConfig) => {
65
- const { base, style } = newConfig;
66
- setConfig({ ...(style || {}) });
104
+ const { base, style: newStyle, data: newDataConfig } = newConfig;
105
+ setConfig({ ...(newStyle || {}) });
67
106
  setSize({ width: base.width, height: base.height });
107
+ setDataConfig(newDataConfig);
68
108
  },
109
+ destroy: handleDestroy,
69
110
  }));
70
111
 
71
112
  // 窗口大小变化时重新调整图表大小
@@ -77,21 +118,61 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
77
118
  chart.current = echarts.init(chartRef.current);
78
119
  window.addEventListener('resize', handleResize);
79
120
  return () => {
80
- window.removeEventListener('resize', handleResize);
81
- chart.current.dispose();
121
+ handleDestroy();
82
122
  }
83
123
  }, []);
84
124
 
125
+
126
+ // 请求数据
127
+ const getData = async () => {
128
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
129
+ const temData = handleData(value);
130
+ setData(temData);
131
+ return config;
132
+ };
133
+
134
+ // 初始化请求数据
135
+ const getInitData = async () => {
136
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
137
+ const config = await getData();
138
+ if (config?.requestType === "polling") {
139
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
140
+ }
141
+ };
142
+
143
+ // 静态数据处理
144
+ useEffect(() => {
145
+ if (dataConfig?.sourceType === 'staticData') {
146
+ setData(handleData(dataConfig.staticData));
147
+ }
148
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
149
+
150
+ /**
151
+ * 数据源数据请求
152
+ * 1、编辑态不请求数据
153
+ */
154
+ useEffect(() => {
155
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
156
+ getInitData();
157
+ } else if (dataConfig?.sourceType === 'sourceId') {
158
+ setData([]);
159
+ }
160
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
161
+
85
162
  const renderChart = () => {
86
163
  const { grid, barMaxWidth, legend, tooltip, color, xAxis, yAxis, } = config
87
- const option = lodash.cloneDeep(defOption);
164
+ const option = _.cloneDeep(defOption);
165
+ // 编辑态无数据显示默认数据
166
+ const temData = isDesignMode && !data?.length ? option.series : data;
88
167
  option.barMaxWidth = barMaxWidth;
89
168
  option.grid = grid;
90
169
  option.legend = { ...legend, ...legends[legend?.position] };
91
170
  option.tooltip = { trigger: "axis", ...tooltip };
92
171
  option.xAxis = { ...option.xAxis, ...xAxis, axisTick: { show: xAxis?.axisLine?.show } };
93
172
  option.yAxis = { ...option.yAxis, ...yAxis };
94
- option.series = option.series.map((r, index) => ({
173
+ option.title.show = !temData?.length;
174
+ option.series = temData.map((r, index) => ({
175
+ type: "bar",
95
176
  ...r,
96
177
  itemStyle: { color: color[index] },
97
178
  }));
@@ -101,7 +182,7 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
101
182
  if (config) {
102
183
  renderChart();
103
184
  }
104
- }, [config]);
185
+ }, [config, data]);
105
186
 
106
187
  useEffect(() => {
107
188
  if (size) {
@@ -2,10 +2,13 @@ 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";
5
7
 
6
8
  const defOption = {
7
9
  tooltip: {
8
10
  trigger: 'item',
11
+ formatter: (val) => val.data
9
12
  },
10
13
  geo: {
11
14
  show: true,
@@ -39,33 +42,67 @@ const defOption = {
39
42
  ]
40
43
  };
41
44
 
45
+ // 处理数据格式
46
+ const handleData = (data: { config: { [key: string]: string }, value: { [key: string]: any }[] }[]) => {
47
+ if (!data?.length) {
48
+ return [];
49
+ }
50
+ const temData = data.map((r) => {
51
+ const { config, value } = r;
52
+ const vNames = Object.keys(config).filter((r) => r.startsWith("v")).sort((a, b) => parseInt(a.substring(1)) - parseInt(b.substring(1)));
53
+ return {
54
+ name: config.d1,
55
+ data: vNames.map((r) => ({
56
+ name: config[r],
57
+ value: value[0]?.[r],
58
+ }))
59
+ };
60
+ });
61
+ return temData[0]?.data || [];
62
+ };
63
+
42
64
 
43
- export interface ChartComponentStyle {
65
+ export interface ComponentStyle {
44
66
  tooltip?: { show: boolean };
45
67
  geo?: { [key: string]: any };
46
68
  }
47
69
 
48
- export interface ChartComponentProps {
49
- style?: ChartComponentStyle;
50
- base: { width: number, height: number }
70
+ export interface ComponentProps {
71
+ style?: ComponentStyle;
72
+ base: { width: number, height: number },
73
+ data?: DataConfigProps;
74
+ isDesignMode?: boolean; // 是否编辑模式
51
75
  }
52
76
 
53
- export interface BaseTextComponentRef {
54
- updateConfig: (newConfig: ChartComponentProps) => void;
77
+ export interface ComponentRef {
78
+ updateConfig: (newConfig: ComponentProps) => void;
79
+ destroy: () => void;
55
80
  }
56
81
 
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 }>()
82
+ const Index = forwardRef((props: ComponentProps, ref: ForwardedRef<ComponentRef>) => {
83
+ const { style, data: propsData, isDesignMode } = props;
84
+ const [config, setConfig] = useState<ComponentStyle>(style || {});
85
+ const [size, setSize] = useState<{ width: number, height: number }>();
86
+ const [dataConfig, setDataConfig] = useState<DataConfigProps>({ ...propsData }); // 数据源配置
87
+ const [data, setData] = useState<{ name: string, value: number[] }[]>([]);
60
88
  const chartRef = useRef<HTMLDivElement>(null);
61
89
  const chart = useRef<any>(null);
90
+ const pollingIntervalRef = useRef<number | NodeJS.Timeout>(null);
91
+
92
+ const handleDestroy = () => {
93
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
94
+ window.removeEventListener('resize', handleResize);
95
+ chart.current.dispose();
96
+ };
62
97
 
63
98
  useImperativeHandle(ref, () => ({
64
99
  updateConfig: (newConfig) => {
65
- const { base, style } = newConfig;
66
- setConfig({ ...(style || {}) });
100
+ const { base, style: newStyle, data: newDataConfig } = newConfig;
101
+ setConfig({ ...(newStyle || {}) });
67
102
  setSize({ width: base.width, height: base.height });
103
+ setDataConfig(newDataConfig);
68
104
  },
105
+ destroy: handleDestroy,
69
106
  }));
70
107
 
71
108
  // 窗口大小变化时重新调整图表大小
@@ -78,23 +115,65 @@ const Index = forwardRef((props: ChartComponentProps, ref: ForwardedRef<BaseText
78
115
  chart.current = echarts.init(chartRef.current, null, { renderer: 'svg' });
79
116
  window.addEventListener('resize', handleResize);
80
117
  return () => {
81
- window.removeEventListener('resize', handleResize);
82
- chart.current.dispose();
118
+ handleDestroy();
83
119
  }
84
120
  }, []);
85
121
 
122
+ // 请求数据
123
+ const getData = async () => {
124
+ const { entities: { config, value } } = await HydrocarbonService.requestMstrucLtmplQueryTop(null, dataConfig?.sourceId, null) || {};
125
+ setData(handleData(value));
126
+ return config;
127
+ };
128
+
129
+ // 初始化请求数据
130
+ const getInitData = async () => {
131
+ pollingIntervalRef.current && clearInterval(pollingIntervalRef.current);
132
+ const config = await getData();
133
+ if (config?.requestType === "polling") {
134
+ pollingIntervalRef.current = setInterval(() => { getData() }, config?.pollingInterval || 60000);
135
+ }
136
+ };
137
+
138
+ // 静态数据处理
139
+ useEffect(() => {
140
+ if (dataConfig?.sourceType === 'staticData') {
141
+ setData(dataConfig.staticData || []);
142
+ }
143
+ }, [dataConfig?.sourceType, dataConfig?.staticData]);
144
+
145
+ /**
146
+ * 数据源数据请求
147
+ * 1、编辑态不请求数据
148
+ */
149
+ useEffect(() => {
150
+ if (!isDesignMode && dataConfig?.sourceType === 'sourceId' && dataConfig?.sourceId) {
151
+ getInitData();
152
+ } else if (dataConfig?.sourceType === 'sourceId') {
153
+ setData([]);
154
+ }
155
+ }, [dataConfig?.sourceType, dataConfig?.sourceId]);
156
+
86
157
  const renderChart = () => {
87
158
  const { tooltip, geo } = config
88
159
  const option = _.cloneDeep(defOption);
89
- option.tooltip = { trigger: "item", ...tooltip };
160
+ option.tooltip = {
161
+ trigger: "item",
162
+ formatter: (val) => {
163
+ const { data: { name, value } } = val || {};
164
+ return `${name}:${value || value == 0 ? value : "-"}`;
165
+ },
166
+ ...tooltip
167
+ };
90
168
  option.geo = { ...option.geo, ...geo, ...geo.normal };
169
+ option.series = option.series.map((item) => ({ ...item, data: data || [] }));
91
170
  chart.current.setOption(option, true);
92
171
  }
93
172
  useEffect(() => {
94
173
  if (config) {
95
174
  renderChart();
96
175
  }
97
- }, [config]);
176
+ }, [config, data]);
98
177
 
99
178
  useEffect(() => {
100
179
  if (size) {
@@ -0,0 +1,59 @@
1
+ .base-table {
2
+ width: 100%;
3
+ height: 100%;
4
+ overflow: hidden;
5
+
6
+ .base-table-empty {
7
+ width: 100%;
8
+ height: 100%;
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ }
13
+
14
+ table {
15
+ width: 100%;
16
+ text-align: center;
17
+ table-layout: fixed;
18
+
19
+ thead {
20
+ position: relative;
21
+ z-index: 1;
22
+
23
+ th {
24
+ padding: 0 4px;
25
+ }
26
+ }
27
+
28
+
29
+ .scroll-body {
30
+ overflow: hidden;
31
+ animation: scroll 10s linear infinite;
32
+
33
+ td {
34
+ padding: 0 4px;
35
+ overflow: hidden;
36
+ white-space: nowrap;
37
+ text-overflow: ellipsis;
38
+ }
39
+ }
40
+ }
41
+
42
+ table:hover {
43
+ .scroll-body {
44
+ animation-play-state: paused !important;
45
+ }
46
+ }
47
+
48
+ }
49
+
50
+
51
+ @keyframes scroll {
52
+ 0% {
53
+ transform: translateY(0);
54
+ }
55
+
56
+ 100% {
57
+ transform: translateY(-100%);
58
+ }
59
+ }