From cddfcdf68ff7fff6b1be82bc5edf822458de6749 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期四, 18 四月 2024 10:35:23 +0800
Subject: [PATCH] 商品档案全量导出修改

---
 src/main/webapp/static/js/mat/mat.js |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/main/webapp/static/js/mat/mat.js b/src/main/webapp/static/js/mat/mat.js
index 0fa6ccc..446c41c 100644
--- a/src/main/webapp/static/js/mat/mat.js
+++ b/src/main/webapp/static/js/mat/mat.js
@@ -167,18 +167,35 @@
                         url: baseUrl+"/mat/export/auth",
                         headers: {'token': localStorage.getItem('token')},
                         data: JSON.stringify(param),
-                        dataType:'json',
+                        // dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         method: 'POST',
+                        xhrFields: {
+                            responseType: "blob" // 璁剧疆鍝嶅簲绫诲瀷涓轰簩杩涘埗鏁版嵁
+                        },
                         success: function (res) {
+                            // 鍒涘缓涓�涓复鏃剁殑涓嬭浇閾炬帴
+                            const url = window.URL.createObjectURL(res);
+                            // 鍒涘缓涓�涓殣钘忕殑 <a> 鍏冪礌骞惰缃笅杞介摼鎺�
+                            const a = document.createElement("a");
+                            a.style.display = "none";
+                            a.href = url;
+                            a.download = "export.xlsx"; // 鎸囧畾涓嬭浇鐨勬枃浠跺悕
+                            document.body.appendChild(a);
+
+                            // 瑙﹀彂鐐瑰嚮浜嬩欢浠ュ紑濮嬩笅杞�
+                            a.click();
+
+                            // 娓呯悊涓存椂璧勬簮
+                            setTimeout(function () {
+                                window.URL.revokeObjectURL(url);
+                                document.body.removeChild(a);
+                                layer.closeAll();
+                            }, 100);
+                        },
+                        fail: function (){
+                            layer.msg('瀵煎嚭澶辫触', {icon: 2})
                             layer.closeAll();
-                            if (res.code === 200) {
-                                table.exportFile(titles,res.data,'xls');
-                            } else if (res.code === 403) {
-                                top.location.href = baseUrl+"/";
-                            } else {
-                                layer.msg(res.msg)
-                            }
                         }
                     });
                 });

--
Gitblit v1.9.1