@cloudbase/weda-ui 0.2.16 → 1.0.24

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 (194) hide show
  1. package/README.md +41 -169
  2. package/package.json +23 -11
  3. package/src/configs/components/calendar.json +4 -1
  4. package/src/configs/components/chart/bar.json +724 -0
  5. package/src/configs/components/chart/line.json +679 -0
  6. package/src/configs/components/chart/pie.json +497 -0
  7. package/src/configs/components/chart/statisticsCard.json +61 -13
  8. package/src/configs/components/container.json +7 -2
  9. package/src/configs/components/dataView.json +21 -6
  10. package/src/configs/components/form/checkbox.json +97 -5
  11. package/src/configs/components/form/radio.json +96 -4
  12. package/src/configs/components/form/select.json +245 -11
  13. package/src/configs/components/graphicCard.json +84 -73
  14. package/src/configs/components/image.json +7 -2
  15. package/src/configs/components/link.json +19 -3
  16. package/src/configs/components/listView.json +65 -18
  17. package/src/configs/components/lottery.json +151 -0
  18. package/src/configs/components/modal.json +37 -5
  19. package/src/configs/components/navLayout.json +87 -75
  20. package/src/configs/components/navigationBar.json +59 -0
  21. package/src/configs/components/richtextview.json +4 -1
  22. package/src/configs/components/scrollVeiw.json +74 -22
  23. package/src/configs/components/swiper.json +4 -1
  24. package/src/configs/components/tabs.json +51 -8
  25. package/src/configs/components/text.json +33 -25
  26. package/src/configs/components/wxOpenApi/phone.json +141 -0
  27. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  28. package/src/configs/components/wxOpenApi/share.json +167 -0
  29. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  30. package/src/configs/index.js +20 -0
  31. package/src/index.js +2 -0
  32. package/src/mp/components/button/index.wxml +1 -2
  33. package/src/mp/components/chart/bar/index.js +258 -0
  34. package/src/mp/components/chart/bar/index.json +6 -0
  35. package/src/mp/components/chart/bar/index.wxml +3 -0
  36. package/src/mp/components/chart/bar/index.wxss +9 -0
  37. package/src/mp/components/chart/common/config/bar.js +50 -0
  38. package/src/mp/components/chart/common/config/global.js +16 -0
  39. package/src/mp/components/chart/common/config/line.js +48 -0
  40. package/src/mp/components/chart/common/config/pie.js +36 -0
  41. package/src/mp/components/chart/common/core/eChartBar.js +263 -0
  42. package/src/mp/components/chart/common/core/eChartBase.js +375 -0
  43. package/src/mp/components/chart/common/core/eChartLine.js +229 -0
  44. package/src/mp/components/chart/common/core/eChartPie.js +166 -0
  45. package/src/mp/components/chart/common/lib/echarts.min.js +18 -0
  46. package/src/mp/components/chart/ec-canvas/ec-canvas.js +277 -0
  47. package/src/mp/components/chart/ec-canvas/ec-canvas.json +4 -0
  48. package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +4 -0
  49. package/src/mp/components/chart/ec-canvas/ec-canvas.wxss +4 -0
  50. package/src/mp/components/chart/ec-canvas/wx-canvas.js +107 -0
  51. package/src/mp/components/chart/line/index.js +247 -0
  52. package/src/mp/components/chart/line/index.json +6 -0
  53. package/src/mp/components/chart/line/index.wxml +3 -0
  54. package/src/mp/components/chart/line/index.wxss +9 -0
  55. package/src/mp/components/chart/pie/index.js +182 -0
  56. package/src/mp/components/chart/pie/index.json +6 -0
  57. package/src/mp/components/chart/pie/index.wxml +4 -0
  58. package/src/mp/components/chart/pie/index.wxss +9 -0
  59. package/src/mp/components/chart/statisticsCard/index.js +33 -6
  60. package/src/mp/components/form/checkbox/index.js +41 -2
  61. package/src/mp/components/form/checkbox/index.wxml +1 -1
  62. package/src/mp/components/form/form/index.wxml +1 -2
  63. package/src/mp/components/form/input/index.js +1 -1
  64. package/src/mp/components/form/location/index.js +43 -2
  65. package/src/mp/components/form/radio/index.js +38 -0
  66. package/src/mp/components/form/select/index.js +348 -40
  67. package/src/mp/components/form/select/index.wxml +21 -6
  68. package/src/mp/components/form/select/region/index.js +101 -0
  69. package/src/mp/components/form/textarea/index.wxml +6 -5
  70. package/src/mp/components/form/uploader/index.js +76 -44
  71. package/src/mp/components/form/uploader/index.wxml +15 -3
  72. package/src/mp/components/form/uploaderFile/index.js +61 -29
  73. package/src/mp/components/graphicCard/index.js +26 -28
  74. package/src/mp/components/listView/index.js +52 -64
  75. package/src/mp/components/listView/index.wxml +2 -2
  76. package/src/mp/components/listView/index.wxss +5 -0
  77. package/src/mp/components/lottery/index.js +270 -0
  78. package/src/mp/components/lottery/index.json +4 -0
  79. package/src/mp/components/lottery/index.wxml +43 -0
  80. package/src/mp/components/lottery/index.wxss +317 -0
  81. package/src/mp/components/navLayout/index.js +3 -3
  82. package/src/mp/components/navigationBar/index.js +193 -0
  83. package/src/mp/components/navigationBar/index.json +6 -0
  84. package/src/mp/components/navigationBar/index.wxml +88 -0
  85. package/src/mp/components/navigationBar/index.wxss +1257 -0
  86. package/src/mp/components/tabs/index.js +7 -2
  87. package/src/mp/components/tabs/index.wxml +2 -1
  88. package/src/mp/components/text/index.js +0 -25
  89. package/src/mp/components/text/index.wxml +3 -3
  90. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  91. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  92. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  93. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  94. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  95. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  96. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  97. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  98. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  99. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  100. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  101. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  102. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  103. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  104. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  105. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  106. package/src/mp/index.json +10 -1
  107. package/src/mp/style/weda-ui.wxss +2 -0
  108. package/src/mp/utils/constant.js +15 -0
  109. package/src/mp/utils/destr.js +48 -0
  110. package/src/mp/utils/lodash.js +2 -0
  111. package/src/mp/utils/platform.js +25 -0
  112. package/src/mp/utils/tcb.js +44 -0
  113. package/src/setupTests.js +2 -1
  114. package/src/web/components/button/index.css +8 -1
  115. package/src/web/components/button/index.tsx +3 -2
  116. package/src/web/components/chart/bar/index.tsx +140 -0
  117. package/src/web/components/chart/common/config/bar.js +49 -0
  118. package/src/web/components/chart/common/config/global.js +16 -0
  119. package/src/web/components/chart/common/config/line.js +50 -0
  120. package/src/web/components/chart/common/config/pie.js +37 -0
  121. package/src/web/components/chart/common/core/eChartBar.js +265 -0
  122. package/src/web/components/chart/common/core/eChartBase.ts +383 -0
  123. package/src/web/components/chart/common/core/eChartLine.js +231 -0
  124. package/src/web/components/chart/common/core/eChartPie.js +170 -0
  125. package/src/web/components/chart/common/core/type.ts +34 -0
  126. package/src/web/components/chart/common/echart.css +106 -0
  127. package/src/web/components/chart/common/echarts.ts +33 -0
  128. package/src/web/components/chart/common/useChart.tsx +69 -0
  129. package/src/web/components/chart/line/index.tsx +136 -0
  130. package/src/web/components/chart/pie/index.tsx +99 -0
  131. package/src/web/components/chart/statisticsCard/index.tsx +29 -8
  132. package/src/web/components/form/checkbox/index.tsx +61 -23
  133. package/src/web/components/form/formcell/index.tsx +10 -5
  134. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +3 -3
  135. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +2 -2
  136. package/src/web/components/form/radio/index.tsx +90 -53
  137. package/src/web/components/form/select/h5.tsx +371 -72
  138. package/src/web/components/form/select/index.css +10 -0
  139. package/src/web/components/form/select/index.tsx +392 -145
  140. package/src/web/components/form/select/region/index.ts +122 -31
  141. package/src/web/components/form/select/time.jsx +90 -0
  142. package/src/web/components/form/select/year.tsx +170 -0
  143. package/src/web/components/form/tips/index.css +4 -0
  144. package/src/web/components/form/tips/index.tsx +4 -3
  145. package/src/web/components/form/uploader/uploader.h5.tsx +28 -19
  146. package/src/web/components/form/uploader/uploader.pc.tsx +17 -20
  147. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +48 -44
  148. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +28 -26
  149. package/src/web/components/graphicCard/index.css +1 -5
  150. package/src/web/components/graphicCard/index.tsx +4 -3
  151. package/src/web/components/image/image.tsx +1 -1
  152. package/src/web/components/image/index.tsx +1 -1
  153. package/src/web/components/index.js +13 -2
  154. package/src/web/components/link/index.tsx +6 -3
  155. package/src/web/components/listView/index.css +4 -0
  156. package/src/web/components/listView/index.tsx +10 -18
  157. package/src/web/components/lottery/index.css +327 -0
  158. package/src/web/components/lottery/index.tsx +567 -0
  159. package/src/web/components/lottery/lotteryUtil.ts +130 -0
  160. package/src/web/components/modal/index.tsx +3 -1
  161. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  162. package/src/web/components/navigationBar/common.tsx +198 -0
  163. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  164. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  165. package/src/web/components/navigationBar/index.css +762 -0
  166. package/src/web/components/navigationBar/index.tsx +231 -0
  167. package/src/web/components/navigationBar/type.d.ts +111 -0
  168. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  169. package/src/web/components/phone/index.css +0 -0
  170. package/src/web/components/phone/index.tsx +22 -0
  171. package/src/web/components/phoneCode/index.css +0 -0
  172. package/src/web/components/phoneCode/index.tsx +22 -0
  173. package/src/web/components/richTextView/index.tsx +3 -5
  174. package/src/web/components/share/index.css +0 -0
  175. package/src/web/components/share/index.tsx +38 -0
  176. package/src/web/components/tabs/index.tsx +2 -0
  177. package/src/web/components/tabs/tabs.h5.tsx +43 -33
  178. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  179. package/src/web/components/text/index.tsx +6 -14
  180. package/src/web/components/userInfo/index.css +0 -0
  181. package/src/web/components/userInfo/index.tsx +30 -0
  182. package/src/web/utils/{constant.js → constant.ts} +17 -2
  183. package/src/web/utils/lodash.ts +2 -0
  184. package/src/web/utils/platform.js +10 -1
  185. package/src/web/utils/tcb.js +20 -6
  186. package/src/web/weda-ui.css +2 -0
  187. package/CHANGELOG.md +0 -240
  188. package/src/.DS_Store +0 -0
  189. package/src/configs/.DS_Store +0 -0
  190. package/src/mp/.gitignore +0 -10
  191. package/src/web/.DS_Store +0 -0
  192. package/src/web/components/form/select/region/cities.ts +0 -2410
  193. package/src/web/components/form/select/region/provinces.ts +0 -240
  194. package/src/web/components/form/select/region/regions.ts +0 -20645
@@ -0,0 +1,265 @@
1
+ import EchartBase from './eChartBase';
2
+ import getConfig from '../config/bar';
3
+ /**
4
+ * 柱状图表
5
+ * @author loonglong
6
+ **/
7
+ class EchartBar extends EchartBase {
8
+ constructor() {
9
+ super();
10
+ const config = getConfig();
11
+ this.config = { ...this.config, ...config };
12
+ }
13
+ async setSourceData({
14
+ dataSource,
15
+ filterData,
16
+ xField,
17
+ xStatistics,
18
+ xIsCountEmpty,
19
+ groupKey,
20
+ groupKeyTimeSpan,
21
+ yField,
22
+ isPile
23
+ }) {
24
+ const { name = '', type = '', methodName = '' } = dataSource;
25
+ if (name !== '') {
26
+ const params = this.createWhere({
27
+ filterData,
28
+ xField,
29
+ xStatistics,
30
+ xIsCountEmpty,
31
+ groupKey,
32
+ groupKeyTimeSpan,
33
+ yField,
34
+ });
35
+ const arrSourData = await this.getSourceData(
36
+ name,
37
+ methodName,
38
+ type,
39
+ params,
40
+ );
41
+ // 获取 x 轴数据
42
+ const sortedXAxisData = this.sortXAxisData(arrSourData, xField.format);
43
+ const arrXaxisData = this.setXaxis(sortedXAxisData, xField.format);
44
+ const arrXisCountEmptyIndex = []; // 记录空值的key
45
+ if (Object.keys(groupKey ?? {}).length === 0) {
46
+ const numLine = sortedXAxisData[0].YLabels.length;
47
+ if (numLine > 0) {
48
+ for (let j = 0; j < numLine; j++) {
49
+ this.config.series[j] = {
50
+ type: 'bar',
51
+ name: '',
52
+ stack: isPile ? 'pile' : null,
53
+ itemStyle: { color: null },
54
+ showSymbol: true,
55
+ label: {
56
+ show: true,
57
+ },
58
+ data: [],
59
+ };
60
+ sortedXAxisData.forEach((itemSource,index) => {
61
+ this.config.series[j].name = itemSource.YLabels[j].Cn_Name;
62
+ if ((itemSource.YLabels[j].Value === undefined || itemSource.YLabels[j].Value === null) && !xIsCountEmpty) {
63
+ arrXisCountEmptyIndex.push(index);
64
+ } else {
65
+ const value = itemSource.YLabels[j].Value ? itemSource.YLabels[j].Value : 0;
66
+ this.config.series[j].data.push(value);
67
+ }
68
+ });
69
+ }
70
+ }
71
+ // 处理显示空值问题
72
+ this.setEmptyValue(xIsCountEmpty);
73
+ } else if (groupKey) {
74
+ // 如果是分组,则这里需要特殊处理
75
+ // 按groupKey分组存放数据值
76
+ const objGroupKey = {}; // {'分组字段':[{value:'统计的值', dimensionality:'维度名', name:'统计的数值字段名'}]}
77
+ sortedXAxisData.forEach((itemSourData) => {
78
+ itemSourData.YLabels.forEach((yLabel) => {
79
+ if (!objGroupKey[yLabel.Group_Name]) {
80
+ objGroupKey[yLabel.Group_Name] = [];
81
+ }
82
+ objGroupKey[yLabel.Group_Name].push({
83
+ value: yLabel.Value,
84
+ dimensionality: itemSourData.XLabel.Value,
85
+ name: yLabel.Cn_Name,
86
+ });
87
+ });
88
+ });
89
+
90
+
91
+ // 组装图表需要的数据
92
+ const arrGroupKey = Object.keys(objGroupKey);
93
+ this.config.series = arrGroupKey.map((groupKey) => {
94
+ // groupKey分组字段中文名
95
+ const serie = {
96
+ name: groupKey,
97
+ type: 'bar',
98
+ itemStyle: {
99
+ color: null,
100
+ },
101
+ showSymbol: true,
102
+ label: {
103
+ show: true,
104
+ },
105
+ data: this.getSeriesDataGroup(
106
+ arrXaxisData,
107
+ objGroupKey[groupKey],
108
+ ),
109
+ stack: isPile ? 'pile' : null,
110
+ };
111
+ return serie;
112
+ });
113
+ this.config.tooltip.formatter = params => (
114
+ `${params.data.dimensionality
115
+ }\r\n${
116
+ params.data.name
117
+ }\r\n${
118
+ params.seriesName
119
+ }:${
120
+ params.value}`
121
+ );
122
+ }
123
+ }
124
+ }
125
+ setColor({ setColor }) {
126
+ if (this.config.series.length > 0 && setColor && setColor.length > 0) {
127
+ let i = 0;
128
+ this.config.series.forEach((itemSeries) => {
129
+ itemSeries.itemStyle.color = setColor[i % 6];
130
+ i = i + 1;
131
+ });
132
+ }
133
+ }
134
+
135
+ // 显示图表上的数据标签 单位,标签,小数位数,后缀
136
+ setIsSeriesShowSymbol({
137
+ isSeriesShowSymbol,
138
+ isUnit,
139
+ unit,
140
+ decimalDigits,
141
+ suffix
142
+ }) {
143
+ decimalDigits = Math.max(0, decimalDigits);
144
+ this.config.series.length > 0
145
+ && this.config.series.forEach((itemSeries) => {
146
+ itemSeries.showSymbol = isSeriesShowSymbol;
147
+ itemSeries.label.show = isSeriesShowSymbol;
148
+ if (isUnit) {
149
+ itemSeries.label.formatter = (params) => {
150
+ const objNewValue = this.getValueByUnit(params.value, unit);
151
+ return (
152
+ `${objNewValue.toFixed(decimalDigits)}${suffix}`
153
+ );
154
+ };
155
+ }
156
+ });
157
+ if (isUnit) {
158
+ this.config.yAxis.axisLabel.formatter = (value) => {
159
+ const objNewValue = this.getValueByUnit(value, unit);
160
+ return `${objNewValue.toFixed(decimalDigits)}${suffix}`;
161
+ };
162
+ } else {
163
+ this.config.yAxis.axisLabel.formatter = null;
164
+ }
165
+ }
166
+
167
+ // 设置柱状图X,Y倒转
168
+ setDirectionType({directionType}) {
169
+ let temAxis = {};
170
+ if (directionType === 'crosswise') { // 横向
171
+ temAxis = this.config.xAxis;
172
+ // @ts-ignore
173
+ this.config.xAxis = this.config.yAxis;
174
+ // @ts-ignore
175
+ this.config.yAxis = temAxis;
176
+ this.config.yAxis.inverse = true;
177
+
178
+ } else { // 纵向
179
+ if (this.config.yAxis.inverse) {
180
+ temAxis = this.config.yAxis;
181
+ // @ts-ignore
182
+ this.config.yAxis = this.config.xAxis;
183
+ // @ts-ignore
184
+ this.config.xAxis = temAxis;
185
+ this.config.xAxis.inverse = false;
186
+ }
187
+ }
188
+ }
189
+ async setOptions({
190
+ directionType,
191
+ isPile,
192
+ setColor,
193
+ isTitle,
194
+ title,
195
+ titleLocation,
196
+ dataSource,
197
+ filterData,
198
+ xField,
199
+ xStatistics,
200
+ groupKey,
201
+ groupKeyTimeSpan,
202
+ xIsCountEmpty,
203
+ yField,
204
+ isLegend,
205
+ legend,
206
+ legend2,
207
+ isXaxisName,
208
+ xAxisName,
209
+ isXaxisAxisLabelShow,
210
+ isXaxisAxisTickShow,
211
+ isXaxisAxisLabelRotate,
212
+ isYAxisSplitlineLinestyleWidth,
213
+ yAxisSplitlineLinestyleType,
214
+ yAxisMax,
215
+ yAxisMin,
216
+ isYAxisName,
217
+ yAxisName,
218
+ isSeriesShowSymbol,
219
+ isYAxisShow,
220
+ isUnit,
221
+ unit,
222
+ decimalDigits,
223
+ suffix
224
+ }) {
225
+ legend = document.body.clientWidth < 1024 ? legend : legend2;
226
+ if (dataSource) {
227
+ await this.setSourceData({
228
+ dataSource,
229
+ filterData,
230
+ xField,
231
+ xStatistics,
232
+ xIsCountEmpty,
233
+ groupKey,
234
+ groupKeyTimeSpan,
235
+ yField,
236
+ isPile
237
+ });
238
+ }
239
+ this.setColor({ setColor });
240
+ this.setTitle({ isTitle, title, titleLocation });
241
+ this.setLegend({ isLegend, legend });
242
+ this.setIsXaxisAxisLabelShow({ isXaxisAxisLabelShow });
243
+ this.setIsXaxisName({ isXaxisName, xAxisName });
244
+ this.setIsXaxisAxisTickShow({ isXaxisAxisTickShow });
245
+ this.setIsXaxisAxisLabelRotate({ isXaxisAxisLabelRotate, xStatistics });
246
+ this.setIsYAxisSplitlineLinestyleWidth({
247
+ isYAxisSplitlineLinestyleWidth,
248
+ yAxisSplitlineLinestyleType,
249
+ });
250
+ this.setYAxisMaxMin({ yAxisMax, yAxisMin });
251
+ this.setIsYAxisName({ isYAxisName, yAxisName });
252
+ this.setIsYAxisShow({ isYAxisShow });
253
+ this.setIsSeriesShowSymbol({
254
+ isSeriesShowSymbol,
255
+ isUnit,
256
+ unit,
257
+ decimalDigits,
258
+ suffix
259
+ });
260
+ this.setDirectionType({directionType});
261
+ return this.config;
262
+ }
263
+ }
264
+
265
+ export default EchartBar;
@@ -0,0 +1,383 @@
1
+ import { callDataSource, callWedaApi } from '../../../../utils/tcb';
2
+ import getConfig from '../config/global';
3
+
4
+ export type IEchartModalBase = typeof EchartBase
5
+ export abstract class AbstractEchartBaseModal {
6
+ abstract setOptions(options: any): Promise<void>;
7
+ abstract getOptions(option: any): Promise<void>;
8
+ }
9
+
10
+ type IReturnData = {
11
+ value: {
12
+ Key: string;
13
+ OperationType: 'count' | 'sum' | 'avg' | 'max' | 'min';
14
+ }[],
15
+ where: [],
16
+ dimension: {
17
+ TimeSpan?: string;
18
+ Key?: string;
19
+ IsCountEmpty?: boolean;
20
+ },
21
+ group: {
22
+ TimeSpan?: string;
23
+ Key?: string;
24
+ },
25
+ }
26
+
27
+ /**
28
+ * 图表处理基类
29
+ * @author loonglong
30
+ **/
31
+ class EchartBase extends AbstractEchartBaseModal {
32
+ // config: ECOption;
33
+ // TODO: type
34
+ config: any;
35
+ constructor() {
36
+ super();
37
+ this.config = getConfig();
38
+ }
39
+
40
+ public async setOptions(options: any): Promise<void> {}
41
+
42
+
43
+ /** 获取所有配置好的图表数据 */
44
+ public getOptions() {
45
+ return this.config;
46
+ }
47
+
48
+ /** 生成后台查询条件 */
49
+ protected createWhere({
50
+ filterData,
51
+ xField,
52
+ xStatistics,
53
+ xIsCountEmpty,
54
+ yField,
55
+ groupKey=({} as Record<string, any>),
56
+ groupKeyTimeSpan='',
57
+ }) {
58
+ const objReturnData: IReturnData = {
59
+ value: [],
60
+ where: [],
61
+ dimension: {},
62
+ group: {},
63
+ };
64
+ if (filterData && filterData.length > 0) { // 协议转化,把首字母改成大写
65
+ objReturnData.where = filterData.map((val) => {
66
+ let arrLogicData = val.logicData;
67
+ if (val.logicData && val.logicData.length > 0) {
68
+ arrLogicData = val.logicData.map((mval)=>{
69
+ return {
70
+ Key: mval.key,
71
+ Rel: mval.rel,
72
+ Value: mval.value,
73
+ Logic: mval.logic,
74
+ Extra: {
75
+ Type:mval?.extra?.type,
76
+ Format:mval?.extra?.format,
77
+ IsExpression:mval?.extra?.isExpression,
78
+ },
79
+ ValueType:mval.valueType,
80
+ Expression:mval.expression
81
+ };
82
+ });
83
+ }
84
+ return {
85
+ GroupLogic:val.groupLogic,
86
+ LogicData: arrLogicData,
87
+ };
88
+ });
89
+ }
90
+ if (xField && xField.name) {
91
+ objReturnData.dimension = {
92
+ Key: xField.name,
93
+ };
94
+ if (xStatistics) {
95
+ objReturnData.dimension.TimeSpan = xStatistics;
96
+ } else {
97
+ objReturnData.dimension.IsCountEmpty = xIsCountEmpty;
98
+ }
99
+ }
100
+ if (yField && yField.numValue && yField.numValue.length > 0) {
101
+ yField.numValue.forEach((itemVal) => {
102
+ objReturnData.value.push({
103
+ Key: itemVal.key,
104
+ OperationType: itemVal.operationType,
105
+ });
106
+ });
107
+ }
108
+
109
+ if (yField && groupKey && groupKey.name) {
110
+ objReturnData.group.Key = groupKey.name;
111
+ objReturnData.group.TimeSpan = groupKeyTimeSpan;
112
+ }
113
+ return objReturnData;
114
+ }
115
+
116
+ /**
117
+ * 从后台获取统计数据
118
+ *
119
+ **/
120
+ protected async getSourceData(
121
+ sourceName = '',
122
+ methods = '',
123
+ dataSourceType = '',
124
+ params,
125
+ ) {
126
+ try {
127
+ if (dataSourceType === 'database') {
128
+ return await callWedaApi({
129
+ action: 'DescribeChartData',
130
+ data: {
131
+ DataSourceName: sourceName,
132
+ Value: params.value,
133
+ Where: params.where,
134
+ Dimension: params.dimension,
135
+ Group: params.group,
136
+ },
137
+ });
138
+ }
139
+ const res = await callDataSource({
140
+ dataSourceName: sourceName,
141
+ methodName: methods,
142
+ params,
143
+ });
144
+ return res.result ?? [];
145
+ } catch (err) {
146
+ return [];
147
+ }
148
+ }
149
+
150
+ protected setTitle({ isTitle, title, titleLocation = '' }) {
151
+ this.config.title;
152
+ this.config.title.show = isTitle;
153
+ this.config.title.text = title;
154
+
155
+ this.config.title.top = '-1%';
156
+ this.config.title.left = '35%';
157
+ this.config.title.right = null;
158
+ }
159
+
160
+ protected setLegend({ isLegend, legend= 'top'}) {
161
+ this.config.legend.show = isLegend;
162
+ switch (legend) {
163
+ case 'top' :
164
+ this.config.legend.orient = 'horizontal';
165
+ this.config.legend.x = 'center';
166
+ this.config.legend.top = '6%';
167
+ break;
168
+ case 'left' :
169
+ this.config.legend.orient = 'vertical';
170
+ this.config.legend.top = '30%';
171
+ this.config.legend.left = '1%';
172
+ break;
173
+ case 'right' :
174
+ this.config.legend.orient = 'vertical';
175
+ this.config.legend.top = '30%';
176
+ this.config.legend.right = '6%';
177
+ break;
178
+ default:
179
+ this.config.legend.top = '89%';
180
+ this.config.legend.orient = 'horizontal';
181
+ this.config.legend.x = 'center';
182
+ break;
183
+ }
184
+ }
185
+
186
+ /**
187
+ * 设置 X轴数据
188
+ * @param { Array<object> } arrData 后台返回的数据
189
+ * @param { string } formatType 类型 datetime:日期时间;date:日期,time:时间,其它
190
+ */
191
+ protected setXaxis(sortedXAxisData, formatType) {
192
+ const xAxisData = [];
193
+ if (sortedXAxisData.length > 0) {
194
+ sortedXAxisData.forEach((itemSource) => {
195
+ let value = itemSource.XLabel.Value;
196
+ if (formatType === 'datetime') {
197
+ value = this.formatTime(itemSource.XLabel.Value, 'dt');
198
+ } else if (formatType === 'date') {
199
+ value = this.formatTime(itemSource.XLabel.Value, 'd');
200
+ } else if (formatType === 'time') {
201
+ value = this.formatTime(itemSource.XLabel.Value, 't');
202
+ }
203
+ xAxisData.push(value);
204
+ });
205
+ this.config.xAxis.data = xAxisData;
206
+ }
207
+ return xAxisData;
208
+ }
209
+ protected sortXAxisData(arrData, formatType = ''): Array<any> {
210
+ let xFields = [...arrData];
211
+ if(['datetime', 'date', 'time'].includes(formatType)) {
212
+ xFields.sort((a, b) => {
213
+ if(a.XLabel.Value && b.XLabel.Value ) {
214
+ return new Date(a.XLabel.Value).getTime() - new Date(b.XLabel.Value).getTime();
215
+ }
216
+ // 产品需求空值放最后
217
+ if(!a.XLabel.Value) {
218
+ return 1;
219
+ }
220
+ if(!b.XLabel.Value) {
221
+ return -1;
222
+ }
223
+ });
224
+ }
225
+
226
+ return xFields;
227
+ }
228
+
229
+ /**
230
+ * 时间轴格式化为日期,时间,日期时间
231
+ * @param { number } time 时间戳
232
+ * @param { string } timeType 需要格式化的类型 dt:日期时间,d:日期,t:时间
233
+ * @returns { string } 格式化结果
234
+ */
235
+ private formatTime(time, timeType='dt') {
236
+ if(typeof time === 'undefined' || time === null) {
237
+ return '空';
238
+ }
239
+ if (typeof(time) === 'string') { // 如果是字符串,代表后台返回的就是格式化的时间格式,则这里不再做格式化处理
240
+ return time;
241
+ }
242
+ const date = new Date(time + 8 * 3600 * 1000);
243
+ let startNum = 0;
244
+ let endNum = 19;
245
+ if (timeType === 'd') {
246
+ startNum = 0;
247
+ endNum = 10;
248
+ } else if (timeType === 't') {
249
+ startNum = 11;
250
+ endNum = 5;
251
+ }
252
+ return date.toISOString().substr(startNum, endNum).replace('T', ' ');
253
+ }
254
+
255
+ /**
256
+ * 当有分组字段时,该方法用于获取图表 series 里的 data值,自动补全没有的数据
257
+ * @param { array } arrXaxisData - 维度名 eg:['张三','李四','王二']
258
+ * @param { array } arrGroupValue - 所属当前分组的数据 eg:[{value:'统计值',name:'统计名',dimensionality:'维度名'}]
259
+ * @returns 返回补全的数组
260
+ **/
261
+ protected getSeriesDataGroup(arrXaxisData, arrGroupValue) {
262
+ const xNums = arrXaxisData.length;
263
+ const arrRe = [];
264
+ for (let i = 0; i < xNums; i++) {
265
+ const objIsInArray = this.isInArray(arrXaxisData[i], arrGroupValue);
266
+ if (Object.keys(objIsInArray).length > 0) {
267
+ arrRe.push({
268
+ value: objIsInArray.value,
269
+ name: objIsInArray.name,
270
+ dimensionality: arrXaxisData[i],
271
+ });
272
+ } else {
273
+ arrRe.push({
274
+ value: null,
275
+ });
276
+ }
277
+ }
278
+ return arrRe;
279
+ }
280
+
281
+ // 判断当前的维度名是否在该数组里
282
+ // TODO: any
283
+ private isInArray(strDimensionality, arrGroupValue): any {
284
+ let mixStatus = {};
285
+ if (arrGroupValue.length > 0) {
286
+ arrGroupValue.forEach((itemGroupValue) => {
287
+ if (strDimensionality === itemGroupValue.dimensionality) {
288
+ mixStatus = itemGroupValue;
289
+ }
290
+ });
291
+ }
292
+ return mixStatus;
293
+ }
294
+
295
+ // 显示 X 轴标签名
296
+ protected setIsXaxisAxisLabelShow({ isXaxisAxisLabelShow }) {
297
+ this.config.xAxis.axisLabel.show = isXaxisAxisLabelShow;
298
+ }
299
+ // 显示 X 轴名
300
+ protected setIsXaxisName({ isXaxisName, xAxisName }) {
301
+ this.config.xAxis.name = isXaxisName ? xAxisName : '';
302
+ }
303
+ // 显示X轴刻度线
304
+ protected setIsXaxisAxisTickShow({ isXaxisAxisTickShow }) {
305
+ this.config.xAxis.axisTick = {show:isXaxisAxisTickShow};
306
+ }
307
+ // X 轴文字倾斜
308
+ protected setIsXaxisAxisLabelRotate({ isXaxisAxisLabelRotate, xStatistics, angle = 30}) {
309
+ this.config.xAxis.axisLabel.rotate = isXaxisAxisLabelRotate ? angle : 0;
310
+ if (isXaxisAxisLabelRotate || xStatistics) { // 如果X轴是时间类型,自动斜30度展示
311
+ this.config.xAxis.axisLabel.rotate = angle;
312
+ } else {
313
+ this.config.xAxis.axisLabel.rotate = 0;
314
+ }
315
+ }
316
+
317
+ // 显示网格线 及 线条类型
318
+ protected setIsYAxisSplitlineLinestyleWidth({
319
+ isYAxisSplitlineLinestyleWidth,
320
+ yAxisSplitlineLinestyleType,
321
+ }) {
322
+ this.config.yAxis.splitLine = {lineStyle:{}};
323
+ this.config.yAxis.splitLine.lineStyle.width = isYAxisSplitlineLinestyleWidth ? 1 : 0;
324
+ this.config.yAxis.splitLine.lineStyle.type = yAxisSplitlineLinestyleType;
325
+ }
326
+ // 显示 Y 轴刻度 最大值,最小值
327
+ protected setYAxisMaxMin({ yAxisMax, yAxisMin }) {
328
+ this.config.yAxis.min = yAxisMin ? yAxisMin : null;
329
+ this.config.yAxis.max = yAxisMax ? yAxisMax : null;
330
+ }
331
+ // 显示 Y 轴名称
332
+ protected setIsYAxisName({ isYAxisName, yAxisName }) {
333
+ this.config.yAxis.name = isYAxisName ? yAxisName : '';
334
+ }
335
+ // 显示 Y 轴刻度线
336
+ protected setIsYAxisShow({ isYAxisShow }) {
337
+ this.config.yAxis.show = isYAxisShow;
338
+ }
339
+
340
+ /**
341
+ * 当为空值时,重写xAxis, 只处理单Y轴情况
342
+ * @param { array } arrXisCountEmptyIndex Y轴空值key记录
343
+ * @param { boolean } xIsCountEmpty 是否统计空值
344
+ */
345
+ protected setEmptyValue(xIsCountEmpty) {
346
+ if (!xIsCountEmpty) {
347
+ const nonEmpty = this.config.xAxis.data.filter(item => item !== undefined && item !== null);
348
+ this.config.xAxis.data = nonEmpty;
349
+ }
350
+ }
351
+
352
+ /**
353
+ * 删除数组里面不存在的键值
354
+ * @param { array } arrXAxis 需要处理的数组
355
+ * @returns { array } 返回处理后的数组
356
+ **/
357
+ private removeEmpty(arrXAxis) {
358
+ const arrNewxAxis = [];
359
+ if (arrXAxis.length > 0) {
360
+ for(let i = 0; i < arrXAxis.length; i++) {
361
+ if (arrXAxis[i]) {
362
+ arrNewxAxis.push(arrXAxis[i]);
363
+ }
364
+ }
365
+ return arrNewxAxis;
366
+ } else {
367
+ return arrXAxis;
368
+ }
369
+ }
370
+
371
+ /**
372
+ * 根据值 value,返回指定单位的数
373
+ * @param {number} value 原始值
374
+ * @param {string} unit 单位,'%'百分比,'‰'千分比, K千,W万,BW 百万,Y 亿,B 十亿
375
+ * @returns {object} 返回对象 {value:新值,postfix:'单位'}
376
+ **/
377
+ protected getValueByUnit(value, unit) {
378
+ value = Number(value);
379
+ return value / unit;
380
+ }
381
+ }
382
+
383
+ export default EchartBase;