11import { GuiFields } from '@acrodata/gui' ;
22import { ChangeDetectorRef , EventEmitter , inject } from '@angular/core' ;
3- import { defaults , isEmpty , merge } from 'lodash-es' ;
3+ import { defaults , isEmpty } from 'lodash-es' ;
44import {
55 VisualActions ,
66 VisualApis ,
@@ -10,7 +10,7 @@ import {
1010 VisualEvents ,
1111 VisualInteractions ,
1212} from './interfaces' ;
13- import { getOptionsFromConfig , mergeDataSource } from './utils' ;
13+ import { getOptionsFromConfig , mergeDataSource , mergeObject } from './utils' ;
1414
1515export class VisualComponent {
1616 constructor ( configs ?: Record < string , any > ) {
@@ -157,6 +157,12 @@ export class VisualComponent {
157157 * @param newOptions
158158 */
159159 updateOptions ( newOptions : Record < string , any > ) {
160+ if ( ! isEmpty ( newOptions ) && this . options != newOptions ) {
161+ mergeObject ( this . options , newOptions ) ;
162+ }
163+ if ( ! isEmpty ( this . apis ) ) {
164+ this . render ( this . responseData . source , this . options ) ;
165+ }
160166 this . detectChanges ( ) ;
161167 }
162168
@@ -165,7 +171,7 @@ export class VisualComponent {
165171 * @param newAttr
166172 */
167173 updateAttr ( newAttr : VisualAttr ) {
168- merge ( this . attr , newAttr ) ;
174+ mergeObject ( this . attr , newAttr ) ;
169175 this . detectChanges ( ) ;
170176 }
171177
@@ -197,8 +203,9 @@ export class VisualComponent {
197203 * @description options 组件配置项
198204 */
199205 requestData ( data : { config ?: any ; options ?: any } ) {
206+ // TODO: data 重新设计,object 表示传一个参数,array 表示传多个参数
200207 mergeDataSource ( this . dataConfig ?. [ 'source' ] ?. dataSource , data . config || { } ) ;
201- merge ( this . options , data . options || { } ) ;
208+ mergeObject ( this . options , data . options || { } ) ;
202209 this . request ( this . dataConfig [ 'source' ] . dataSource )
203210 . then ( res => this . requestSucceeded . emit ( res ) )
204211 . catch ( err => this . requestFailed . emit ( err ) ) ;
0 commit comments