From 9057e04efad1b7d61c77a72e5c37a504d0aee935 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 26 九月 2025 09:24:03 +0800
Subject: [PATCH] H5静态化

---
 admin/src/plugins/download.js |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/admin/src/plugins/download.js b/admin/src/plugins/download.js
new file mode 100644
index 0000000..b6ee316
--- /dev/null
+++ b/admin/src/plugins/download.js
@@ -0,0 +1,21 @@
+import fileDownload from 'js-file-download'
+import message from './message'
+
+export default function (response, decode = true, mime = 'application/octet-stream') {
+  // 褰撲笅杞芥帴鍙f病鏈夋垚鍔熻繑鍥炴祦骞朵笖鎺ュ彛杩斿洖鐨勬槸JSON鏃堕渶瑕佸鍝嶅簲娴佽繘琛岃В鏋愬苟鎻愮ず閿欒銆傦紙澶勭悊涓嬭浇鎺ュ彛鍑虹幇鏈煡寮傚父鐨勬儏鍐碉級
+  if (response.headers['content-type'] === 'application/json') {
+    const blob = new Blob([response.data])
+    const fileReader = new FileReader()
+    fileReader.readAsText(blob, 'utf-8')
+    fileReader.onload = function () {
+      message.apiFailed(JSON.parse(fileReader.result))
+    }
+    return
+  }
+  if (response.headers['content-length'] === '0') {
+    message.error('鏃犳硶涓嬭浇鏂囦欢锛屽彲鑳藉洜涓烘暟鎹鐞嗛敊璇鑷存枃浠跺ぇ灏忎负0B')
+    return
+  }
+  // 涓嬭浇鎺ュ彛鍦ㄥ搷搴斿ごdoumee-download-filename涓瓨鏀炬枃浠跺悕绉帮紝鎺ュ彛鐨勮繑鍥炵殑鏂囦欢鍚嶇О闇�閲囩敤url encode鐨勬柟寮忚繘琛岀紪鐮�
+  fileDownload(response.data, decode ? decodeURI(response.headers['doumee-download-filename']) : response.headers['doumee-download-filename'], mime)
+}

--
Gitblit v1.9.3