@cloudbase/weda-ui-mp 3.12.0 → 3.12.2
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.
- package/components/listView/index.js +28 -82
- package/package.json +1 -1
- package/utils/getModelParams.js +7 -3
|
@@ -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
|
-
|
|
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
|
-
.
|
|
484
|
-
|
|
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
|
-
`${
|
|
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
|
-
`${
|
|
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
package/utils/getModelParams.js
CHANGED
|
@@ -71,9 +71,7 @@ const getSelectFields = async (props) => {
|
|
|
71
71
|
select[name] = true;
|
|
72
72
|
});
|
|
73
73
|
} else if (props.selectFieldType === 'custom') {
|
|
74
|
-
const _selectFields = Array.isArray(props.selectFields)
|
|
75
|
-
? props.selectFields
|
|
76
|
-
: [];
|
|
74
|
+
const _selectFields = Array.isArray(props.selectFields) ? props.selectFields : [];
|
|
77
75
|
_selectFields.forEach((name) => {
|
|
78
76
|
select[name] = true;
|
|
79
77
|
});
|
|
@@ -98,6 +96,12 @@ export const getModelParams = async (props) => {
|
|
|
98
96
|
// 支持多关联查询,需要将查询条件转换为filter
|
|
99
97
|
if (props?.queryCondition?.constructor === Object) {
|
|
100
98
|
params['filter'] = getFilter(props.queryCondition);
|
|
99
|
+
} else if (Array.isArray(props?.queryCondition)) {
|
|
100
|
+
params['filter'] = {
|
|
101
|
+
where: {
|
|
102
|
+
$and: props?.queryCondition,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
101
105
|
}
|
|
102
106
|
params.select = await getSelectFields(props);
|
|
103
107
|
// 处理排序字段
|