@cloudbase/weda-ui 0.2.15 → 1.0.21

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 (250) hide show
  1. package/README.md +41 -169
  2. package/package.json +28 -15
  3. package/src/configs/components/calendar.json +78 -0
  4. package/src/configs/components/carousel.json +273 -0
  5. package/src/configs/components/chart/bar.json +724 -0
  6. package/src/configs/components/chart/line.json +679 -0
  7. package/src/configs/components/chart/pie.json +497 -0
  8. package/src/configs/components/chart/statisticsCard.json +379 -0
  9. package/src/configs/components/container.json +7 -2
  10. package/src/configs/components/dataView.json +154 -0
  11. package/src/configs/components/form/checkbox.json +97 -5
  12. package/src/configs/components/form/location.json +152 -0
  13. package/src/configs/components/form/radio.json +96 -4
  14. package/src/configs/components/form/select.json +245 -11
  15. package/src/configs/components/form/uploaderFile.json +2 -1
  16. package/src/configs/components/graphicCard.json +410 -0
  17. package/src/configs/components/image.json +7 -2
  18. package/src/configs/components/link.json +20 -4
  19. package/src/configs/components/listView.json +277 -0
  20. package/src/configs/components/modal.json +37 -5
  21. package/src/configs/components/navLayout.json +362 -0
  22. package/src/configs/components/navigationBar.json +59 -0
  23. package/src/configs/components/richtextview.json +4 -1
  24. package/src/configs/components/scrollVeiw.json +74 -22
  25. package/src/configs/components/swiper.json +6 -3
  26. package/src/configs/components/tabs.json +51 -8
  27. package/src/configs/components/text.json +33 -25
  28. package/src/configs/components/wxOpenApi/phone.json +141 -0
  29. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  30. package/src/configs/components/wxOpenApi/share.json +167 -0
  31. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  32. package/src/configs/index.js +34 -0
  33. package/src/mp/components/button/index.js +12 -13
  34. package/src/mp/components/button/index.wxml +1 -1
  35. package/src/mp/components/calendar/arrowright--line.svg +11 -0
  36. package/src/mp/components/calendar/index.js +238 -0
  37. package/src/mp/components/calendar/index.json +4 -0
  38. package/src/mp/components/calendar/index.wxml +37 -0
  39. package/src/mp/components/calendar/index.wxss +178 -0
  40. package/src/mp/components/carousel/index.js +88 -0
  41. package/src/mp/components/carousel/index.json +7 -0
  42. package/src/mp/components/carousel/index.wxml +6 -0
  43. package/src/mp/components/chart/bar/index.js +258 -0
  44. package/src/mp/components/chart/bar/index.json +6 -0
  45. package/src/mp/components/chart/bar/index.wxml +3 -0
  46. package/src/mp/components/chart/bar/index.wxss +9 -0
  47. package/src/mp/components/chart/common/config/bar.js +50 -0
  48. package/src/mp/components/chart/common/config/global.js +16 -0
  49. package/src/mp/components/chart/common/config/line.js +48 -0
  50. package/src/mp/components/chart/common/config/pie.js +36 -0
  51. package/src/mp/components/chart/common/core/eChartBar.js +263 -0
  52. package/src/mp/components/chart/common/core/eChartBase.js +375 -0
  53. package/src/mp/components/chart/common/core/eChartLine.js +229 -0
  54. package/src/mp/components/chart/common/core/eChartPie.js +166 -0
  55. package/src/mp/components/chart/common/lib/echarts.min.js +18 -0
  56. package/src/mp/components/chart/ec-canvas/ec-canvas.js +277 -0
  57. package/src/mp/components/chart/ec-canvas/ec-canvas.json +4 -0
  58. package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +4 -0
  59. package/src/mp/components/chart/ec-canvas/ec-canvas.wxss +4 -0
  60. package/src/mp/components/chart/ec-canvas/wx-canvas.js +107 -0
  61. package/src/mp/components/chart/line/index.js +247 -0
  62. package/src/mp/components/chart/line/index.json +6 -0
  63. package/src/mp/components/chart/line/index.wxml +3 -0
  64. package/src/mp/components/chart/line/index.wxss +9 -0
  65. package/src/mp/components/chart/pie/index.js +182 -0
  66. package/src/mp/components/chart/pie/index.json +6 -0
  67. package/src/mp/components/chart/pie/index.wxml +4 -0
  68. package/src/mp/components/chart/pie/index.wxss +9 -0
  69. package/src/mp/components/chart/statisticsCard/index.js +253 -0
  70. package/src/mp/components/chart/statisticsCard/index.json +4 -0
  71. package/src/mp/components/chart/statisticsCard/index.wxml +9 -0
  72. package/src/mp/components/chart/statisticsCard/index.wxss +45 -0
  73. package/src/mp/components/dataView/index.js +34 -0
  74. package/src/mp/components/dataView/index.json +7 -0
  75. package/src/mp/components/dataView/index.wxml +15 -0
  76. package/src/mp/components/dataView/index.wxss +0 -0
  77. package/src/mp/components/form/checkbox/index.js +41 -2
  78. package/src/mp/components/form/checkbox/index.wxml +1 -1
  79. package/src/mp/components/form/input/index.js +1 -1
  80. package/src/mp/components/form/location/components/mapChoose/index.js +201 -0
  81. package/src/mp/components/form/location/components/mapChoose/index.json +4 -0
  82. package/src/mp/components/form/location/components/mapChoose/index.wxml +42 -0
  83. package/src/mp/components/form/location/components/mapChoose/index.wxss +188 -0
  84. package/src/mp/components/form/location/index.js +382 -0
  85. package/src/mp/components/form/location/index.json +6 -0
  86. package/src/mp/components/form/location/index.wxml +25 -0
  87. package/src/mp/components/form/location/index.wxss +91 -0
  88. package/src/mp/components/form/radio/index.js +38 -0
  89. package/src/mp/components/form/select/index.js +360 -40
  90. package/src/mp/components/form/select/index.wxml +21 -6
  91. package/src/mp/components/form/select/region/index.js +98 -0
  92. package/src/mp/components/form/textarea/index.wxml +6 -5
  93. package/src/mp/components/form/uploader/index.js +84 -48
  94. package/src/mp/components/form/uploader/index.wxml +15 -3
  95. package/src/mp/components/form/uploaderFile/index.js +106 -27
  96. package/src/mp/components/graphicCard/chevron-right.svg +3 -0
  97. package/src/mp/components/graphicCard/index.js +203 -0
  98. package/src/mp/components/graphicCard/index.json +4 -0
  99. package/src/mp/components/graphicCard/index.wxml +29 -0
  100. package/src/mp/components/graphicCard/index.wxss +157 -0
  101. package/src/mp/components/image/index.js +0 -1
  102. package/src/mp/components/listView/arrow-right-line.svg +3 -0
  103. package/src/mp/components/listView/index.js +285 -0
  104. package/src/mp/components/listView/index.json +4 -0
  105. package/src/mp/components/listView/index.wxml +40 -0
  106. package/src/mp/components/listView/index.wxss +155 -0
  107. package/src/mp/components/listView/more-line.svg +3 -0
  108. package/src/mp/components/navLayout/index.js +123 -0
  109. package/src/mp/components/navLayout/index.json +7 -0
  110. package/src/mp/components/navLayout/index.wxml +25 -0
  111. package/src/mp/components/navLayout/index.wxss +1193 -0
  112. package/src/mp/components/navigationBar/index.js +193 -0
  113. package/src/mp/components/navigationBar/index.json +6 -0
  114. package/src/mp/components/navigationBar/index.wxml +88 -0
  115. package/src/mp/components/navigationBar/index.wxss +1257 -0
  116. package/src/mp/components/swiper/index.wxml +2 -0
  117. package/src/mp/components/tabs/index.js +7 -2
  118. package/src/mp/components/tabs/index.wxml +2 -1
  119. package/src/mp/components/text/index.js +0 -25
  120. package/src/mp/components/text/index.wxml +3 -3
  121. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  122. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  123. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  124. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  125. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  126. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  127. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  128. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  129. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  130. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  131. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  132. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  133. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  134. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  135. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  136. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  137. package/src/mp/index.json +18 -2
  138. package/src/mp/style/weda-ui.wxss +2 -0
  139. package/src/mp/utils/debounce.js +133 -0
  140. package/src/mp/utils/destr.js +48 -0
  141. package/src/mp/utils/dr_square_point.js +25 -0
  142. package/src/mp/utils/platform.js +25 -0
  143. package/src/mp/utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js +1336 -0
  144. package/src/mp/utils/spark-md5.js +776 -0
  145. package/src/mp/utils/tcb.js +62 -0
  146. package/src/setupTests.js +2 -1
  147. package/src/web/components/button/index.css +8 -1
  148. package/src/web/components/button/index.tsx +3 -2
  149. package/src/web/components/calendar/index.css +382 -0
  150. package/src/web/components/calendar/index.jsx +312 -0
  151. package/src/web/components/calendar/util.js +90 -0
  152. package/src/web/components/carousel/index.css +119 -0
  153. package/src/web/components/carousel/index.tsx +417 -0
  154. package/src/web/components/chart/bar/index.tsx +140 -0
  155. package/src/web/components/chart/common/config/bar.js +49 -0
  156. package/src/web/components/chart/common/config/global.js +16 -0
  157. package/src/web/components/chart/common/config/line.js +50 -0
  158. package/src/web/components/chart/common/config/pie.js +37 -0
  159. package/src/web/components/chart/common/core/eChartBar.js +265 -0
  160. package/src/web/components/chart/common/core/eChartBase.ts +383 -0
  161. package/src/web/components/chart/common/core/eChartLine.js +231 -0
  162. package/src/web/components/chart/common/core/eChartPie.js +170 -0
  163. package/src/web/components/chart/common/core/type.ts +34 -0
  164. package/src/web/components/chart/common/echart.css +106 -0
  165. package/src/web/components/chart/common/echarts.ts +33 -0
  166. package/src/web/components/chart/common/useChart.tsx +69 -0
  167. package/src/web/components/chart/line/index.tsx +136 -0
  168. package/src/web/components/chart/pie/index.tsx +99 -0
  169. package/src/web/components/chart/statisticsCard/index.css +62 -0
  170. package/src/web/components/chart/statisticsCard/index.tsx +307 -0
  171. package/src/web/components/chart/statisticsCard/interface.ts +14 -0
  172. package/src/web/components/dataView/index.tsx +20 -0
  173. package/src/web/components/dataView/interface.ts +6 -0
  174. package/src/web/components/form/checkbox/index.tsx +55 -23
  175. package/src/web/components/form/location/common/mapChoose.css +178 -0
  176. package/src/web/components/form/location/common/mapChoose.jsx +343 -0
  177. package/src/web/components/form/location/common/mapView.jsx +190 -0
  178. package/src/web/components/form/location/common/propsConfig.js +54 -0
  179. package/src/web/components/form/location/common/selectModal.css +44 -0
  180. package/src/web/components/form/location/common/selectModal.jsx +82 -0
  181. package/src/web/components/form/location/common/useLocationInfo.js +100 -0
  182. package/src/web/components/form/location/components/LocationH5/index.css +243 -0
  183. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +403 -0
  184. package/src/web/components/form/location/components/LocationPC/Header.jsx +109 -0
  185. package/src/web/components/form/location/components/LocationPC/index.css +44 -0
  186. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +323 -0
  187. package/src/web/components/form/location/constants.js +4 -0
  188. package/src/web/components/form/location/index.css +0 -0
  189. package/src/web/components/form/location/index.jsx +25 -0
  190. package/src/web/components/form/radio/index.tsx +84 -53
  191. package/src/web/components/form/select/h5.tsx +389 -71
  192. package/src/web/components/form/select/index.css +10 -0
  193. package/src/web/components/form/select/index.tsx +404 -144
  194. package/src/web/components/form/select/region/index.ts +122 -31
  195. package/src/web/components/form/select/time.jsx +90 -0
  196. package/src/web/components/form/select/year.tsx +170 -0
  197. package/src/web/components/form/uploader/uploader.h5.tsx +19 -4
  198. package/src/web/components/form/uploader/uploader.pc.tsx +8 -7
  199. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +132 -113
  200. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +16 -11
  201. package/src/web/components/graphicCard/index.css +159 -0
  202. package/src/web/components/graphicCard/index.tsx +310 -0
  203. package/src/web/components/image/image.tsx +1 -2
  204. package/src/web/components/image/index.tsx +1 -1
  205. package/src/web/components/index.js +24 -2
  206. package/src/web/components/link/index.tsx +6 -3
  207. package/src/web/components/listView/arrow-right-line.svg +3 -0
  208. package/src/web/components/listView/index.css +143 -0
  209. package/src/web/components/listView/index.tsx +359 -0
  210. package/src/web/components/listView/interface.ts +98 -0
  211. package/src/web/components/modal/index.tsx +3 -1
  212. package/src/web/components/navLayout/index.css +332 -0
  213. package/src/web/components/navLayout/index.tsx +247 -0
  214. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  215. package/src/web/components/navigationBar/common.tsx +198 -0
  216. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  217. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  218. package/src/web/components/navigationBar/index.css +762 -0
  219. package/src/web/components/navigationBar/index.tsx +231 -0
  220. package/src/web/components/navigationBar/type.d.ts +111 -0
  221. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  222. package/src/web/components/phone/index.css +0 -0
  223. package/src/web/components/phone/index.tsx +22 -0
  224. package/src/web/components/phoneCode/index.css +0 -0
  225. package/src/web/components/phoneCode/index.tsx +22 -0
  226. package/src/web/components/richTextView/index.tsx +3 -5
  227. package/src/web/components/share/index.css +0 -0
  228. package/src/web/components/share/index.tsx +38 -0
  229. package/src/web/components/tabs/index.tsx +4 -2
  230. package/src/web/components/tabs/tabs.h5.tsx +50 -37
  231. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  232. package/src/web/components/text/index.tsx +6 -14
  233. package/src/web/components/uploaderFileView/index.css +9 -9
  234. package/src/web/components/uploaderFileView/index.jsx +32 -23
  235. package/src/web/components/userInfo/index.css +0 -0
  236. package/src/web/components/userInfo/index.tsx +30 -0
  237. package/src/web/types.d.ts +15 -14
  238. package/src/web/utils/debounce.js +98 -0
  239. package/src/web/utils/platform.js +40 -0
  240. package/src/web/utils/tcb.js +49 -0
  241. package/src/web/utils/tmap.js +4 -0
  242. package/src/web/weda-ui.css +2 -0
  243. package/CHANGELOG.md +0 -240
  244. package/src/.DS_Store +0 -0
  245. package/src/configs/.DS_Store +0 -0
  246. package/src/mp/.gitignore +0 -10
  247. package/src/web/.DS_Store +0 -0
  248. package/src/web/components/form/select/region/cities.ts +0 -2410
  249. package/src/web/components/form/select/region/provinces.ts +0 -240
  250. 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;