[前端] 修复PDF加载:直接用axios获取arraybuffer,绕过blob处理问题
This commit is contained in:
@@ -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>';
|
||||
|
||||
Reference in New Issue
Block a user