|
|
@@ -462,77 +462,90 @@
|
|
462
|
462
|
const replaceResult = this.query.ordNo.replace(/[;,,;\s\r\n]+/g, ",").split(",");
|
|
463
|
463
|
this.query.ordNo = replaceResult;
|
|
464
|
464
|
},
|
|
465
|
|
- handleExport() {
|
|
466
|
|
- // 显示加载动画
|
|
|
465
|
+ async handleExport() {
|
|
467
|
466
|
this.exportLoading = true;
|
|
|
467
|
+ try {
|
|
|
468
|
+ const baseUrl = this.$store.state.app.serverName;
|
|
|
469
|
+ const url = baseUrl + 'WareStore/inExportStoreExcel.do';
|
|
|
470
|
+ const userId = localStorage.getItem("userId");
|
|
|
471
|
+ const belongId = localStorage.getItem("belongId");
|
|
|
472
|
+ const token = localStorage.getItem("token");
|
|
|
473
|
+ console.log(userId, belongId, token);
|
|
468
|
474
|
|
|
469
|
|
- var baseUrl = this.$store.state.app.serverName;
|
|
470
|
|
- var url = baseUrl + 'WareStore/inExportStoreExcel.do';
|
|
471
|
|
- let userId = localStorage.getItem("userId");
|
|
472
|
|
- let belongId = localStorage.getItem("belongId");
|
|
473
|
|
- let token = localStorage.getItem("token");
|
|
474
|
|
- console.log(userId, belongId, token);
|
|
475
|
|
- var param = {
|
|
476
|
|
- page: -1,
|
|
477
|
|
- rows: -1,
|
|
478
|
|
- wareName: this.query.wareName,
|
|
479
|
|
- stackName: this.query.stackName,
|
|
480
|
|
- model: this.query.model,
|
|
481
|
|
- materialName: this.query.materialName,
|
|
482
|
|
- standard: this.query.standard,
|
|
483
|
|
- customerName: this.query.customerName,
|
|
484
|
|
- plateNo: this.query.plateNo.length == 0 ? '' : this.query.plateNo.join(','),
|
|
485
|
|
- fromDate:(!this.query.inRecordDate[0]) ? "1970-01-01 00:00:00" : this.query.inRecordDate[0].Format("yyyy-MM-dd HH:mm:ss"), //date类型
|
|
486
|
|
- toDate :(!this.query.inRecordDate[1]) ? new Date().Format("yyyy-MM-dd HH:mm:ss") :this.query.inRecordDate[1].Format("yyyy-MM-dd HH:mm:ss"),
|
|
487
|
|
- ordNo: this.query.ordNo == 0 ? '' : this.query.ordNo.join(','),
|
|
488
|
|
- carNo : this.query.carNo,
|
|
489
|
|
- tallyPeople:this.query.tallyPeople,
|
|
490
|
|
- fkComponyName:this.query.fkComponyName,
|
|
491
|
|
- remark1:this.query.remark1,
|
|
492
|
|
- contractNo:this.query.contractNo.length == 0 ? '' : this.query.contractNo.join(','),
|
|
493
|
|
- userId: userId,
|
|
494
|
|
- belongId: belongId
|
|
495
|
|
- }
|
|
|
475
|
+ // 组装导出参数(直接放body,不再拼接URL)
|
|
|
476
|
+ const param = {
|
|
|
477
|
+ page: -1,
|
|
|
478
|
+ rows: -1,
|
|
|
479
|
+ wareName: this.query.wareName,
|
|
|
480
|
+ stackName: this.query.stackName,
|
|
|
481
|
+ model: this.query.model,
|
|
|
482
|
+ materialName: this.query.materialName,
|
|
|
483
|
+ standard: this.query.standard,
|
|
|
484
|
+ customerName: this.query.customerName,
|
|
|
485
|
+ plateNo: this.query.plateNo.length == 0 ? '' : this.query.plateNo.join(','),
|
|
|
486
|
+ fromDate: (!this.query.inRecordDate[0]) ? "1970-01-01 00:00:00" : this.query.inRecordDate[0].Format("yyyy-MM-dd HH:mm:ss"),
|
|
|
487
|
+ toDate: (!this.query.inRecordDate[1]) ? new Date().Format("yyyy-MM-dd HH:mm:ss") : this.query.inRecordDate[1].Format("yyyy-MM-dd HH:mm:ss"),
|
|
|
488
|
+ ordNo: this.query.ordNo == 0 ? '' : this.query.ordNo.join(','),
|
|
|
489
|
+ carNo: this.query.carNo,
|
|
|
490
|
+ tallyPeople: this.query.tallyPeople,
|
|
|
491
|
+ fkComponyName: this.query.fkComponyName,
|
|
|
492
|
+ remark1: this.query.remark1,
|
|
|
493
|
+ contractNo: this.query.contractNo.length == 0 ? '' : this.query.contractNo.join(','),
|
|
|
494
|
+ userId: userId,
|
|
|
495
|
+ belongId: belongId
|
|
|
496
|
+ };
|
|
496
|
497
|
|
|
497
|
|
- var params = [];
|
|
498
|
|
- // 去掉 if(param\[key\]) 判断,空字符串也要传递给后端
|
|
499
|
|
- for (var key in param) {
|
|
500
|
|
- params.push(key + '=' + encodeURIComponent(param[key]));
|
|
501
|
|
- }
|
|
502
|
|
- var fullUrl = url + (params.length > 0 ? '?' + params.join('&') : '');
|
|
|
498
|
+ // POST请求,携带token鉴权头,60秒超时
|
|
|
499
|
+ const controller = new AbortController();
|
|
|
500
|
+ const timeoutId = setTimeout(() => controller.abort(), 600000); // 10分钟超时
|
|
|
501
|
+
|
|
|
502
|
+ const response = await fetch(url, {
|
|
|
503
|
+ method: 'POST',
|
|
|
504
|
+ headers: {
|
|
|
505
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
506
|
+ 'token': token // 带上登录凭证,和列表查询接口保持一致
|
|
|
507
|
+ },
|
|
|
508
|
+ body: new URLSearchParams(param), // 参数放入请求体,不再拼URL
|
|
|
509
|
+ signal: controller.signal
|
|
|
510
|
+ });
|
|
|
511
|
+ clearTimeout(timeoutId);
|
|
503
|
512
|
|
|
504
|
|
- // 使用 fetch + blob 方式,下载完成后关闭 loading
|
|
505
|
|
- fetch(fullUrl)
|
|
506
|
|
- .then(response => {
|
|
507
|
513
|
if (!response.ok) {
|
|
508
|
|
- throw new Error('网络请求失败');
|
|
|
514
|
+ throw new Error(`服务异常,状态码:${response.status}`);
|
|
|
515
|
+ }
|
|
|
516
|
+ const blob = await response.blob();
|
|
|
517
|
+ // 判断后端是否返回错误提示(非Excel二进制)
|
|
|
518
|
+ if (blob.type.includes('text')) {
|
|
|
519
|
+ const text = await blob.text();
|
|
|
520
|
+ throw new Error(text || '导出数据查询失败,请缩小筛选时间范围');
|
|
509
|
521
|
}
|
|
510
|
|
- return response.blob();
|
|
511
|
|
- })
|
|
512
|
|
- .then(blob => {
|
|
513
|
|
- // 创建下载链接
|
|
514
|
|
- const url = window.URL.createObjectURL(blob);
|
|
|
522
|
+
|
|
|
523
|
+ // 下载文件逻辑不变
|
|
|
524
|
+ const blobUrl = window.URL.createObjectURL(blob);
|
|
515
|
525
|
const link = document.createElement('a');
|
|
516
|
|
- link.href = url;
|
|
|
526
|
+ link.href = blobUrl;
|
|
517
|
527
|
link.download = '入库记录_' + new Date().toISOString().slice(0, 10) + '.xlsx';
|
|
518
|
528
|
document.body.appendChild(link);
|
|
519
|
529
|
link.click();
|
|
520
|
|
- // 浏览器开始下载后立即关闭 loading
|
|
521
|
|
- this.exportLoading = false;
|
|
522
|
|
- // 清理
|
|
523
|
530
|
setTimeout(() => {
|
|
524
|
531
|
document.body.removeChild(link);
|
|
525
|
|
- window.URL.revokeObjectURL(url);
|
|
|
532
|
+ window.URL.revokeObjectURL(blobUrl);
|
|
526
|
533
|
}, 100);
|
|
527
|
|
- })
|
|
528
|
|
- .catch(error => {
|
|
|
534
|
+ this.$message.success('导出成功');
|
|
|
535
|
+ } catch (error) {
|
|
529
|
536
|
console.error('导出失败:', error);
|
|
530
|
|
- this.$message.error('导出失败:' + error.message);
|
|
|
537
|
+ // 超时单独提示
|
|
|
538
|
+ if (error.name === 'AbortError') {
|
|
|
539
|
+ this.$message.error('导出超时:数据量过大,请缩短查询时间区间');
|
|
|
540
|
+ } else {
|
|
|
541
|
+ this.$message.error('导出失败:' + error.message);
|
|
|
542
|
+ }
|
|
|
543
|
+ } finally {
|
|
531
|
544
|
this.exportLoading = false;
|
|
532
|
|
- });
|
|
|
545
|
+ }
|
|
|
546
|
+ },
|
|
533
|
547
|
|
|
534
|
|
- },
|
|
535
|
|
- exportExcel(imptData) {
|
|
|
548
|
+ exportExcel(imptData) {
|
|
536
|
549
|
// alert(JSON.stringify(imptData))
|
|
537
|
550
|
const header = ["仓库名称"
|
|
538
|
551
|
,"垛位"
|