[前端] 修复PDF加载:直接用axios获取arraybuffer,绕过blob处理问题

This commit is contained in:
2026-04-02 13:39:45 +08:00
parent f273643011
commit 0e25154468

View File

@@ -217,6 +217,7 @@ import Loading from "@/components/Loading.vue";
import {UploadFilled} from '@element-plus/icons-vue';
import {ElMessage, ElMessageBox, type UploadFile, type UploadFiles} from "element-plus";
import Mark from "mark.js";
import axios from '@/utils/request/axios';
// ===================== 面板尺寸与折叠 =====================
const leftWidth = ref(280);
@@ -437,10 +438,11 @@ const loadPdfFile = async () => {
if (!selectedFile.value) return;
docHtml.value = '';
try {
const resp = await downloadFile({ fileId: selectedFile.value.fileId });
const blob = new Blob([resp]);
const arrayBuffer = await blob.arrayBuffer();
pdfData.value = arrayBuffer;
const resp = await axios.get('/gpt/file/downloadFile', {
params: { fileId: selectedFile.value.fileId },
responseType: 'arraybuffer'
});
pdfData.value = resp.data;
} catch (e: any) {
pdfData.value = null;
docHtml.value = '<p style="color:#999;text-align:center;margin-top:40px;">PDF 文件加载失败</p>';