@cloudbase/weda-ui-mp 3.12.1 → 3.12.3

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.
@@ -1,5 +1,6 @@
1
1
  import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
2
2
  import { transSize, randomStr } from '../../../utils/platform';
3
+ import equal from '../../../utils/deepEqual';
3
4
 
4
5
  Component({
5
6
  options: {
@@ -24,6 +25,9 @@ Component({
24
25
  defaultValue: {
25
26
  type: null,
26
27
  },
28
+ oldValue: {
29
+ type: null,
30
+ },
27
31
  maxUploadCount: {
28
32
  type: Number,
29
33
  value: 9,
@@ -105,10 +109,7 @@ Component({
105
109
  });
106
110
  return false;
107
111
  }
108
- if (
109
- this.properties.maxSize &&
110
- files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)
111
- ) {
112
+ if (this.properties.maxSize && files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)) {
112
113
  wx.showToast({
113
114
  title: `上传文件大小不能超过${this.properties.maxSize}M`,
114
115
  icon: 'none',
@@ -154,6 +155,13 @@ Component({
154
155
  },
155
156
  });
156
157
  },
158
+ getName: function (hf) {
159
+ const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
160
+ const lastIndex = String(hf).lastIndexOf('/');
161
+ const name = String(hf).slice(lastIndex + 1);
162
+ const label = name.replace(uuidReg, '');
163
+ return label;
164
+ },
157
165
  handleUpload: async function (files, reload = false) {
158
166
  var _this = this;
159
167
  if (!this.handleBefore(files)) return;
@@ -172,10 +180,7 @@ Component({
172
180
  });
173
181
  if (typeof ret === 'boolean') {
174
182
  shouldUploadToCos = ret;
175
- } else if (
176
- Array.Array(ret) &&
177
- ret.every((i) => typeof i === 'string')
178
- ) {
183
+ } else if (Array.Array(ret) && ret.every((i) => typeof i === 'string')) {
179
184
  files = ret.map((path, idx) => {
180
185
  files[idx].path = path;
181
186
  });
@@ -193,14 +198,12 @@ Component({
193
198
  ...i,
194
199
  percent: '0',
195
200
  cloudPath: null,
196
- name: i?.name || i?.tempFilePath.slice(9),
201
+ name: i?.name || this.getName(i?.tempFilePath),
197
202
  filePath: i?.path || i?.tempFilePath || null,
198
203
  size: transSize(i?.size),
199
204
  status: 'pending',
200
205
  }));
201
- let filelsList = reload
202
- ? this.data.files
203
- : [...this.data.files, ...initFiles];
206
+ let filelsList = reload ? this.data.files : [...this.data.files, ...initFiles];
204
207
  this.setData({
205
208
  files: filelsList,
206
209
  });
@@ -210,9 +213,7 @@ Component({
210
213
  _this.handleUploadFile({
211
214
  _tempFile: tempFile,
212
215
  onSuccess: (res) => {
213
- filelsList = filelsList.map((i) =>
214
- i.filePath === res.filePath ? res : i
215
- );
216
+ filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
216
217
  _this.triggerEvent('success', {
217
218
  value: res.cloudPath,
218
219
  file: res,
@@ -220,30 +221,22 @@ Component({
220
221
  resolve(res);
221
222
  },
222
223
  onProgressUpdate: (res) => {
223
- filelsList = filelsList.map((i) =>
224
- i.filePath === res.filePath ? res : i
225
- );
224
+ filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
226
225
  _this.setData({
227
226
  files: filelsList,
228
227
  });
229
228
  },
230
229
  onFail: (res, error) => {
231
- filelsList = filelsList.map((i) =>
232
- i.filePath === res.filePath ? res : i
233
- );
230
+ filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
234
231
  _this.triggerEvent('error', error.detail);
235
232
  resolve(res);
236
233
  },
237
234
  });
238
235
  });
239
- })
236
+ }),
240
237
  ).then((res) => {
241
- const result = filelsList.map(
242
- (i) => res.find((j) => j.filePath === i.filePath) || i
243
- );
244
- const cloudPathList = result
245
- .filter((i) => i.cloudPath)
246
- .map((j) => j.cloudPath);
238
+ const result = filelsList.map((i) => res.find((j) => j.filePath === i.filePath) || i);
239
+ const cloudPathList = result.filter((i) => i.cloudPath).map((j) => j.cloudPath);
247
240
  this.setData({
248
241
  files: result,
249
242
  urls: cloudPathList,
@@ -252,12 +245,7 @@ Component({
252
245
  _this.handleChange(cloudPathList);
253
246
  });
254
247
  },
255
- handleUploadFile: async function ({
256
- _tempFile,
257
- onSuccess,
258
- onProgressUpdate,
259
- onFail,
260
- }) {
248
+ handleUploadFile: async function ({ _tempFile, onSuccess, onProgressUpdate, onFail }) {
261
249
  const tempFile = {
262
250
  ..._tempFile,
263
251
  };
@@ -324,20 +312,15 @@ Component({
324
312
  }
325
313
  });
326
314
  this.setData({
327
- files: this.data.files.filter(
328
- (v) => e.target.dataset.item.cloudPath !== v.cloudPath
329
- ),
315
+ files: this.data.files.filter((v) => e.target.dataset.item.cloudPath !== v.cloudPath),
330
316
  urls: newUrls,
331
317
  });
332
318
  } else {
333
319
  const filelist = this.data.files.filter(
334
320
  (item) =>
335
- e.target.dataset.item?.path != item?.path ||
336
- e.target.dataset.item?.tempFilePath != item?.tempFilePath
337
- );
338
- newUrls = this.data.urls.filter(
339
- (v) => e.target.dataset.item?.cloudPath != v
321
+ e.target.dataset.item?.path != item?.path || e.target.dataset.item?.tempFilePath != item?.tempFilePath,
340
322
  );
323
+ newUrls = this.data.urls.filter((v) => e.target.dataset.item?.cloudPath != v);
341
324
  this.setData({
342
325
  files: filelist,
343
326
  urls: newUrls,
@@ -352,6 +335,7 @@ Component({
352
335
  if (this.properties.single) {
353
336
  value = values[0] ?? '';
354
337
  }
338
+ this.setData({ oldValue: value });
355
339
  this.triggerEvent('change', { value });
356
340
  },
357
341
 
@@ -428,6 +412,9 @@ Component({
428
412
  },
429
413
  observers: {
430
414
  defaultValue: async function (value) {
415
+ if (equal(this.data.oldValue, value)) {
416
+ return;
417
+ }
431
418
  //当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
432
419
  if (Array.isArray(value) && !this.data.singleFlag) {
433
420
  this.setData({
@@ -441,10 +428,7 @@ Component({
441
428
  for (let f of values) {
442
429
  if (f.startsWith('cloud:')) {
443
430
  const hf = await getTempFileURL(f);
444
- const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
445
- const lastIndex = String(hf).lastIndexOf('/');
446
- const name = String(hf).slice(lastIndex + 1);
447
- const label = name.replace(uuidReg, '');
431
+ const label = this.getName(hf);
448
432
  const httpFile = {
449
433
  name: label,
450
434
  cloudPath: f,
@@ -455,19 +439,14 @@ Component({
455
439
  httpFiles.push(httpFile);
456
440
  }
457
441
  }
458
- const files = this.data.files;
459
- // 文件上传成功也会触发defaultValue变化,此情况不执行初始化文件列表
460
- if (!files?.length) {
461
- this.setData({
462
- files: httpFiles,
463
- cloudFile:
464
- JSON.stringify(value) != JSON.stringify(this.data.cloudFile)
465
- ? [].concat(value)
466
- : [],
467
- });
468
- }
442
+ this.setData({
443
+ oldValue: value,
444
+ files: httpFiles,
445
+ cloudFile: JSON.stringify(value) != JSON.stringify(this.data.cloudFile) ? [].concat(value) : [],
446
+ });
469
447
  } else {
470
448
  this.setData({
449
+ oldValue: value,
471
450
  files: [],
472
451
  cloudFile: [],
473
452
  });
@@ -481,8 +460,7 @@ Component({
481
460
  },
482
461
  'layout,extClass': function (layout, extClass) {
483
462
  const temp = `weda-formcells weui-cells weui-cells_forms ${extClass}`;
484
- const layoutCls =
485
- layout !== 'vertical' ? ` weui-flex ${temp}` : `${temp}`;
463
+ const layoutCls = layout !== 'vertical' ? ` weui-flex ${temp}` : `${temp}`;
486
464
  this.setData({ layoutCls });
487
465
  },
488
466
  },
@@ -31,7 +31,7 @@
31
31
  /* theme */
32
32
  .weda-uploader-files__btn {
33
33
  margin: 0;
34
- width: 88px;
34
+ width: auto;
35
35
  height: 32px;
36
36
  padding: 0;
37
37
  display: flex;
@@ -132,27 +132,19 @@
132
132
  }
133
133
 
134
134
  /* 标准化样式适配 start */
135
- .wd-form-item.wd-mp-upload-file-root
136
- .weda-uploader-files
137
- .weda-uploader-files__btn-contain {
135
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__btn-contain {
138
136
  padding: 0;
139
137
  }
140
138
 
141
- .wd-form-item.wd-mp-upload-file-root
142
- .weda-uploader-files
143
- .weda-uploader-files__file-status {
139
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__file-status {
144
140
  width: auto;
145
141
  }
146
142
 
147
- .wd-form-item.wd-mp-upload-file-root
148
- .weda-uploader-files
149
- .weda-uploader-files__file-foot {
143
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__file-foot {
150
144
  margin: 0;
151
145
  }
152
146
 
153
- .wd-form-item.wd-mp-upload-file-root
154
- .weda-uploader-files
155
- .weda-uploader-files__item {
147
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__item {
156
148
  padding: 0;
157
149
  }
158
150
 
@@ -179,14 +179,7 @@ Component({
179
179
  methods: {
180
180
  // 数据列表设置表达式: 区分前后端分页
181
181
  setExpression: function () {
182
- const {
183
- dataSourceData,
184
- enableTotal,
185
- total: _total,
186
- isRecords,
187
- pageSize,
188
- pagination,
189
- } = this.properties;
182
+ const { dataSourceData, enableTotal, total: _total, isRecords, pageSize, pagination } = this.properties;
190
183
  const { pageNo } = this.data;
191
184
  let records = [];
192
185
  let total = 0;
@@ -207,7 +200,7 @@ Component({
207
200
  const pageStr = this.getPageStr(total, pageNo, pageSize);
208
201
  this.data.delayRef.current.initExpr = true;
209
202
  this.setData({ records, listTotal: total, pageStr }, () =>
210
- this.onSuccessCb({ records, total, isTriggerEmpty: isRecords })
203
+ this.onSuccessCb({ records, total, isTriggerEmpty: isRecords }),
211
204
  );
212
205
  },
213
206
  // 更新参数
@@ -246,13 +239,8 @@ Component({
246
239
  });
247
240
  if (dataSourceType === 'expression') {
248
241
  this.setData({ _status: 'loading' });
249
- this.data.delayRef.current.exprTimer = setTimeout(
250
- () => this.setData({ _status: '' }),
251
- 3000
252
- );
253
- !enableTotal &&
254
- this.data.delayRef.current.initExpr &&
255
- this.setExpression();
242
+ this.data.delayRef.current.exprTimer = setTimeout(() => this.setData({ _status: '' }), 3000);
243
+ !enableTotal && this.data.delayRef.current.initExpr && this.setExpression();
256
244
  return;
257
245
  }
258
246
 
@@ -266,10 +254,7 @@ Component({
266
254
  if (isModel) {
267
255
  dataSourceName = datasource?.name;
268
256
  extra = datasource?.extra;
269
- methodName =
270
- typeof extra?.methodName === 'string'
271
- ? extra?.methodName
272
- : 'wedaGetRecords';
257
+ methodName = typeof extra?.methodName === 'string' ? extra?.methodName : 'wedaGetRecords';
273
258
  eventDataSource = datasource;
274
259
  const modelParams = await getModelParams({
275
260
  ...this.properties,
@@ -289,10 +274,7 @@ Component({
289
274
  return;
290
275
  }
291
276
  // select为空时,不触发请求
292
- if (
293
- methodName === 'wedaGetRecordsV2' &&
294
- !Object.keys(tcbParams?.select)?.length
295
- ) {
277
+ if (methodName === 'wedaGetRecordsV2' && !Object.keys(tcbParams?.select)?.length) {
296
278
  console.warn(`当前请求缺少必要参数 select`);
297
279
  return;
298
280
  }
@@ -308,7 +290,7 @@ Component({
308
290
  params: tcbParams,
309
291
  swr: { forceClear },
310
292
  },
311
- this.data.records.length
293
+ this.data.records.length,
312
294
  );
313
295
  } else {
314
296
  data = await callDataSource(
@@ -321,7 +303,7 @@ Component({
321
303
  }),
322
304
  swr: { forceClear },
323
305
  },
324
- true
306
+ true,
325
307
  );
326
308
  }
327
309
  if (fetchVersion !== this.data.delayRef.current.version) return;
@@ -346,7 +328,7 @@ Component({
346
328
  total: listTotal,
347
329
  isTriggerEmpty: !isDataViewApis,
348
330
  datasource: eventDataSource,
349
- })
331
+ }),
350
332
  );
351
333
  } catch (e) {
352
334
  const obj = this.onFailCb(e);
@@ -393,10 +375,7 @@ Component({
393
375
 
394
376
  // 下一页
395
377
  handleNext: function () {
396
- if (
397
- this.data.status === 'loading' ||
398
- !(this.properties.pageSize * this.data.pageNo < this.data.listTotal)
399
- ) {
378
+ if (this.data.status === 'loading' || !(this.properties.pageSize * this.data.pageNo < this.data.listTotal)) {
400
379
  return;
401
380
  }
402
381
  this.fetchData({ pageNo: this.data.pageNo + 1 });
@@ -413,9 +392,7 @@ Component({
413
392
  // 加载成功(包含为空)事件
414
393
  onSuccessCb: function ({ records, total, isTriggerEmpty, datasource }) {
415
394
  const beforeDataChange = this.properties.beforeDataChange || ((v) => v);
416
- const isDelay = ['loadMoreButton', 'bottomLoad'].includes(
417
- this.properties.pagination
418
- );
395
+ const isDelay = ['loadMoreButton', 'bottomLoad'].includes(this.properties.pagination);
419
396
  this.triggerEvent('onDataChange', {
420
397
  data: beforeDataChange(records),
421
398
  state: this.getContextState(),
@@ -452,10 +429,7 @@ Component({
452
429
  onFailCb: function (e) {
453
430
  this.setData({ _status: 'fail' });
454
431
  const code =
455
- e?.code ||
456
- (this.properties.refType === 'dataView'
457
- ? 'WdDataView.QueryError'
458
- : 'WdListView.QueryError');
432
+ e?.code || (this.properties.refType === 'dataView' ? 'WdDataView.QueryError' : 'WdListView.QueryError');
459
433
  const obj = {
460
434
  code,
461
435
  message: `${e?.message}`,
@@ -479,11 +453,9 @@ Component({
479
453
  _observerSign: function () {
480
454
  setTimeout(() => {
481
455
  this.signObserver = this.createIntersectionObserver();
482
- this.signObserver
483
- .relativeToViewport()
484
- .observe('#weda-list-view_sign', (res) => {
485
- this.setData({ isVisiableSign: res?.intersectionRatio > 0 });
486
- });
456
+ this.signObserver.relativeToViewport().observe('#weda-list-view_sign', (res) => {
457
+ this.setData({ isVisiableSign: res?.intersectionRatio > 0 });
458
+ });
487
459
  }, 500);
488
460
  },
489
461
 
@@ -509,16 +481,13 @@ Component({
509
481
  const { pageNo, listTotal } = this.data;
510
482
  const { pageSize } = this.properties;
511
483
  if (this.properties.pagination === 'pagination') {
512
- const pageNoRaw =
513
- (pageNo - 1) * pageSize + 1 === listTotal ? pageNo - 1 : pageNo;
484
+ const pageNoRaw = (pageNo - 1) * pageSize + 1 === listTotal ? pageNo - 1 : pageNo;
514
485
  await this.fetchData({
515
486
  pageNo: pageNoRaw,
516
487
  records: [],
517
488
  forceClear: true,
518
489
  });
519
- } else if (
520
- ['loadMoreButton', 'bottomLoad'].includes(this.properties.pagination)
521
- ) {
490
+ } else if (['loadMoreButton', 'bottomLoad'].includes(this.properties.pagination)) {
522
491
  await this.fetchData({
523
492
  records: [],
524
493
  isFetchCurrent: true,
@@ -562,29 +531,15 @@ Component({
562
531
  methodDeleteOne: async function (params) {
563
532
  try {
564
533
  if (!this.data.isModel) {
565
- throw new WdCompError(
566
- `${LISTVIEW_MESSAGE.methods_no_support}` || '',
567
- {
568
- code: `${
569
- this.properties.refType === 'dataView'
570
- ? 'WdDataView'
571
- : 'WdListView'
572
- }.ActionNotSupport`,
573
- }
574
- );
534
+ throw new WdCompError(`${LISTVIEW_MESSAGE.methods_no_support}` || '', {
535
+ code: `${this.properties.refType === 'dataView' ? 'WdDataView' : 'WdListView'}.ActionNotSupport`,
536
+ });
575
537
  }
576
538
  const _id = params?._id;
577
539
  if (!_id || typeof _id !== 'string') {
578
- throw new WdCompError(
579
- `${LISTVIEW_MESSAGE.deleteOne_param_error}` || '',
580
- {
581
- code: `${
582
- this.properties.refType === 'dataView'
583
- ? 'WdDataView'
584
- : 'WdListView'
585
- }.DeleteOneParamError`,
586
- }
587
- );
540
+ throw new WdCompError(`${LISTVIEW_MESSAGE.deleteOne_param_error}` || '', {
541
+ code: `${this.properties.refType === 'dataView' ? 'WdDataView' : 'WdListView'}.DeleteOneParamError`,
542
+ });
588
543
  }
589
544
  const { app } = getWedaAPI();
590
545
  await app?.cloud?.callDataSource(
@@ -593,7 +548,7 @@ Component({
593
548
  methodName: 'wedaDelete',
594
549
  params: { _id },
595
550
  },
596
- true
551
+ true,
597
552
  );
598
553
  await this._methodRefreshKeepPage();
599
554
  } catch (e) {
@@ -631,13 +586,12 @@ Component({
631
586
  refresh: this.methodRefresh.bind(this),
632
587
  deleteOne: this.methodDeleteOne.bind(this),
633
588
  error: errorObj,
634
- dataSourceVersion:
635
- datasource?.extra?.methodName === 'wedaGetRecordsV2' ? 'v2' : 'v1',
589
+ dataSourceVersion: datasource?.extra?.methodName === 'wedaGetRecordsV2' ? 'v2' : 'v1',
636
590
  });
637
591
  },
638
592
  },
639
593
  observers: {
640
- 'datasource,bindConnectMetadata,connectorMethod,orderBy,orderType,selectFieldType,selectFields,pageIndex,pageSize,pagination,where,queryCondition,connectorParams,dataSourceType':
594
+ 'datasource,bindConnectMetadata,connectorMethod,orderBy,orderType,selectFieldType,selectFields,pageIndex,pageSize,pagination,where,queryCondition,connectorParams,dataSourceType,sorter':
641
595
  function (...rest) {
642
596
  if (isEqual(this.data.paramRef, rest)) return;
643
597
  this.data.paramRef = rest;
@@ -656,19 +610,11 @@ Component({
656
610
  }
657
611
  },
658
612
  'isVisiableSign,status': function (dIsVisiableSign, dStatus) {
659
- if (
660
- dIsVisiableSign &&
661
- ['', 'success'].includes(dStatus) &&
662
- this.properties.pagination === 'bottomLoad'
663
- ) {
613
+ if (dIsVisiableSign && ['', 'success'].includes(dStatus) && this.properties.pagination === 'bottomLoad') {
664
614
  this.handleNext();
665
615
  }
666
616
  },
667
- 'dataSourceType,isRecords,loadButtonText': function (
668
- dataSourceType,
669
- isRecords,
670
- loadButtonText
671
- ) {
617
+ 'dataSourceType,isRecords,loadButtonText': function (dataSourceType, isRecords, loadButtonText) {
672
618
  const isModel = dataSourceType === 'data-model';
673
619
  const isDataViewApis = !isRecords && !isModel;
674
620
  const loadButtonTextFinal = textToString(loadButtonText) || '加载更多';
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.12.1",
6
+ "version": "3.12.3",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"