This commit is contained in:
cwchen 2024-11-11 15:39:24 +08:00
parent 1919489d48
commit e5d389c397
4 changed files with 38 additions and 6 deletions

View File

@ -262,7 +262,7 @@ function exportExcel() {
'module': $('#module').val(),
'proId': objParam.proId,
'id': id,
'curryDay':time
'curryDay': time
}
let url = dataUrl + "backstage/export/exportPcList";
exportExcelUtil(url, '发货详情-批次-' + time, JSON.stringify(params));
@ -330,7 +330,7 @@ function viewFile(obj) {
{
"alt": "layer",
"pid": 1,
"src": "../../../images/captcha.jpg",
"src": fileUrl + obj.fileUrl + '?token=' + sessionStorage.getItem("gz-token"),
}
]
}
@ -340,5 +340,10 @@ function viewFile(obj) {
// 下载文件
function downLoadFile(obj) {
alert('下载');
console.log(obj);
let params = {
'fileId': obj.id,
}
let url = dataUrl + "backstage/export/download";
downLoadFileUtil(url, obj.fileName, JSON.stringify(params));
}

View File

@ -189,7 +189,7 @@ function exportExcel() {
'module': $('#module').val(),
type: 1
}
let url = dataUrl + "backstage/export/exportFhList";
let url = dataUrl + "backstage/export/exportWarnExcel";
exportExcelUtil(url, '超库存量', JSON.stringify(params));
}

View File

@ -177,7 +177,7 @@ function exportExcel() {
'module': $('#module').val(),
type: 2
}
let url = dataUrl + "backstage/export/exportFhList";
let url = dataUrl + "backstage/export/exportWarnExcel";
exportExcelUtil(url, '计划外量', JSON.stringify(params));
}

View File

@ -1,4 +1,5 @@
const dataUrl = 'http://127.0.0.1:21995/';
const dataUrl = 'http://127.0.0.1:21995/'; // 数据请求路径
const fileUrl = 'http://127.0.0.1:21995/'; // 文件路径
@ -82,6 +83,32 @@ function exportExcelUtil(url, fileName,params) {
xhr.send(params);
}
// 下载文件的公共方法
function downLoadFileUtil(url, fileName,params) {
let loadingMsg = layer.msg("数据导出中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
let xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8')
xhr.setRequestHeader("authorization", sessionStorage.getItem("gz-token"));
xhr.onload = function () {
layer.close(loadingMsg);
if (this.status === 200) {
let blob = this.response;
var a = document.createElement("a");
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName + ".xlsx"; // 文件名
} else {
layer.msg("数据发生异常,请稍后重试", { icon: 16, scrollbar: false, time: 2000 });
}
a.click();
window.URL.revokeObjectURL(url);
};
xhr.send(params);
}
// 格式化日对象
const getNowDate = () => {
var date = new Date();