|
@@ -1,22 +1,36 @@
|
|
|
import Common from './Common.js';
|
|
import Common from './Common.js';
|
|
|
-
|
|
|
|
|
|
|
+import Notify from './Notify.js';
|
|
|
/**
|
|
/**
|
|
|
* 报表下载服务
|
|
* 报表下载服务
|
|
|
*/
|
|
*/
|
|
|
export default {
|
|
export default {
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* GET 方式下载文件
|
|
* GET 方式下载文件
|
|
|
* @param {*} url
|
|
* @param {*} url
|
|
|
* @param {*} fileName
|
|
* @param {*} fileName
|
|
|
*/
|
|
*/
|
|
|
downloadFile: function (url, fileName) {
|
|
downloadFile: function (url, fileName) {
|
|
|
- var a = document.createElement('a');
|
|
|
|
|
- a.download = fileName;
|
|
|
|
|
- a.href = url;
|
|
|
|
|
- $('body').append(a); // 修复firefox中无法触发click
|
|
|
|
|
- a.click();
|
|
|
|
|
- $(a).remove();
|
|
|
|
|
|
|
+ fetch(url, {
|
|
|
|
|
+ method: 'GET',
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'token': localStorage.getItem('#token'),
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(res => res.blob())
|
|
|
|
|
+ .then(data => {
|
|
|
|
|
+ const blobUrl = window.URL.createObjectURL(data);
|
|
|
|
|
+
|
|
|
|
|
+ var a = document.createElement('a');
|
|
|
|
|
+ a.download = fileName;
|
|
|
|
|
+ a.href = blobUrl;
|
|
|
|
|
+ $('body').append(a); // 修复firefox中无法触发click
|
|
|
|
|
+ a.click();
|
|
|
|
|
+ $(a).remove();
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ Notify.error(err.code, err.responseText, true);
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|