|
|
@@ -204,6 +204,7 @@ import { ref, onMounted, onUnmounted } from "vue";
|
|
|
import { useRouter } from "vue-router";
|
|
|
import { apis } from "@/request/apis.js";
|
|
|
import { BACKEND_API_PREFIX } from "@/utils/apiConfig";
|
|
|
+import { getToken } from "@/utils/auth";
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
@@ -395,20 +396,30 @@ const downloadPolicy = async (file) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 最简单的下载方式
|
|
|
-const downloadFileViaBackend = (fileUrl, fileName) => {
|
|
|
+// 带鉴权的下载方式
|
|
|
+const downloadFileViaBackend = async (fileUrl, fileName) => {
|
|
|
const downloadUrl = `${BACKEND_API_PREFIX}/download_file?pdf_oss_download_link=${encodeURIComponent(
|
|
|
fileUrl
|
|
|
)}&file_name=${encodeURIComponent(fileName)}`;
|
|
|
|
|
|
- // 创建隐藏的a标签进行下载
|
|
|
+ const token = getToken();
|
|
|
+ const headers = {};
|
|
|
+ if (token) {
|
|
|
+ headers['Authorization'] = `Bearer ${token}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ const response = await fetch(downloadUrl, { headers });
|
|
|
+ const blob = await response.blob();
|
|
|
+ const blobUrl = URL.createObjectURL(blob);
|
|
|
+
|
|
|
const a = document.createElement("a");
|
|
|
- a.href = downloadUrl;
|
|
|
+ a.href = blobUrl;
|
|
|
a.download = fileName || "download_file";
|
|
|
a.style.display = "none";
|
|
|
document.body.appendChild(a);
|
|
|
a.click();
|
|
|
document.body.removeChild(a);
|
|
|
+ URL.revokeObjectURL(blobUrl);
|
|
|
};
|
|
|
// 导入文件类型图标
|
|
|
import pdfIcon from "@/assets/Policy/2.png";
|