@cloudbase/weda-ui-mp 3.13.5 → 3.13.6

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,13 +1,6 @@
1
1
  import classNames from '../../../utils/classnames';
2
2
  import dayjs from '../../../utils/dayjs.min.js';
3
- import {
4
- getRegionTree,
5
- buildDisplayValue,
6
- provinces,
7
- cities,
8
- regions,
9
- getAreaKey,
10
- } from './region/index';
3
+ import { getRegionTree, buildDisplayValue, provinces, cities, regions, getAreaKey } from './region/index';
11
4
  import destr from '../../../utils/destr';
12
5
  import deepEqual from '../../../utils/deepEqual';
13
6
  import { callDataSourceApi, callWedaApi } from '../../../utils/tcb';
@@ -240,12 +233,8 @@ Component({
240
233
  break;
241
234
  }
242
235
  case 'time': {
243
- start = startTime
244
- ? this.converTime2Dayjs(startTime).format('HH:mm')
245
- : undefined;
246
- end = endTime
247
- ? this.converTime2Dayjs(endTime).format('HH:mm')
248
- : undefined;
236
+ start = startTime ? this.converTime2Dayjs(startTime).format('HH:mm') : undefined;
237
+ end = endTime ? this.converTime2Dayjs(endTime).format('HH:mm') : undefined;
249
238
  break;
250
239
  }
251
240
  case 'date': {
@@ -287,137 +276,20 @@ Component({
287
276
  },
288
277
  },
289
278
  observers: {
290
- 'defaultValue, defaultTime, defaultRegion,defaultMutiRegion,defaultDate,option,regionType':
291
- function (
292
- defaultValue,
293
- defaultTime,
294
- defaultRegion,
295
- defaultMutiRegion,
296
- defaultDate,
297
- option,
298
- regionType
299
- ) {
300
- const { range, mode, separator, placeholder, dateMode, format } =
301
- this.properties;
302
-
303
- if (
304
- deepEqual(
305
- {
306
- defaultValue,
307
- defaultTime,
308
- defaultRegion,
309
- defaultMutiRegion,
310
- defaultDate,
311
- option,
312
- range,
313
- mode,
314
- separator,
315
- placeholder,
316
- dateMode,
317
- format,
318
- regionType,
319
- },
320
- this.data.__prev
321
- )
322
- ) {
323
- return;
324
- }
279
+ 'defaultValue, defaultTime, defaultRegion,defaultMutiRegion,defaultDate,option,regionType': function (
280
+ defaultValue,
281
+ defaultTime,
282
+ defaultRegion,
283
+ defaultMutiRegion,
284
+ defaultDate,
285
+ option,
286
+ regionType,
287
+ ) {
288
+ const { range, mode, separator, placeholder, dateMode, format } = this.properties;
325
289
 
326
- let value, displayValue;
327
- switch (mode) {
328
- case 'selector': {
329
- // TODO: == 故意的
330
- if (!isFormatNeedFetch(format)) {
331
- const index = range.findIndex(
332
- (item) => item.value == defaultValue
333
- );
334
- // 小程序picker组件,value值表示选择了 range 中的第几个(下标从 0 开始),类型为number
335
- value = index < 0 ? 0 : index;
336
- displayValue = index < 0 ? defaultValue : range[index].label;
337
- // 更新选中值
338
- this.setData({
339
- chooseIndexValue: index < 0 ? defaultValue : range[index].value,
340
- chooseIndexLable: displayValue,
341
- });
342
- } else {
343
- const { chooseIndexValue } = this.data;
344
- const currentValue = defaultValue;
345
- const index = option.findIndex(
346
- (item) => item.value == currentValue
347
- );
348
- if (
349
- !chooseIndexValue &&
350
- this.data.option.length > 0 &&
351
- index === -1 &&
352
- defaultValue &&
353
- defaultValue.length > 0
354
- ) {
355
- // 没查找到,接口查找
356
- this._fetchData(
357
- [
358
- {
359
- _id: {
360
- $eq: defaultValue,
361
- },
362
- },
363
- ],
364
- 1,
365
- true
366
- );
367
- // 再次判断
368
- if (
369
- this.data.chooseIndexValue &&
370
- this.data.chooseIndexValue.length > 0
371
- ) {
372
- // 找到了
373
- displayValue = this.data.chooseIndexLable;
374
- }
375
- } else {
376
- value = index < 0 ? 0 : index;
377
- displayValue = index < 0 ? currentValue : option[index].label;
378
- }
379
- // 更新value
380
- this.setData({
381
- chooseIndexValue: currentValue,
382
- chooseIndexLable: displayValue,
383
- });
384
- }
385
- break;
386
- }
387
- case 'date': {
388
- value = this._coverNumber2Date(defaultDate, dateMode);
389
- displayValue = this._coverNumber2Date(defaultDate, dateMode, true);
390
- break;
391
- }
392
- case 'time': {
393
- value =
394
- defaultTime == null || defaultTime === ''
395
- ? ''
396
- : this.converTime(`${defaultTime}`);
397
- displayValue = value;
398
- break;
399
- }
400
- case 'region': {
401
- value = defaultRegion;
402
- displayValue = defaultRegion.join(separator);
403
- break;
404
- }
405
- case 'mutiRegion': {
406
- displayValue = defaultMutiRegion || '';
407
- this.getProvince(displayValue);
408
- break;
409
- }
410
- default: {
411
- break;
412
- }
413
- }
414
- const data = { displayValue };
415
- if (mode !== 'mutiRegion') {
416
- data.value = value;
417
- }
418
- this.setData(data);
419
- this.setData({
420
- __prev: {
290
+ if (
291
+ deepEqual(
292
+ {
421
293
  defaultValue,
422
294
  defaultTime,
423
295
  defaultRegion,
@@ -432,8 +304,113 @@ Component({
432
304
  format,
433
305
  regionType,
434
306
  },
435
- });
436
- },
307
+ this.data.__prev,
308
+ )
309
+ ) {
310
+ return;
311
+ }
312
+
313
+ let value, displayValue;
314
+ switch (mode) {
315
+ case 'selector': {
316
+ // TODO: == 故意的
317
+ if (!isFormatNeedFetch(format)) {
318
+ const index = range.findIndex((item) => item.value == defaultValue);
319
+ // 小程序picker组件,value值表示选择了 range 中的第几个(下标从 0 开始),类型为number
320
+ value = index < 0 ? 0 : index;
321
+ displayValue = index < 0 ? defaultValue : range[index].label;
322
+ // 更新选中值
323
+ this.setData({
324
+ chooseIndexValue: index < 0 ? defaultValue : range[index].value,
325
+ chooseIndexLable: displayValue,
326
+ });
327
+ } else {
328
+ const { chooseIndexValue } = this.data;
329
+ const currentValue = defaultValue;
330
+ const index = option.findIndex((item) => item.value == currentValue);
331
+ if (
332
+ !chooseIndexValue &&
333
+ this.data.option.length > 0 &&
334
+ index === -1 &&
335
+ defaultValue &&
336
+ defaultValue.length > 0
337
+ ) {
338
+ // 没查找到,接口查找
339
+ this._fetchData(
340
+ [
341
+ {
342
+ _id: {
343
+ $eq: defaultValue,
344
+ },
345
+ },
346
+ ],
347
+ 1,
348
+ true,
349
+ );
350
+ // 再次判断
351
+ if (this.data.chooseIndexValue && this.data.chooseIndexValue.length > 0) {
352
+ // 找到了
353
+ displayValue = this.data.chooseIndexLable;
354
+ }
355
+ } else {
356
+ value = index < 0 ? 0 : index;
357
+ displayValue = index < 0 ? currentValue : option[index].label;
358
+ }
359
+ // 更新value
360
+ this.setData({
361
+ chooseIndexValue: currentValue,
362
+ chooseIndexLable: displayValue,
363
+ });
364
+ }
365
+ break;
366
+ }
367
+ case 'date': {
368
+ value = this._coverNumber2Date(defaultDate, dateMode);
369
+ displayValue = this._coverNumber2Date(defaultDate, dateMode, true);
370
+ break;
371
+ }
372
+ case 'time': {
373
+ value = defaultTime == null || defaultTime === '' ? '' : this.converTime(`${defaultTime}`);
374
+ displayValue = value;
375
+ break;
376
+ }
377
+ case 'region': {
378
+ value = defaultRegion;
379
+ displayValue = defaultRegion.join(separator);
380
+ break;
381
+ }
382
+ case 'mutiRegion': {
383
+ displayValue = defaultMutiRegion || '';
384
+ this.getProvince(displayValue);
385
+ break;
386
+ }
387
+ default: {
388
+ break;
389
+ }
390
+ }
391
+ const data = { displayValue };
392
+ if (mode !== 'mutiRegion') {
393
+ data.value = value;
394
+ }
395
+ this.setData(data);
396
+ this.setData({
397
+ __prev: {
398
+ defaultValue,
399
+ defaultTime,
400
+ defaultRegion,
401
+ defaultMutiRegion,
402
+ defaultDate,
403
+ option,
404
+ range,
405
+ mode,
406
+ separator,
407
+ placeholder,
408
+ dateMode,
409
+ format,
410
+ regionType,
411
+ },
412
+ });
413
+ },
437
414
  range: function (range) {
438
415
  // 防止range在不改变的情况下重新对option赋值,导致触发option的observer改变选中值
439
416
  if (JSON.stringify(this.data.oldRange) === JSON.stringify(range)) return;
@@ -536,23 +513,15 @@ Component({
536
513
  },
537
514
  'format,defaultValue': function (format, defaultValue) {
538
515
  if (isFormatNeedFetch(format)) {
539
- this._fetchData(
540
- defaultValue ? [{ _id: { $eq: defaultValue } }] : [],
541
- 1,
542
- false
543
- );
516
+ this._fetchData(defaultValue ? [{ _id: { $eq: defaultValue } }] : [], 1, false);
544
517
  }
545
518
  },
546
519
  },
547
520
  methods: {
548
521
  // 最终选择的日期时间
549
522
  onAllTimePicker: function (e) {
550
- const show =
551
- e.currentTarget.dataset.show === undefined
552
- ? e.detail.show
553
- : e.currentTarget.dataset.show;
554
- if (!show && e?.detail?.confirm)
555
- this.triggerEvent('change', { value: e.detail.dateTamp });
523
+ const show = e.currentTarget.dataset.show === undefined ? e.detail.show : e.currentTarget.dataset.show;
524
+ if (!show && e?.detail?.confirm) this.triggerEvent('change', { value: e.detail.dateTamp });
556
525
  this.setData({
557
526
  allPickerShow: typeof show === 'boolean' ? show : JSON.parse(show),
558
527
  value: e.detail.data,
@@ -589,18 +558,12 @@ Component({
589
558
  });
590
559
  const { isSearch, option, searchOption, chooseIndexValue } = this.data;
591
560
  if (chooseIndexValue && chooseIndexLable !== displayValue) {
592
- const index = (isSearch ? searchOption : option)?.findIndex(
593
- (item) => item.value === chooseIndexValue
594
- );
561
+ const index = (isSearch ? searchOption : option)?.findIndex((item) => item.value === chooseIndexValue);
595
562
  this.onChange({ detail: { value: index < 0 ? 0 : index } });
596
563
  } else if (e.detail?.clear === 'true') {
597
564
  this.onChange({ detail: { value: null } });
598
565
  }
599
- if (
600
- searchOption.length <= 0 &&
601
- (this.data.dataSourceName?.length > 0 ||
602
- isFormatNeedFetch(this.data.format))
603
- ) {
566
+ if (searchOption.length <= 0 && (this.data.dataSourceName?.length > 0 || isFormatNeedFetch(this.data.format))) {
604
567
  // this.setData({ isSearch: true });
605
568
  const param = [
606
569
  {
@@ -614,8 +577,7 @@ Component({
614
577
  },
615
578
  // 获取数据列表:关联关系和主子明细
616
579
  _fetchData: async function (param, pageNo, isUpdate = false) {
617
- const { dataSourceName, viewId, records, searchRecords } =
618
- this.properties;
580
+ const { dataSourceName, viewId, records, searchRecords } = this.properties;
619
581
 
620
582
  if (!dataSourceName) return;
621
583
  let pageSize = 50;
@@ -633,11 +595,9 @@ Component({
633
595
  console.log(results, param, 'Records');
634
596
  if (isUpdate && results && results.length > 0) {
635
597
  this.setData({
636
- chooseIndexLable:
637
- results[0][this.properties.primaryField] || results[0]._id,
598
+ chooseIndexLable: results[0][this.properties.primaryField] || results[0]._id,
638
599
  chooseIndexValue: results[0]._id,
639
- displayValue:
640
- results[0][this.properties.primaryField] || results[0]._id,
600
+ displayValue: results[0][this.properties.primaryField] || results[0]._id,
641
601
  });
642
602
  return;
643
603
  }
@@ -650,40 +610,28 @@ Component({
650
610
  const isSearch = this.data.isSearch;
651
611
  if (this.data.records.length === 0 && results?.length === 0) {
652
612
  // 当异常的时候,主要为了不引起records的observer变化变化设置默认值
653
- this.setData(
654
- isSearch ? { searchStatus: status } : { loadStatus: STATUS_CLOSED }
655
- );
613
+ this.setData(isSearch ? { searchStatus: status } : { loadStatus: STATUS_CLOSED });
656
614
  } else {
657
615
  this.setData(
658
616
  isSearch
659
617
  ? {
660
618
  searchRecords: searchRecords.concat(
661
- (results ?? []).filter(
662
- (item) =>
663
- searchRecords.findIndex((r) => r._id === item._id) < 0
664
- ) || []
619
+ (results ?? []).filter((item) => searchRecords.findIndex((r) => r._id === item._id) < 0) || [],
665
620
  ),
666
621
  records: records.concat(
667
- (results ?? []).filter(
668
- (item) => records.findIndex((r) => r._id === item._id) < 0
669
- ) || []
622
+ (results ?? []).filter((item) => records.findIndex((r) => r._id === item._id) < 0) || [],
670
623
  ),
671
624
  searchStatus: status,
672
625
  }
673
626
  : {
674
627
  searchRecords: searchRecords.concat(
675
- (results ?? []).filter(
676
- (item) =>
677
- searchRecords.findIndex((r) => r._id === item._id) < 0
678
- ) || []
628
+ (results ?? []).filter((item) => searchRecords.findIndex((r) => r._id === item._id) < 0) || [],
679
629
  ),
680
630
  records: records.concat(
681
- (results ?? []).filter(
682
- (item) => records.findIndex((r) => r._id === item._id) < 0
683
- ) || []
631
+ (results ?? []).filter((item) => records.findIndex((r) => r._id === item._id) < 0) || [],
684
632
  ),
685
633
  loadStatus: status,
686
- }
634
+ },
687
635
  );
688
636
  }
689
637
  },
@@ -700,9 +648,7 @@ Component({
700
648
  searchStatus: STATUS_LOADING,
701
649
  });
702
650
  }
703
- const param = [
704
- { [this.properties.primaryField]: { $search: searchValue } },
705
- ];
651
+ const param = [{ [this.properties.primaryField]: { $search: searchValue } }];
706
652
  this._fetchData(param, pageNo);
707
653
  } else {
708
654
  if (pageNo === 1) {
@@ -725,10 +671,7 @@ Component({
725
671
  const provinceValue = (defaultValue || defaultArea).split(',')[0];
726
672
  const changeData = await getRegionTree(defaultMutiRegion || '');
727
673
  //限制渲染时change事件触发,否则会有初始数据被覆盖问题
728
- if (
729
- changeData?.result.length > 0 &&
730
- !deepEqual(changeData.value, defaultMutiRegion)
731
- ) {
674
+ if (changeData?.result.length > 0 && !deepEqual(changeData.value, defaultMutiRegion)) {
732
675
  this.triggerEvent('change', changeData);
733
676
  }
734
677
  var provinceList = [...provinces];
@@ -864,8 +807,7 @@ Component({
864
807
  column // 处理不同的逻辑
865
808
  ) {
866
809
  case 0: // 第一列更改 就是省级的更改
867
- if (regionType != 'levelOne')
868
- this.getCity(this.data.provinceList[e.detail.value]); // 获取当前key下面的市级数据
810
+ if (regionType != 'levelOne') this.getCity(this.data.provinceList[e.detail.value]); // 获取当前key下面的市级数据
869
811
  data.multiIndex[1] = 0; // 将市默认选择第一个
870
812
  data.multiIndex[2] = 0; //第一列滚动时,市区默认选中第一个
871
813
  break;
@@ -903,26 +845,20 @@ Component({
903
845
  },
904
846
 
905
847
  onChange(e) {
906
- const { range, mode, separator, regionType, dateMode, format } =
907
- this.properties;
848
+ const { range, mode, separator, regionType, dateMode, format } = this.properties;
908
849
  let displayValue;
909
850
  switch (mode) {
910
851
  case 'selector': {
911
852
  if (!isFormatNeedFetch(format)) {
912
- const data =
913
- e.detail?.value != null
914
- ? range[e.detail.value]
915
- : { label: null, value: null };
916
- this.triggerEvent('change', data);
853
+ const data = e.detail?.value != null ? range[e.detail.value] : { label: null, value: null };
854
+ this.triggerEvent('change', { ...data, value: data.value, context: { option: data } });
917
855
  displayValue = data.label;
918
856
  } else {
919
857
  const { isSearch, searchOption, option } = this.data;
920
858
  const opt = isSearch ? searchOption : option;
921
- const data =
922
- e.detail?.value != null
923
- ? opt[e.detail.value]
924
- : { label: null, value: null };
925
- this.triggerEvent('change', data);
859
+ const data = e.detail?.value != null ? opt[e.detail.value] : { label: null, value: null };
860
+ this.triggerEvent('change', { ...data, value: data.value, context: { option: data } });
861
+
926
862
  displayValue = this.properties.displayValue;
927
863
  }
928
864
  break;
@@ -953,11 +889,7 @@ Component({
953
889
  step: 1,
954
890
  multiIndex: e.detail.value, // 更新下标字段
955
891
  });
956
- const value = buildDisplayValue(
957
- this.data.multiArray,
958
- this.data.multiIndex,
959
- regionType
960
- );
892
+ const value = buildDisplayValue(this.data.multiArray, this.data.multiIndex, regionType);
961
893
  displayValue = value?.value;
962
894
  this.triggerEvent('change', value);
963
895
  break;
@@ -221,10 +221,7 @@ Component({
221
221
  // 最终选择的选项
222
222
  onSelectPicker: function (e) {
223
223
  if (this.data.disabled === true) return;
224
- if (
225
- e.detail.clear === 'true' ||
226
- e.currentTarget.dataset.clear === 'true'
227
- ) {
224
+ if (e.detail.clear === 'true' || e.currentTarget.dataset.clear === 'true') {
228
225
  let options = this.properties.option.map((item) => ({
229
226
  ...item,
230
227
  check: false,
@@ -240,8 +237,10 @@ Component({
240
237
  }
241
238
  if (!e.detail.clear) {
242
239
  const value = e.detail.map((v) => v.value);
240
+ const options = e.detail.map((v) => ({ label: v.label, value: v.value, extra: { ...v } }));
241
+
243
242
  this.setData({ value });
244
- this.onChange({ detail: { value } });
243
+ this.onChange({ detail: { value, context: { options } } });
245
244
  }
246
245
  },
247
246
  onChange(e) {
@@ -253,11 +252,7 @@ Component({
253
252
  // eslint-disable-next-line rulesdir/no-timer
254
253
  this.data.fetchTimed = setTimeout(() => {
255
254
  const { format, dataSourceName, primaryField } = this.properties;
256
- if (
257
- ['many-many', 'one-many'].concat(format) &&
258
- dataSourceName &&
259
- primaryField
260
- ) {
255
+ if (['many-many', 'one-many'].concat(format) && dataSourceName && primaryField) {
261
256
  this.setData({ records: [], option: [], pageNo: 1 });
262
257
  this._fetchData(1, _where, true);
263
258
  }
@@ -321,9 +316,7 @@ Component({
321
316
  },
322
317
  _childFetchData: function (e) {
323
318
  const { pageNo, searchValue } = e.detail;
324
- const _where = searchValue
325
- ? [{ [this.properties.primaryField]: { $search: searchValue } }]
326
- : [];
319
+ const _where = searchValue ? [{ [this.properties.primaryField]: { $search: searchValue } }] : [];
327
320
  this._fetchData(pageNo, _where);
328
321
  },
329
322
  getLabels: function (values, options) {
@@ -357,9 +350,7 @@ Component({
357
350
  }
358
351
 
359
352
  // 接口搜索
360
- const _where = searchValue
361
- ? [{ [this.properties.primaryField]: { $search: searchValue } }]
362
- : [];
353
+ const _where = searchValue ? [{ [this.properties.primaryField]: { $search: searchValue } }] : [];
363
354
  this._initFetchData(_where);
364
355
  },
365
356
  },
@@ -407,22 +407,12 @@ export default Behavior({
407
407
  },
408
408
  // 通用: clear 动作
409
409
  handleClear: function () {
410
- const e = { detail: { value: null } };
410
+ const e = { detail: { value: null, context: {} } };
411
411
  this.handleChange(e);
412
412
  },
413
413
  // 通用: 输入类挂载 widgets
414
414
  updateWidgetAPI: function () {
415
- const {
416
- name,
417
- value,
418
- label,
419
- required,
420
- visible,
421
- disabled,
422
- readOnly,
423
- before,
424
- after,
425
- } = this.data;
415
+ const { name, value, label, required, visible, disabled, readOnly, before, after } = this.data;
426
416
  this.setReadonlyAttributes?.({
427
417
  name,
428
418
  value,
@@ -444,10 +434,7 @@ export default Behavior({
444
434
  },
445
435
  observers: {
446
436
  'clearable,disabled,value': function (clearable, disabled, value) {
447
- const truth =
448
- value != null &&
449
- value !== '' &&
450
- (!Array.isArray(value) || value.length !== 0);
437
+ const truth = value != null && value !== '' && (!Array.isArray(value) || value.length !== 0);
451
438
  const hasClearIcon = !!(clearable && !disabled && truth);
452
439
  this.setData({ hasClearIcon });
453
440
  },
@@ -3,7 +3,6 @@ import { WD_PREFIX } from '../../utils/constant';
3
3
 
4
4
  Component({
5
5
  options: {
6
- virtualHost: true,
7
6
  multipleSlots: true,
8
7
  },
9
8
  behaviors: [commonCompBehavior],
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.13.5",
6
+ "version": "3.13.6",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"