|
|
|
import { model, Model } from '@core/core';
|
|
|
|
import { ApiFactory } from '../../..//crud/apiFactory';
|
|
|
|
import { AppModel } from '../../../app.model';
|
|
|
|
const api = new ApiFactory().create();
|
|
|
|
export const ConnectionListModelXtype = 'dec.dcm.model.connection.list';
|
|
|
|
@model(ConnectionListModelXtype)
|
|
|
|
export class ConnectionListModel extends Model<{
|
|
|
|
context : {
|
|
|
|
connections: AppModel['$$childContext']['connections'];
|
|
|
|
connectionSelected: AppModel['$$childContext']['connectionSelected'];
|
|
|
|
}
|
|
|
|
}> {
|
|
|
|
context = ['connections', 'connectionSelected'];
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
setConnections: ():Promise<void> => api.getConnectionlist().then(data => {
|
|
|
|
if (BI.size(data.data) > 0) {
|
|
|
|
this.model.connections = data.data;
|
|
|
|
this.model.connections.forEach(item => {
|
|
|
|
// 后端传过来的是字符串,转为对象
|
|
|
|
item.connectionData = JSON.parse(item.connectionData as string);
|
|
|
|
});
|
|
|
|
this.model.connectionSelected = data.data[0].connectionName;
|
|
|
|
} else {
|
|
|
|
this.model.connectionSelected = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|