@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,277 @@
1
+ import WxCanvas from './wx-canvas';
2
+ import * as echarts from '../common/lib/echarts.min';
3
+
4
+ let ctx;
5
+
6
+ function compareVersion(v1, v2) {
7
+ v1 = v1.split('.');
8
+ v2 = v2.split('.');
9
+ const len = Math.max(v1.length, v2.length);
10
+
11
+ while (v1.length < len) {
12
+ v1.push('0');
13
+ }
14
+ while (v2.length < len) {
15
+ v2.push('0');
16
+ }
17
+
18
+ for (let i = 0; i < len; i++) {
19
+ const num1 = parseInt(v1[i]);
20
+ const num2 = parseInt(v2[i]);
21
+
22
+ if (num1 > num2) {
23
+ return 1;
24
+ } else if (num1 < num2) {
25
+ return -1;
26
+ }
27
+ }
28
+ return 0;
29
+ }
30
+
31
+ Component({
32
+ properties: {
33
+ canvasId: {
34
+ type: String,
35
+ value: 'ec-canvas',
36
+ },
37
+
38
+ ec: {
39
+ type: Object,
40
+ },
41
+
42
+ forceUseOldCanvas: {
43
+ type: Boolean,
44
+ value: false,
45
+ },
46
+ },
47
+
48
+ data: {
49
+ isUseNewCanvas: false,
50
+ },
51
+
52
+ ready: function () {
53
+ // Disable prograssive because drawImage doesn't support DOM as parameter
54
+ // See https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
55
+ echarts.registerPreprocessor((option) => {
56
+ if (option && option.series) {
57
+ if (option.series.length > 0) {
58
+ option.series.forEach((series) => {
59
+ series.progressive = 0;
60
+ });
61
+ } else if (typeof option.series === 'object') {
62
+ option.series.progressive = 0;
63
+ }
64
+ }
65
+ });
66
+
67
+ if (!this.data.ec) {
68
+ console.warn(
69
+ '组件需绑定 ec 变量,例:<ec-canvas id="mychart-dom-bar" ' +
70
+ 'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>'
71
+ );
72
+ return;
73
+ }
74
+
75
+ if (!this.data.ec.lazyLoad) {
76
+ this.init();
77
+ }
78
+ },
79
+
80
+ methods: {
81
+ init: function (callback) {
82
+ const version = wx.getSystemInfoSync().SDKVersion;
83
+
84
+ const canUseNewCanvas = compareVersion(version, '2.9.0') >= 0;
85
+ const forceUseOldCanvas = this.data.forceUseOldCanvas;
86
+ const isUseNewCanvas = canUseNewCanvas && !forceUseOldCanvas;
87
+ this.setData({ isUseNewCanvas });
88
+
89
+ if (forceUseOldCanvas && canUseNewCanvas) {
90
+ console.warn('开发者强制使用旧canvas,建议关闭');
91
+ }
92
+
93
+ if (isUseNewCanvas) {
94
+ // console.log('微信基础库版本大于2.9.0,开始使用<canvas type="2d"/>');
95
+ // 2.9.0 可以使用 <canvas type="2d"></canvas>
96
+ this.initByNewWay(callback);
97
+ } else {
98
+ const isValid = compareVersion(version, '1.9.91') >= 0;
99
+ if (!isValid) {
100
+ console.error(
101
+ '微信基础库版本过低,需大于等于 1.9.91。' +
102
+ '参见:https://github.com/ecomfe/echarts-for-weixin' +
103
+ '#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82'
104
+ );
105
+ return;
106
+ } else {
107
+ console.warn(
108
+ '建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能'
109
+ );
110
+ this.initByOldWay(callback);
111
+ }
112
+ }
113
+ },
114
+
115
+ initByOldWay(callback) {
116
+ // 1.9.91 <= version < 2.9.0:原来的方式初始化
117
+ ctx = wx.createCanvasContext(this.data.canvasId, this);
118
+ const canvas = new WxCanvas(ctx, this.data.canvasId, false);
119
+
120
+ echarts.setCanvasCreator(() => {
121
+ return canvas;
122
+ });
123
+ // const canvasDpr = wx.getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr
124
+ const canvasDpr = 1;
125
+ var query = wx.createSelectorQuery().in(this);
126
+ query
127
+ .select('.ec-canvas')
128
+ .boundingClientRect(async (res) => {
129
+ if (typeof callback === 'function') {
130
+ this.chart = callback(canvas, res.width, res.height, canvasDpr);
131
+ } else if (
132
+ this.data.ec &&
133
+ typeof this.data.ec.onInit === 'function'
134
+ ) {
135
+ this.chart = await this.data.ec.onInit(
136
+ canvas,
137
+ res.width,
138
+ res.height,
139
+ canvasDpr
140
+ );
141
+ } else {
142
+ this.triggerEvent('init', {
143
+ canvas: canvas,
144
+ width: res.width,
145
+ height: res.height,
146
+ canvasDpr: canvasDpr, // 增加了dpr,可方便外面echarts.init
147
+ });
148
+ }
149
+ })
150
+ .exec();
151
+ },
152
+
153
+ initByNewWay(callback) {
154
+ // version >= 2.9.0:使用新的方式初始化
155
+ const query = wx.createSelectorQuery().in(this);
156
+ query
157
+ .select('.ec-canvas')
158
+ .fields({ node: true, size: true })
159
+ .exec(async (res) => {
160
+ const canvasNode = res[0].node;
161
+ this.canvasNode = canvasNode;
162
+
163
+ const canvasDpr = wx.getSystemInfoSync().pixelRatio;
164
+ const canvasWidth = res[0].width;
165
+ const canvasHeight = res[0].height;
166
+
167
+ const ctx = canvasNode.getContext('2d');
168
+
169
+ const canvas = new WxCanvas(
170
+ ctx,
171
+ this.data.canvasId,
172
+ true,
173
+ canvasNode
174
+ );
175
+ echarts.setCanvasCreator(() => {
176
+ return canvas;
177
+ });
178
+
179
+ if (typeof callback === 'function') {
180
+ this.chart = callback(canvas, canvasWidth, canvasHeight, canvasDpr);
181
+ } else if (
182
+ this.data.ec &&
183
+ typeof this.data.ec.onInit === 'function'
184
+ ) {
185
+ this.chart = await this.data.ec.onInit(
186
+ canvas,
187
+ canvasWidth,
188
+ canvasHeight,
189
+ canvasDpr
190
+ );
191
+ } else {
192
+ this.triggerEvent('init', {
193
+ canvas: canvas,
194
+ width: canvasWidth,
195
+ height: canvasHeight,
196
+ dpr: canvasDpr,
197
+ });
198
+ }
199
+ });
200
+ },
201
+ canvasToTempFilePath(opt) {
202
+ if (this.data.isUseNewCanvas) {
203
+ // 新版
204
+ const query = wx.createSelectorQuery().in(this);
205
+ query
206
+ .select('.ec-canvas')
207
+ .fields({ node: true, size: true })
208
+ .exec((res) => {
209
+ const canvasNode = res[0].node;
210
+ opt.canvas = canvasNode;
211
+ wx.canvasToTempFilePath(opt);
212
+ });
213
+ } else {
214
+ // 旧的
215
+ if (!opt.canvasId) {
216
+ opt.canvasId = this.data.canvasId;
217
+ }
218
+ ctx.draw(true, () => {
219
+ wx.canvasToTempFilePath(opt, this);
220
+ });
221
+ }
222
+ },
223
+
224
+ touchStart(e) {
225
+ if (this.chart && e.touches.length > 0) {
226
+ var touch = e.touches[0];
227
+ var handler = this.chart.getZr().handler;
228
+ handler.dispatch('mousedown', {
229
+ zrX: touch.x,
230
+ zrY: touch.y,
231
+ });
232
+ handler.dispatch('mousemove', {
233
+ zrX: touch.x,
234
+ zrY: touch.y,
235
+ });
236
+ handler.processGesture(wrapTouch(e), 'start');
237
+ }
238
+ },
239
+
240
+ touchMove(e) {
241
+ if (this.chart && e.touches.length > 0) {
242
+ var touch = e.touches[0];
243
+ var handler = this.chart.getZr().handler;
244
+ handler.dispatch('mousemove', {
245
+ zrX: touch.x,
246
+ zrY: touch.y,
247
+ });
248
+ handler.processGesture(wrapTouch(e), 'change');
249
+ }
250
+ },
251
+
252
+ touchEnd(e) {
253
+ if (this.chart) {
254
+ const touch = e.changedTouches ? e.changedTouches[0] : {};
255
+ var handler = this.chart.getZr().handler;
256
+ handler.dispatch('mouseup', {
257
+ zrX: touch.x,
258
+ zrY: touch.y,
259
+ });
260
+ handler.dispatch('click', {
261
+ zrX: touch.x,
262
+ zrY: touch.y,
263
+ });
264
+ handler.processGesture(wrapTouch(e), 'end');
265
+ }
266
+ },
267
+ },
268
+ });
269
+
270
+ function wrapTouch(event) {
271
+ for (let i = 0; i < event.touches.length; ++i) {
272
+ const touch = event.touches[i];
273
+ touch.offsetX = touch.x;
274
+ touch.offsetY = touch.y;
275
+ }
276
+ return event;
277
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "component": true,
3
+ "usingComponents": {}
4
+ }
@@ -0,0 +1,4 @@
1
+ <!-- 新的:接口对齐了H5 -->
2
+ <canvas wx:if="{{isUseNewCanvas}}" type="2d" class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
3
+ <!-- 旧的 -->
4
+ <canvas wx:else class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
@@ -0,0 +1,4 @@
1
+ .ec-canvas {
2
+ width: 100%;
3
+ height: 100%;
4
+ }
@@ -0,0 +1,107 @@
1
+ class WxCanvas {
2
+ constructor(ctx, canvasId, isNew, canvasNode) {
3
+ this.ctx = ctx;
4
+ this.canvasId = canvasId;
5
+ this.chart = null;
6
+ this.isNew = isNew;
7
+ if (isNew) {
8
+ this.canvasNode = canvasNode;
9
+ }
10
+ else {
11
+ this._initStyle(ctx);
12
+ }
13
+
14
+ // this._initCanvas(zrender, ctx);
15
+
16
+ this._initEvent();
17
+ }
18
+
19
+ getContext(contextType) {
20
+ if (contextType === '2d') {
21
+ return this.ctx;
22
+ }
23
+ }
24
+
25
+ // canvasToTempFilePath(opt) {
26
+ // if (!opt.canvasId) {
27
+ // opt.canvasId = this.canvasId;
28
+ // }
29
+ // return wx.canvasToTempFilePath(opt, this);
30
+ // }
31
+
32
+ setChart(chart) {
33
+ this.chart = chart;
34
+ }
35
+
36
+ attachEvent() {
37
+ // noop
38
+ }
39
+
40
+ detachEvent() {
41
+ // noop
42
+ }
43
+
44
+ _initCanvas(zrender, ctx) {
45
+ zrender.util.getContext = function () {
46
+ return ctx;
47
+ };
48
+
49
+ zrender.util.$override('measureText', function (text, font) {
50
+ ctx.font = font || '12px sans-serif';
51
+ return ctx.measureText(text);
52
+ });
53
+ }
54
+
55
+ _initStyle(ctx) {
56
+ ctx.createRadialGradient = () => {
57
+ return ctx.createCircularGradient(arguments);
58
+ };
59
+ }
60
+
61
+ _initEvent() {
62
+ this.event = {};
63
+ const eventNames = [{
64
+ wxName: 'touchStart',
65
+ ecName: 'mousedown'
66
+ }, {
67
+ wxName: 'touchMove',
68
+ ecName: 'mousemove'
69
+ }, {
70
+ wxName: 'touchEnd',
71
+ ecName: 'mouseup'
72
+ }, {
73
+ wxName: 'touchEnd',
74
+ ecName: 'click'
75
+ }];
76
+
77
+ eventNames.forEach(name => {
78
+ this.event[name.wxName] = e => {
79
+ const touch = e.touches[0];
80
+ this.chart.getZr().handler.dispatch(name.ecName, {
81
+ zrX: name.wxName === 'tap' ? touch.clientX : touch.x,
82
+ zrY: name.wxName === 'tap' ? touch.clientY : touch.y
83
+ });
84
+ };
85
+ });
86
+ }
87
+
88
+ set width(w) {
89
+ if (this.canvasNode) this.canvasNode.width = w;
90
+ }
91
+ set height(h) {
92
+ if (this.canvasNode) this.canvasNode.height = h;
93
+ }
94
+
95
+ get width() {
96
+ if (this.canvasNode)
97
+ return this.canvasNode.width;
98
+ return 0;
99
+ }
100
+ get height() {
101
+ if (this.canvasNode)
102
+ return this.canvasNode.height;
103
+ return 0;
104
+ }
105
+ }
106
+
107
+ export default WxCanvas;
@@ -0,0 +1,247 @@
1
+ import * as echarts from '../common/lib/echarts.min';
2
+ import EchartLine from '../common/core/eChartLine';
3
+ Component({
4
+ options: {
5
+ virtualHost: true,
6
+ multipleSlots: true,
7
+ },
8
+ properties: {
9
+ id: {
10
+ type: String,
11
+ value: '',
12
+ },
13
+ className: {
14
+ type: String,
15
+ value: '',
16
+ },
17
+ style: {
18
+ type: String,
19
+ value: '',
20
+ },
21
+ chartType: {
22
+ // 线条类型
23
+ type: String,
24
+ value: 'bight',
25
+ },
26
+ title: {
27
+ // 图表标题
28
+ type: String,
29
+ },
30
+ isTitle: {
31
+ // 是否显示标题
32
+ type: Boolean,
33
+ value: false,
34
+ },
35
+ titleLocation: {
36
+ type: String,
37
+ value: 'top',
38
+ },
39
+ dataSource: {
40
+ // 数据源
41
+ type: Object,
42
+ },
43
+ filterData: {
44
+ // 数据筛选
45
+ type: Array,
46
+ value: [],
47
+ },
48
+ xField: {
49
+ // x轴字段选择
50
+ type: Object,
51
+ value: {
52
+ format: '',
53
+ type: '', // 数据源字段 类型
54
+ title: '', // 字段名中文
55
+ name: '', // 字段名英文
56
+ },
57
+ },
58
+ xStatistics: {
59
+ // x轴统计维度
60
+ type: String,
61
+ value: '', // 统计纬度, 只有选择时间类型才有,y 年,m月,d 日,w周,h时,min 分,s秒
62
+ },
63
+ groupKey: {
64
+ // x轴字段选择
65
+ type: Object,
66
+ value: {
67
+ format: '',
68
+ type: '', // 数据源字段 类型
69
+ title: '', // 字段名中文
70
+ name: '', // 字段名英文
71
+ },
72
+ },
73
+ groupKeyTimeSpan: {
74
+ // x轴统计维度
75
+ type: String,
76
+ value: '', // 统计纬度, 只有选择时间类型才有,y 年,m月,d 日,w周,h时,min 分,s秒
77
+ },
78
+ xIsCountEmpty: {
79
+ // x轴 是否统计空值
80
+ type: Boolean,
81
+ value: false,
82
+ },
83
+ yField: {
84
+ // Y轴字段,分组字段,是否分组
85
+ type: Object,
86
+ value: {
87
+ numValue: [{ key: '', operationType: '' }],
88
+ groupKey: '',
89
+ },
90
+ },
91
+ isLegend: {
92
+ // 是否显示图例
93
+ type: Boolean,
94
+ value: false,
95
+ },
96
+ legend: {
97
+ // 图例
98
+ type: String,
99
+ value: 'bottom', // 左 left 右right, 上top,下 bottom
100
+ },
101
+
102
+ // 高级属性
103
+ isXaxisName: {
104
+ // 是否显示坐标轴名称
105
+ type: Boolean,
106
+ value: true,
107
+ },
108
+ xAxisName: {
109
+ // 是否显示坐标轴名称
110
+ type: String,
111
+ value: '',
112
+ },
113
+ isXaxisAxisLabelShow: {
114
+ // 是否显示标签
115
+ type: Boolean,
116
+ value: true,
117
+ },
118
+ isXaxisAxisTickShow: {
119
+ // 显示X轴刻度线
120
+ type: Boolean,
121
+ value: true,
122
+ },
123
+ isXaxisAxisLabelRotate: {
124
+ // 文字自动倾斜
125
+ type: Boolean,
126
+ value: false,
127
+ },
128
+ isYAxisShow: {
129
+ // 是否显示 Y 轴刻度线
130
+ type: Boolean,
131
+ value: true,
132
+ },
133
+ isYAxisName: {
134
+ // 是否显示 Y坐标轴名称
135
+ type: Boolean,
136
+ value: true,
137
+ },
138
+ isYAxisSplitlineLinestyleWidth: {
139
+ // 是否显示网格线 ,yAxis.splitLine.lineStyle.width设置为0
140
+ type: Boolean,
141
+ value: true,
142
+ },
143
+ yAxisSplitlineLinestyleType: {
144
+ // 网格线线条类型 solid,dashed,dotted
145
+ type: String,
146
+ value: 'dashed',
147
+ },
148
+ yAxisName: {
149
+ // Y坐标轴名称 显示名称后需要设置居中,轴线距离属性 yAxis.nameLocation='middle' yAxis.nameGap =20
150
+ type: String,
151
+ value: '',
152
+ },
153
+ yAxisMin: {
154
+ // Y轴刻度最小值
155
+ type: Number,
156
+ value: 0,
157
+ },
158
+ yAxisMax: {
159
+ // Y轴刻度最大值, 切记如果为0时,则不设置
160
+ type: Number,
161
+ value: 0,
162
+ },
163
+ isSeriesShowSymbol: {
164
+ // 是否显示数据标签 开启后 属性 series.label.show 要同时设置为true
165
+ type: Boolean,
166
+ value: true,
167
+ },
168
+ isUnit: {
169
+ // 显示单位
170
+ type: Boolean,
171
+ value: false,
172
+ },
173
+ unit: {
174
+ // 数字显示的单位 百分比,千分比,千,万,百万,亿,十亿
175
+ type: String,
176
+ value: '%',
177
+ },
178
+ decimalDigits: {
179
+ // 小数位数
180
+ type: Number,
181
+ value: 0,
182
+ },
183
+ suffix: {
184
+ // 后缀
185
+ type: String,
186
+ value: '',
187
+ },
188
+ },
189
+ data: {
190
+ ec: {},
191
+ canvas_id: {
192
+ type: String,
193
+ value: `canvas_line_${Date.now()}_${Math.random() * 100}`,
194
+ },
195
+ },
196
+ lifetimes: {
197
+ attached() {
198
+ // 在组件实例进入页面节点树时执行
199
+ this.initData();
200
+ },
201
+ detached() {
202
+ // 在组件实例被从页面节点树移除时执行
203
+ },
204
+ },
205
+ // 以下是旧式的定义方式,可以保持对 <2.2.3 版本基础库的兼容
206
+ attached() {
207
+ // 在组件实例进入页面节点树时执行
208
+ this.initData();
209
+ },
210
+ detached() {
211
+ // 在组件实例被从页面节点树移除时执行
212
+ },
213
+ methods: {
214
+ initData() {
215
+ this.setData({
216
+ ec: {
217
+ onInit: this.initChart.bind(this),
218
+ },
219
+ });
220
+ },
221
+ async initChart(canvas, width, height, dpr) {
222
+ const objEchart = echarts.init(canvas, null, {
223
+ width,
224
+ height,
225
+ devicePixelRatio: dpr,
226
+ });
227
+ canvas.setChart(objEchart);
228
+ const objEChartLine = new EchartLine();
229
+ await objEChartLine.setOptions(this.properties);
230
+ const options = await objEChartLine.getOptions();
231
+ // objEchart.clear();
232
+ console.log('设置前参数line', options);
233
+ objEchart.setOption(options);
234
+ this._chart = objEchart;
235
+ return objEchart;
236
+ },
237
+ },
238
+ observers: {
239
+ // 当参数变化时
240
+ '**': async function() {
241
+ const objEChartLine = new EchartLine();
242
+ await objEChartLine.setOptions(this.properties);
243
+ const options = objEChartLine.getOptions();
244
+ this._chart && this._chart.setOption(options);
245
+ },
246
+ }
247
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "component": true,
3
+ "usingComponents": {
4
+ "ec-canvas": "../ec-canvas/ec-canvas"
5
+ }
6
+ }
@@ -0,0 +1,3 @@
1
+ <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}">
2
+ <ec-canvas canvas-id="{{canvas_id}}" ec="{{ ec }}"></ec-canvas>
3
+ </view>
@@ -0,0 +1,9 @@
1
+ /**index.wxss**/
2
+ ec-canvas {
3
+ width: 100%;
4
+ height: 100%;
5
+ }
6
+ .ec_container {
7
+ width: 100%;
8
+ height: 380px;
9
+ }