Commit 9e8886d0 authored by wangqinghua's avatar wangqinghua

兼容IE下载

parent 03b2a2f8
import {Injectable, OnInit} from "@angular/core";
import {NzModalService} from 'ng-zorro-antd';
import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {SERVER_API_URL, SERVER_API_URL_COMS} from '../../app.constants';
import {DatePipe} from '@angular/common';
@Injectable()
export class CommonService implements OnInit {
constructor(private modalSer:NzModalService,private datePipe:DatePipe) {
constructor(private modalSer:NzModalService,private datePipe:DatePipe,
private message:NzMessageService) {
// 定义发射事件
}
......@@ -98,16 +99,31 @@ export class CommonService implements OnInit {
* 下载文件
* @param url 文件URL
*/
downloadFile(title,data: Response) {
const blob = new Blob([data], {type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"});
const url= window.URL.createObjectURL(blob);
let link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", title);
downloadFile(title, data: Response) {
const blob = new Blob([data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;'});
const ie = navigator.userAgent.match(/MSIE\s([\d.]+)/),
ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/),
ieEDGE = navigator.userAgent.match(/Edge/g),
ieVer = (ie ? ie[1] : (ie11 ? 11 : (ieEDGE ? 12 : -1)));
console.log('ie:' + ie);
console.log('ieVer:' + ieVer);
if (ie && ieVer < 10) {
this.message.error('No blobs on IE<10');
return;
}
if (ieVer > -1) {
window.navigator.msSaveBlob(blob, title);
} else {
const url = window.URL.createObjectURL(blob);
let link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', title);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
/**
* 部分区域全屏
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment