Skip to content

Commit 512e718

Browse files
committed
refactor: improve requestData params
1 parent 2e217bd commit 512e718

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/visual-component.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GuiFields } from '@acrodata/gui';
22
import { ChangeDetectorRef, EventEmitter, inject } from '@angular/core';
3-
import { defaults, isEmpty } from 'lodash-es';
3+
import { defaults, isArray, isEmpty, isPlainObject } from 'lodash-es';
44
import {
55
VisualActions,
66
VisualApis,
@@ -198,15 +198,22 @@ export class VisualComponent {
198198

199199
/**
200200
* 请求数据
201-
* @param data
202-
* @description config 数据源配置
203-
* @description options 组件配置项
201+
* @param params 请求参数
204202
*/
205-
requestData(data: { config?: any; options?: any }) {
206-
// TODO: data 重新设计,object 表示传一个参数,array 表示传多个参数
207-
mergeDataSource(this.dataConfig?.['source']?.dataSource, data.config || {});
208-
mergeObject(this.options, data.options || {});
209-
this.request(this.dataConfig['source'].dataSource)
203+
requestData(params: Record<string, any> | any[]) {
204+
let dataSrc = {};
205+
let opts = {};
206+
if (isPlainObject(params)) {
207+
dataSrc = params;
208+
} else if (isArray(params)) {
209+
dataSrc = isPlainObject(params[0]) ? params[0] : {};
210+
opts = isPlainObject(params[1]) ? params[1] : {};
211+
}
212+
213+
mergeDataSource(this.dataConfig['source']?.dataSource, dataSrc);
214+
mergeObject(this.options, opts);
215+
216+
this.request(this.dataConfig['source']?.dataSource)
210217
.then(res => this.requestSucceeded.emit(res))
211218
.catch(err => this.requestFailed.emit(err));
212219
}

0 commit comments

Comments
 (0)