@cloudbase/weda-ui-mp 3.14.1 → 3.14.4

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.
@@ -220,10 +220,6 @@ Component({
220
220
  },
221
221
  data: {
222
222
  ec: {},
223
- canvas_id: {
224
- type: String,
225
- value: `canvas_line_${Date.now()}_${Math.random() * 100}`,
226
- },
227
223
  },
228
224
  lifetimes: {
229
225
  attached() {
@@ -269,22 +265,11 @@ Component({
269
265
  return options ?? [];
270
266
  } else {
271
267
  if (this.properties.dataSourceType === 'variable') {
272
- const result = transform(
273
- 'bar',
274
- this.properties.datasourceVariable,
275
- this.properties
276
- );
268
+ const result = transform('bar', this.properties.datasourceVariable, this.properties);
277
269
  return result ?? [];
278
270
  } else if (this.properties.dataSourceType === 'custom-connector') {
279
- const { connector, connectorMethod, connectorParams } =
280
- this.properties;
281
- if (
282
- !(
283
- connector?.datasource?.name &&
284
- connectorMethod?.name &&
285
- connectorParams
286
- )
287
- ) {
271
+ const { connector, connectorMethod, connectorParams } = this.properties;
272
+ if (!(connector?.datasource?.name && connectorMethod?.name && connectorParams)) {
288
273
  console.warn('Chart 参数不完整');
289
274
  }
290
275
  const res = await callDataSource({
@@ -299,6 +284,7 @@ Component({
299
284
  },
300
285
  initData() {
301
286
  this.setData({
287
+ id: this.id,
302
288
  ec: {
303
289
  onInit: this.initChart.bind(this),
304
290
  },
@@ -312,7 +298,6 @@ Component({
312
298
  });
313
299
  canvas.setChart(objEchart);
314
300
  const options = await this.getData();
315
- console.log('设置前参数bar', options);
316
301
  objEchart.setOption(options, true);
317
302
  this._chart = objEchart;
318
303
  return objEchart;
@@ -324,7 +309,6 @@ Component({
324
309
  const canvas = this.selectComponent(`#canvas_${this.properties.id}`);
325
310
  canvas?.init();
326
311
  const options = await this.getData();
327
- console.log('设置前参数bar', options);
328
312
  this._chart && this._chart.setOption(options, true);
329
313
  },
330
314
  },
@@ -1 +1 @@
1
- <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvas-id="{{canvas_id}}" ec="{{ ec }}" /> </view>
1
+ <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvasId="{{'canvas_'+id}}" ec="{{ ec }}" /> </view>
@@ -48,7 +48,7 @@ Component({
48
48
  data: {
49
49
  isUseNewCanvas: false,
50
50
  },
51
-
51
+ domObserver: null,
52
52
  ready: function () {
53
53
  // Disable prograssive because drawImage doesn't support DOM as parameter
54
54
  // See https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
@@ -67,14 +67,10 @@ Component({
67
67
  if (!this.data.ec) {
68
68
  console.warn(
69
69
  '组件需绑定 ec 变量,例:<ec-canvas id="mychart-dom-bar" ' +
70
- 'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>'
70
+ 'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>',
71
71
  );
72
72
  return;
73
73
  }
74
-
75
- if (!this.data.ec.lazyLoad) {
76
- this.init();
77
- }
78
74
  },
79
75
 
80
76
  methods: {
@@ -100,13 +96,11 @@ Component({
100
96
  console.error(
101
97
  '微信基础库版本过低,需大于等于 1.9.91。' +
102
98
  '参见: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'
99
+ '#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82',
104
100
  );
105
101
  return;
106
102
  } else {
107
- console.warn(
108
- '建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能'
109
- );
103
+ console.warn('建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能');
110
104
  this.initByOldWay(callback);
111
105
  }
112
106
  }
@@ -128,16 +122,8 @@ Component({
128
122
  .boundingClientRect(async (res) => {
129
123
  if (typeof callback === 'function') {
130
124
  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
- );
125
+ } else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
126
+ this.chart = await this.data.ec.onInit(canvas, res.width, res.height, canvasDpr);
141
127
  } else {
142
128
  this.triggerEvent('init', {
143
129
  canvas: canvas,
@@ -154,7 +140,7 @@ Component({
154
140
  // version >= 2.9.0:使用新的方式初始化
155
141
  const query = wx.createSelectorQuery().in(this);
156
142
  query
157
- .select('.ec-canvas')
143
+ .select(`#${this.data.canvasId}`)
158
144
  .fields({ node: true, size: true })
159
145
  .exec(async (res) => {
160
146
  const canvasNode = res[0].node;
@@ -166,28 +152,15 @@ Component({
166
152
 
167
153
  const ctx = canvasNode.getContext('2d');
168
154
 
169
- const canvas = new WxCanvas(
170
- ctx,
171
- this.data.canvasId,
172
- true,
173
- canvasNode
174
- );
155
+ const canvas = new WxCanvas(ctx, this.data.canvasId, true, canvasNode);
175
156
  echarts.setCanvasCreator(() => {
176
157
  return canvas;
177
158
  });
178
159
 
179
160
  if (typeof callback === 'function') {
180
161
  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
- );
162
+ } else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
163
+ this.chart = await this.data.ec.onInit(canvas, canvasWidth, canvasHeight, canvasDpr);
191
164
  } else {
192
165
  this.triggerEvent('init', {
193
166
  canvas: canvas,
@@ -196,6 +169,8 @@ Component({
196
169
  dpr: canvasDpr,
197
170
  });
198
171
  }
172
+
173
+ this.domObserver && this.domObserver.disconnect();
199
174
  });
200
175
  },
201
176
  canvasToTempFilePath(opt) {
@@ -264,6 +239,29 @@ Component({
264
239
  handler.processGesture(wrapTouch(e), 'end');
265
240
  }
266
241
  },
242
+
243
+ // 监听模块曝光
244
+ observeModuleExpose() {
245
+ this.domObserver && this.domObserver.disconnect();
246
+ this.domObserver = wx.createIntersectionObserver(this);
247
+ this.domObserver.relativeToViewport().observe(`#${this.data.canvasId}`, (res) => {
248
+ // 当页面出现图表时再绘制图表,避免出现白屏
249
+ if (res.intersectionRatio) {
250
+ this.init();
251
+ }
252
+ });
253
+ },
254
+ },
255
+ lifetimes: {
256
+ attached() {
257
+ // 在组件实例进入页面节点树时执行
258
+ if (!this.data.ec.lazyLoad) {
259
+ this.observeModuleExpose();
260
+ }
261
+ },
262
+ detached() {
263
+ this.domObserver && this.domObserver.disconnect();
264
+ },
267
265
  },
268
266
  });
269
267
 
@@ -1,4 +1,4 @@
1
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>
2
+ <canvas wx:if="{{isUseNewCanvas}}" type="2d" class="ec-canvas" id="{{canvasId}}" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
3
3
  <!-- 旧的 -->
4
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>
@@ -215,10 +215,6 @@ Component({
215
215
  },
216
216
  data: {
217
217
  ec: {},
218
- canvas_id: {
219
- type: String,
220
- value: `canvas_line_${Date.now()}_${Math.random() * 100}`,
221
- },
222
218
  },
223
219
  lifetimes: {
224
220
  attached() {
@@ -264,22 +260,11 @@ Component({
264
260
  return options ?? [];
265
261
  } else {
266
262
  if (this.properties.dataSourceType === 'variable') {
267
- const result = transform(
268
- 'line',
269
- this.properties.datasourceVariable,
270
- this.properties
271
- );
263
+ const result = transform('line', this.properties.datasourceVariable, this.properties);
272
264
  return result ?? [];
273
265
  } else if (this.properties.dataSourceType === 'custom-connector') {
274
- const { connector, connectorMethod, connectorParams } =
275
- this.properties;
276
- if (
277
- !(
278
- connector?.datasource?.name &&
279
- connectorMethod?.name &&
280
- connectorParams
281
- )
282
- ) {
266
+ const { connector, connectorMethod, connectorParams } = this.properties;
267
+ if (!(connector?.datasource?.name && connectorMethod?.name && connectorParams)) {
283
268
  console.warn('Chart 参数不完整');
284
269
  }
285
270
  const res = await callDataSource({
@@ -294,6 +279,7 @@ Component({
294
279
  },
295
280
  initData() {
296
281
  this.setData({
282
+ id: this.id,
297
283
  ec: {
298
284
  onInit: this.initChart.bind(this),
299
285
  },
@@ -307,7 +293,6 @@ Component({
307
293
  });
308
294
  canvas.setChart(objEchart);
309
295
  const options = await this.getData();
310
- console.log('设置前参数line', options);
311
296
  objEchart.setOption(options, true);
312
297
  this._chart = objEchart;
313
298
  return objEchart;
@@ -319,7 +304,6 @@ Component({
319
304
  const canvas = this.selectComponent(`#canvas_${this.properties.id}`);
320
305
  canvas?.init();
321
306
  const options = await this.getData();
322
- console.log('设置前参数line', options);
323
307
  this._chart && this._chart.setOption(options, true);
324
308
  },
325
309
  },
@@ -1 +1 @@
1
- <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvas-id="{{canvas_id}}" ec="{{ ec }}" /> </view>
1
+ <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvasId="{{'canvas_'+id}}" ec="{{ ec }}" /> </view>
@@ -145,10 +145,6 @@ Component({
145
145
  },
146
146
  data: {
147
147
  ec: {},
148
- canvas_id: {
149
- type: String,
150
- value: `canvas_pie_${Date.now()}_${Math.random() * 100}`,
151
- },
152
148
  },
153
149
  lifetimes: {
154
150
  attached() {
@@ -173,7 +169,6 @@ Component({
173
169
  const canvas = this.selectComponent(`#canvas_${this.properties.id}`);
174
170
  canvas?.init();
175
171
  const options = await this.getData();
176
- console.log('设置前参数pie', options);
177
172
  this._chart && this._chart.setOption(options, true);
178
173
  },
179
174
  },
@@ -204,22 +199,11 @@ Component({
204
199
  return options ?? [];
205
200
  } else {
206
201
  if (this.properties.dataSourceType === 'variable') {
207
- const result = transform(
208
- 'pie',
209
- this.properties.datasourceVariable,
210
- this.properties
211
- );
202
+ const result = transform('pie', this.properties.datasourceVariable, this.properties);
212
203
  return result ?? [];
213
204
  } else if (this.properties.dataSourceType === 'custom-connector') {
214
- const { connector, connectorMethod, connectorParams } =
215
- this.properties;
216
- if (
217
- !(
218
- connector?.datasource?.name &&
219
- connectorMethod?.name &&
220
- connectorParams
221
- )
222
- ) {
205
+ const { connector, connectorMethod, connectorParams } = this.properties;
206
+ if (!(connector?.datasource?.name && connectorMethod?.name && connectorParams)) {
223
207
  console.warn('Chart 参数不完整');
224
208
  }
225
209
  const res = await callDataSource({
@@ -234,6 +218,7 @@ Component({
234
218
  },
235
219
  initData() {
236
220
  this.setData({
221
+ id: this.id,
237
222
  ec: {
238
223
  onInit: this.initChart.bind(this),
239
224
  },
@@ -248,7 +233,6 @@ Component({
248
233
  canvas.setChart(objEchart);
249
234
  const options = await this.getData();
250
235
  // objEchart.clear();
251
- console.log('设置前参数pie', options);
252
236
  objEchart.setOption(options, true);
253
237
  this._chart = objEchart;
254
238
  return objEchart;
@@ -1 +1 @@
1
- <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvas-id="{{canvas_id}}" ec="{{ ec }}" /> </view>
1
+ <view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvasId="{{'canvas_'+id}}" ec="{{ ec }}" /> </view>
@@ -62,7 +62,7 @@ Component({
62
62
  : GUTTER_VALUE.find((item) => item.gutterValue === gutterY)?.styleValue || 0;
63
63
  const actalClassName = classNames({
64
64
  'wd-grid': true,
65
- 'wd-grid--avoid-scrollbar': avoidScrollbar,
65
+ 'wd-grid--gap': avoidScrollbar,
66
66
  [`wd-grid-gx-${gutterXValue}`]: !isNil(gutterXValue),
67
67
  // 产品要求guterX 同时间决定row一个换行的间距和 row之间的间距
68
68
  [`wd-grid-gy-${gutterYValue}`]: !isNil(gutterYValue),
@@ -48,8 +48,7 @@ Component({
48
48
  try {
49
49
  return (
50
50
  '<pre><code class="hljs">' +
51
- hljs.highlight(str, { language: lang, ignoreIllegals: true })
52
- .value +
51
+ hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
53
52
  '</code></pre>'
54
53
  );
55
54
  } catch (__) {}
@@ -69,8 +68,7 @@ Component({
69
68
  this.setReadonlyAttributes({
70
69
  value: this.properties.value,
71
70
  markdownInstance: this.data.mdInstance,
72
- updateMarkdownInstance: ({ markdownInstance }) =>
73
- this.setData({ mdInstance: markdownInstance }),
71
+ updateMarkdownInstance: ({ markdownInstance }) => this.setData({ mdInstance: markdownInstance }),
74
72
  });
75
73
  },
76
74
  },
@@ -78,7 +76,6 @@ Component({
78
76
  value: function () {
79
77
  const { mdInstance } = this.data;
80
78
  if (!mdInstance) return;
81
- console.log(this.data.value);
82
79
  this.setData({
83
80
  __html: mdInstance.render(this.data.value),
84
81
  });
@@ -2,10 +2,7 @@ import { commonCompBehavior } from '../../utils/common-behavior';
2
2
  import formFieldBehavior from '../form-field-behavior/form-field-behavior';
3
3
  import { WD_PREFIX } from '../../utils/constant';
4
4
  import itemBehavior from '../form-field-behavior/item-behavior';
5
- import {
6
- calculateNextValue,
7
- calculatePercentByValueAndBoundary,
8
- } from '../../utils/range';
5
+ import { calculateNextValue, calculatePercentByValueAndBoundary } from '../../utils/range';
9
6
 
10
7
  Component({
11
8
  options: {
@@ -34,13 +31,20 @@ Component({
34
31
  data: {
35
32
  classPrefix: WD_PREFIX,
36
33
  percent: 0,
34
+ active: true,
37
35
  },
38
36
  methods: {
39
37
  onTap: function (e) {
38
+ if (!this.data.active) {
39
+ return;
40
+ }
40
41
  const mouseX = e.detail.x;
41
42
  this._triggerChangeWithMouseX(mouseX);
42
43
  },
43
44
  onTouchStart: function (e) {
45
+ if (!this.data.active) {
46
+ return;
47
+ }
44
48
  const mouseX = e.touches[0]?.clientX;
45
49
  if (typeof mouseX !== 'number') {
46
50
  return;
@@ -48,6 +52,9 @@ Component({
48
52
  this._triggerChangeWithMouseX(mouseX);
49
53
  },
50
54
  onTouchMove: function (e) {
55
+ if (!this.data.active) {
56
+ return;
57
+ }
51
58
  const mouseX = e.touches[0]?.clientX;
52
59
  if (typeof mouseX !== 'number') {
53
60
  return;
@@ -55,19 +62,7 @@ Component({
55
62
  this._triggerChangeWithMouseX(mouseX);
56
63
  },
57
64
  updateWidgetAPI: function () {
58
- const {
59
- name,
60
- value,
61
- label,
62
- required,
63
- visible,
64
- disabled,
65
- readOnly,
66
- showPercent,
67
- min,
68
- max,
69
- step,
70
- } = this.data;
65
+ const { name, value, label, required, visible, disabled, readOnly, showPercent, min, max, step } = this.data;
71
66
  this.setReadonlyAttributes?.({
72
67
  name,
73
68
  value,
@@ -126,9 +121,13 @@ Component({
126
121
  'value, min, max': function () {
127
122
  this._computePercent();
128
123
  },
129
- 'name, value, label, required, visible, disabled, readOnly, showPercent, min, max, step':
130
- function () {
131
- this.updateWidgetAPI();
132
- },
124
+ 'name, value, label, required, visible, disabled, readOnly, showPercent, min, max, step': function () {
125
+ this.updateWidgetAPI();
126
+ },
127
+ 'disabled,readOnly': function (disabled, readOnly) {
128
+ this.setData({
129
+ active: !(readOnly || disabled),
130
+ });
131
+ },
133
132
  },
134
133
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.14.1",
6
+ "version": "3.14.4",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"