codeRun(code: string): void {
if (!this.viewState.source || !this.viewState.source.id) return;
this.toolbarState.loading.run = true;
this.toolbarState.enable.stop = true;
this.viewTableState.loading = true;
const param: ViewTestExecute = {
sourceId: this.viewState.source.id,
scriptType: 'SQL',
size: this.toolbarState.limit.value,
script: code,
variables: [],
columns: [],
countTotal: true
};
this.dataProviderService
.execute(param)
.pipe(
catchError(exception => {
this.toolbarState.loading.run = false;
this.toolbarState.enable.stop = false;
this.viewTableState.loading = false;
throw exception;
})
)
.pipe(takeUntil(this.destroy$))
.subscribe((result: QueryResult) => {
this.viewState.execute = param
this.toolbarState.loading.run = false;
this.toolbarState.enable = {run: true, stop: false, save: true, setting: false, copy: false};
this.viewTableState = {...result, loading: false};
});
}
如上面这段代码,因为页面的标签例如 <spin [spining]='xxxloading'></spin>这样,有一个加载状态,但是用
this.loading = true
this.http.get().subscribe(xx=>this.loading=false)
这种改变 loading 状态的代码,感觉弄得我代码很不干净,有没有什么方法能尽量让改变页面状态代码精简些,让我的代码干净些