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