导出功能实现及接口对接

This commit is contained in:
zhouyuejun
2019-03-01 14:12:10 +08:00
parent e1c7a28376
commit e6a9b2ea62
2 changed files with 50 additions and 9 deletions
+38 -8
View File
@@ -37,8 +37,8 @@ export class MainComponent implements OnInit {
this.toastService.getToasts().forEach((config: ToastConfig) => { this.toastService.getToasts().forEach((config: ToastConfig) => {
console.log(config); console.log(config);
this.toastConfigs.unshift(config); this.toastConfigs.unshift(config);
}); });
this.toastService.removeToastMainSubject.subscribe((config?: ToastConfig) => { this.toastService.removeToastMainSubject.subscribe((config?: ToastConfig) => {
if (config) { if (config) {
this.remove(config); this.remove(config);
} else { } else {
@@ -51,7 +51,7 @@ export class MainComponent implements OnInit {
).subscribe( ).subscribe(
(event: NavigationEnd) => { (event: NavigationEnd) => {
if (event.urlAfterRedirects != '/app/main') { if (event.urlAfterRedirects != '/app/main') {
if(this.websocketService.websocket.readyState === 1){ if (this.websocketService.websocket.readyState === 1) {
this.websocketService.websocket.close(); this.websocketService.websocket.close();
} }
} }
@@ -127,7 +127,7 @@ export class MainComponent implements OnInit {
'Australian walks 100km after outback crash.', 'Australian walks 100km after outback crash.',
'Man charged over missing wedding girl.', 'Man charged over missing wedding girl.',
'Los Angeles battles huge wildfires.' 'Los Angeles battles huge wildfires.'
]; ];
ngOnInit() { ngOnInit() {
window.onresize = function () { window.onresize = function () {
@@ -431,8 +431,8 @@ export class MainComponent implements OnInit {
export() { export() {
let exportArray = []; let exportArray = [];
this.wait_render_data.forEach(item => { this.wait_render_data.forEach(item => {
let exportItem = Object.assign({},item) let exportItem = Object.assign({}, item)
if (this.orderHandle.isLinked(exportItem)||this.orderHandle.isArriFlight(exportItem)) { if (this.orderHandle.isLinked(exportItem) || this.orderHandle.isArriFlight(exportItem)) {
exportItem['renderFlight']['orderBy'] = new Date(this.utils.dateFormatter(exportItem['preFlight']['SODT'])).getTime(); exportItem['renderFlight']['orderBy'] = new Date(this.utils.dateFormatter(exportItem['preFlight']['SODT'])).getTime();
} else { } else {
exportItem['renderFlight']['orderBy'] = new Date(this.utils.dateFormatter(exportItem['reaFlight']['SODT'])).getTime() exportItem['renderFlight']['orderBy'] = new Date(this.utils.dateFormatter(exportItem['reaFlight']['SODT'])).getTime()
@@ -444,7 +444,37 @@ export class MainComponent implements OnInit {
return (a['orderBy'] - b['orderBy']); return (a['orderBy'] - b['orderBy']);
}) })
console.log(exportArray); let colArray = [];
this.render_col_lists.forEach(element => {
let column = { 'key': element['COL_CODE'], "name": element['COL_CN'] }
colArray.push(column);
})
var postData = new Object();
postData['columns'] = colArray;
postData['data'] = exportArray;
this.httpCilent.post('/adminapi/fltrs/toExcel', postData, { responseType: 'blob' }).subscribe(
data => {
let blob = new Blob();
blob = data;
let downloadFileName = '航班动态.xlsx';
if ('msSaveOrOpenBlob' in navigator) {
window.navigator.msSaveOrOpenBlob(blob, downloadFileName);
}
else {
var downloadElement = document.createElement('a');
var href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = downloadFileName; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
}
}
)
} }
/** /**
@@ -1519,7 +1549,7 @@ export class MainComponent implements OnInit {
/** /**
* 清除所有消息弹出框 * 清除所有消息弹出框
*/ */
clearAllNotify(){ clearAllNotify() {
this.toastConfigs = []; this.toastConfigs = [];
this.toastService.removeToastBox(); this.toastService.removeToastBox();
} }
+12 -1
View File
@@ -98,7 +98,18 @@ export class HttpClientService {
* @param options * @param options
*/ */
post(url: string, body?, options?): Observable<any> { post(url: string, body?, options?): Observable<any> {
return this.commonProcess(this.httpClient.post(url, body, { headers: this.header })); let optObj = {
headers: this.header
}
if (options) {
for (const key in options) {
if (options.hasOwnProperty(key)) {
// const element = options[key];
optObj[key] = options[key]
}
}
}
return this.commonProcess(this.httpClient.post(url, body, optObj));
} }
/** /**