From f112e2c62b6fca7b115dd37e34dc19dbcbc91d15 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 07 三月 2025 14:52:41 +0800
Subject: [PATCH] 样式优化
---
src/plugins/download.js | 42 +++++++++++++++++++++++++++++-------------
1 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/src/plugins/download.js b/src/plugins/download.js
index c0c1878..36db93e 100644
--- a/src/plugins/download.js
+++ b/src/plugins/download.js
@@ -4,6 +4,7 @@
import { getToken } from "@/utils/auth";
import errorCode from "@/utils/errorCode";
import { blobValidate } from "@/utils/ruoyi";
+import Vue from "vue";
const baseURL = process.env.VUE_APP_BASE_API;
let downloadLoadingInstance;
@@ -80,22 +81,37 @@
downloadLoadingInstance.close();
});
},
+ async downloadFileFromUrl(url, filename) {
+ try {
+ let state = /\.(jpg|jpeg|png|gif)$/i.test(url) // 鍒ゆ柇鏄惁涓哄浘鐗�
+ let url1 = ''
+ if (state) {
+ url1 = Vue.prototype.javaApi + '/img/' + url;
+ } else {
+ url1 = Vue.prototype.javaApi + '/word/' + url
+ }
+ // 浣跨敤 fetch 鑾峰彇鏂囦欢
+ const response = await fetch(url1);
+ if (!response.ok) {
+ throw new Error('鏂囦欢涓嬭浇澶辫触: ' + response.statusText);
+ }
+ // 灏嗘枃浠惰浆鎹负 Blob
+ const blob = await response.blob();
+ // 浣跨敤 saveAs 淇濆瓨鏂囦欢
+ saveAs(blob, filename);
+ Message.success("鏁版嵁瀵煎嚭鎴愬姛");
+ } catch (error) {
+ Message.error(error);
+ }
+ },
saveAs(text, name, opts) {
- if (typeof text === "string") {
- // 璺緞涓嬭浇
+ // 娴佷笅杞�
+ blobToText(text).then((result) => {
+ Message.error(result.msg);
+ }).catch(() => {
saveAs(text, name, opts);
Message.success("鏁版嵁瀵煎嚭鎴愬姛");
- } else {
- // 娴佷笅杞�
- blobToText(text)
- .then((result) => {
- Message.error(result.msg);
- })
- .catch(() => {
- saveAs(text, name, opts);
- Message.success("鏁版嵁瀵煎嚭鎴愬姛");
- });
- }
+ });
},
async printErrMsg(data) {
const resText = await data.text();
--
Gitblit v1.9.3