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