|
1 | 1 | import { GuiFields } from '@acrodata/gui'; |
2 | 2 | import { ChangeDetectorRef, EventEmitter, inject } from '@angular/core'; |
3 | | -import { defaults, isEmpty } from 'lodash-es'; |
| 3 | +import { defaults, isArray, isEmpty, isPlainObject } from 'lodash-es'; |
4 | 4 | import { |
5 | 5 | VisualActions, |
6 | 6 | VisualApis, |
@@ -198,15 +198,22 @@ export class VisualComponent { |
198 | 198 |
|
199 | 199 | /** |
200 | 200 | * 请求数据 |
201 | | - * @param data |
202 | | - * @description config 数据源配置 |
203 | | - * @description options 组件配置项 |
| 201 | + * @param params 请求参数 |
204 | 202 | */ |
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) |
210 | 217 | .then(res => this.requestSucceeded.emit(res)) |
211 | 218 | .catch(err => this.requestFailed.emit(err)); |
212 | 219 | } |
|
0 commit comments