请求方法必须 config.responseType = 'arraybuffer';
download (orderId) {
const vm = this;
this.$axios.get('/pay/getOrderByOrderId', { params: { orderId: orderId } }).then((data) => {
if (data.code == 500 || data.code == 401) {
util.setSession('page', '/lt');
util.removeCookie('__USER_INFO');
this.$router.push({ path: '/overTime', replace: true });
}
const url = window.URL.createObjectURL(new Blob([data]));
const link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute(
'download',
'招标数据' + vm.Format('yyyy-MM-dd hh:mm:ss', new Date()) + '.xls'
);
document.body.appendChild(link);
link.click();
vm.$message.success('下载完成');
});
},
Format (fmt, datatime) {
var o = {
'M+': datatime.getMonth() + 1,
'd+': datatime.getDate(),
'h+': datatime.getHours(),
'm+': datatime.getMinutes(),
's+': datatime.getSeconds(),
'q+': Math.floor((datatime.getMonth() + 3) / 3)
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
(datatime.getFullYear() + '').substr(4 - RegExp.$1.length)
);
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length == 1
? o[k]
: ('00' + o[k]).substr(('' + o[k]).length)
);
}
}
return fmt;
},