From 0bf3f3967322f09ec83051b93309866d2ef091c9 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 04 七月 2025 11:10:30 +0800
Subject: [PATCH] ss
---
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