/*
|
* @Author: 小明丶
|
* @Date: 2019-10-25 10:17:56
|
* @LastEditors: zhaoxiaoqiang 287285524@qq.com
|
* @LastEditTime: 2023-07-28 16:27:12
|
* @Description:
|
*/
|
/**
|
* 作者:c.k
|
* 文件说明:
|
* Creeated by c.k on 2018/2/7
|
*
|
*/
|
import dateForm from './date'
|
|
export default {
|
/**
|
* excel 文件下载参数配置
|
* @param data 参数
|
* @param apiuURL 访问地址
|
* @returns {[null,null]}
|
*/
|
configDate: function(res, parFilename, from) {
|
console.log(res)
|
// console.log(parFilename)
|
let fileNamet =/\.{1}[A-Za-z]{1,}$/.exec(res.headers['content-disposition'])
|
let blob = new Blob([res.data], {
|
type: 'application/vnd.ms-excel'
|
});
|
let fileName = '';
|
let prefix = fileNamet[0];
|
if(parFilename==undefined&& from !== 'overDay'){
|
fileName = dateForm(new Date(), 'YYYY-MM-DD') + prefix;
|
}
|
if (parFilename != undefined && from !== 'overDay') {
|
fileName = parFilename + '_' + dateForm(new Date(), 'YYYYMMDDHHssmm') + prefix;
|
}
|
if (parFilename != undefined && from === 'overDay') {
|
fileName = `${parFilename}_${dateForm((dateForm(new Date()) - 24*60*60*1000), 'YYYYMMDD')}${prefix}`
|
console.log(fileName)
|
}
|
// let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];
|
function downFile(blob, fileName) {
|
if (window.navigator.msSaveOrOpenBlob) {
|
navigator.msSaveBlob(blob, fileName);
|
console.log(1)
|
} else {
|
console.log(2)
|
// let objectUrl = URL.createObjectURL(blob);
|
// window.location.href = objectUrl;
|
let link = document.createElement('a');
|
link.href = window.URL.createObjectURL(blob);
|
link.download = fileName;
|
// appendChild这个是为了解决火狐浏览器下载的兼容问题,火狐必须append到html中
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
window.URL.revokeObjectURL(link.href);
|
}
|
}
|
|
downFile(blob, fileName);
|
},
|
configDate2: function(res, parFilename, from) {
|
console.log(res);
|
// let fileNamet =/\.{1}[A-Za-z]{1,}$/.exec(res.headers['content-disposition']);
|
let blob = new Blob([res.data], {type: 'application/vnd.ms-excel'});
|
let fileName = parFilename?parFilename:"";
|
function downFile(blob, fileName) {
|
// console.log(blob)
|
if (window.navigator.msSaveOrOpenBlob) {
|
navigator.msSaveBlob(blob, fileName);
|
} else {
|
// let objectUrl = URL.createObjectURL(blob);
|
// window.location.href = objectUrl;
|
let link = document.createElement('a');
|
link.href = window.URL.createObjectURL(blob);
|
link.download = fileName;
|
// appendChild这个是为了解决火狐浏览器下载的兼容问题,火狐必须append到html中
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
window.URL.revokeObjectURL(link.href);
|
}
|
}
|
|
downFile(blob, fileName);
|
},
|
configDate3: function(res, parFilename, from) {
|
console.log(parFilename,123123)
|
let blob = new Blob([res], {
|
type: 'application/zip'
|
});
|
let fileName = '';
|
let prefix = '.zip';
|
if (parFilename != undefined && from !== 'overDay') {
|
fileName = parFilename + '_' + dateForm(new Date(), 'YYYYMMDDHHssmm') + prefix;
|
}
|
if (parFilename != undefined && from === 'overDay') {
|
fileName = `${parFilename}_${dateForm((dateForm(new Date()) - 24*60*60*1000), 'YYYYMMDD')}${prefix}`
|
console.log(fileName)
|
}
|
// let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];
|
function downFile(blob, fileName) {
|
if (window.navigator.msSaveOrOpenBlob) {
|
navigator.msSaveBlob(blob, fileName);
|
console.log(1)
|
} else {
|
console.log(2)
|
// let objectUrl = URL.createObjectURL(blob);
|
// window.location.href = objectUrl;
|
let link = document.createElement('a');
|
link.href = window.URL.createObjectURL(blob);
|
link.download = fileName;
|
// appendChild这个是为了解决火狐浏览器下载的兼容问题,火狐必须append到html中
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
window.URL.revokeObjectURL(link.href);
|
}
|
}
|
|
downFile(blob, fileName);
|
},
|
downexcelModel:function(url,name) {
|
var a = document.createElement("a"); //页面上创建一个标签
|
var str = process.env.NODE_ENV == "development" ? "t.finlean.com" : window.location.host
|
a.style.display = "none";
|
a.setAttribute("href",`https://${str}${url}`);
|
a.setAttribute("download", name); //设置a 标签的download 属性,并限定下载文件名。
|
a.click(); //出发a点击事件,下载文件
|
}
|
}
|