@@ -13,7 +13,7 @@ import {
1313import { mergeDataSource } from './utils' ;
1414
1515export class VisualComponent {
16- constructor ( configs ?: Record < string , any > , cdr ?: ChangeDetectorRef ) {
16+ constructor ( configs ?: Record < string , any > ) {
1717 if ( configs ) {
1818 this . attr = { ...configs [ 'attr' ] } ;
1919 this . config = { ...configs [ 'config' ] } ;
@@ -48,11 +48,9 @@ export class VisualComponent {
4848 } ;
4949 }
5050 }
51-
52- cdr && ( this . _cdr = cdr ) ;
5351 }
5452
55- _cdr = inject ( ChangeDetectorRef ) ;
53+ changeDetectorRef = inject ( ChangeDetectorRef ) ;
5654
5755 /** 组件 ID */
5856 id = '' ;
@@ -98,13 +96,13 @@ export class VisualComponent {
9896 apis : VisualApis = { } ;
9997
10098 /** 静态数据 */
101- data : Record < string , any [ ] > = { } ;
99+ data : { [ k : string ] : any [ ] | undefined ; source ?: any [ ] } = { } ;
102100
103101 /** 数据源配置 */
104102 dataConfig : Record < string , VisualDataConfig > = { } ;
105103
106104 /** 请求响应数据 */
107- responseData : Record < string , any [ ] > = { } ;
105+ responseData : { [ k : string ] : any [ ] | undefined ; source ?: any [ ] } = { } ;
108106
109107 /** 资源路径 */
110108 resources : Record < string , any > = { } ;
@@ -124,19 +122,19 @@ export class VisualComponent {
124122 /** 显示 */
125123 show ( ) {
126124 this . isHide = false ;
127- this . _cdr ?. detectChanges ( ) ;
125+ this . detectChanges ( ) ;
128126 }
129127
130128 /** 隐藏 */
131129 hide ( ) {
132130 this . isHide = true ;
133- this . _cdr ?. detectChanges ( ) ;
131+ this . detectChanges ( ) ;
134132 }
135133
136134 /** 切换显隐状态 */
137135 toggleHide ( ) {
138136 this . isHide = ! this . isHide ;
139- this . _cdr ?. detectChanges ( ) ;
137+ this . detectChanges ( ) ;
140138 }
141139
142140 /** 组件初始化钩子函数 */
@@ -151,15 +149,15 @@ export class VisualComponent {
151149 * @param options
152150 */
153151 render ( data : any , options ?: Record < string , any > ) {
154- this . _cdr ?. detectChanges ( ) ;
152+ this . detectChanges ( ) ;
155153 }
156154
157155 /**
158156 * 组件配置更新钩子函数
159157 * @param newOptions
160158 */
161159 updateOptions ( newOptions : Record < string , any > ) {
162- this . _cdr ?. detectChanges ( ) ;
160+ this . detectChanges ( ) ;
163161 }
164162
165163 /**
@@ -168,7 +166,7 @@ export class VisualComponent {
168166 */
169167 updateAttr ( newAttr : VisualAttr ) {
170168 merge ( this . attr , newAttr ) ;
171- this . _cdr ?. detectChanges ( ) ;
169+ this . detectChanges ( ) ;
172170 }
173171
174172 /**
@@ -177,7 +175,7 @@ export class VisualComponent {
177175 * @param height
178176 */
179177 resize ( width : number , height : number ) {
180- this . _cdr ?. detectChanges ( ) ;
178+ this . detectChanges ( ) ;
181179 }
182180
183181 /**
@@ -205,4 +203,9 @@ export class VisualComponent {
205203 . then ( res => this . requestSucceeded . emit ( res ) )
206204 . catch ( err => this . requestFailed . emit ( err ) ) ;
207205 }
206+
207+ /** 触发变更检测 */
208+ detectChanges ( ) {
209+ this . changeDetectorRef . detectChanges ( ) ;
210+ }
208211}
0 commit comments