[前端+RAG] 恢复同步上传修复导读生成;用Uint8Array存PDF字节修复detached;CSS覆盖PDF阅读模式空白
This commit is contained in:
@@ -283,7 +283,14 @@ provide('selectedFile', selectedFile);
|
||||
const docHtml = ref('');
|
||||
const fileContent = ref(null);
|
||||
const readingBox = ref(null);
|
||||
const pdfData = ref<ArrayBuffer | null>(null);
|
||||
const pdfBytes = ref<Uint8Array | null>(null); // 存原始字节,不会被 detach
|
||||
const pdfData = computed(() => {
|
||||
// 每次访问时复制一份新的 ArrayBuffer 给 PdfViewer
|
||||
if (!pdfBytes.value) return null;
|
||||
const copy = new ArrayBuffer(pdfBytes.value.byteLength);
|
||||
new Uint8Array(copy).set(pdfBytes.value);
|
||||
return copy;
|
||||
});
|
||||
const readingMode = ref(false);
|
||||
const fileType = computed(() => {
|
||||
const name = selectedFile.value?.fileName || '';
|
||||
@@ -447,7 +454,7 @@ const handleNodeClick = async (data: any) => {
|
||||
if (ext === 'pdf') {
|
||||
await loadPdfFile();
|
||||
} else {
|
||||
pdfData.value = null;
|
||||
pdfBytes.value = null;
|
||||
await loadFileContent();
|
||||
}
|
||||
};
|
||||
@@ -460,13 +467,9 @@ const loadPdfFile = async () => {
|
||||
params: { fileId: selectedFile.value.fileId },
|
||||
responseType: 'arraybuffer'
|
||||
});
|
||||
// 复制 ArrayBuffer 避免被 Vue 响应式代理导致 detached
|
||||
const src = resp.data as ArrayBuffer;
|
||||
const copy = new ArrayBuffer(src.byteLength);
|
||||
new Uint8Array(copy).set(new Uint8Array(src));
|
||||
pdfData.value = copy;
|
||||
pdfBytes.value = new Uint8Array(resp.data as ArrayBuffer);
|
||||
} catch (e: any) {
|
||||
pdfData.value = null;
|
||||
pdfBytes.value = null;
|
||||
docHtml.value = '<p style="color:#999;text-align:center;margin-top:40px;">PDF 文件加载失败</p>';
|
||||
}
|
||||
// 同时加载 HTML 用于笔记功能(后台)
|
||||
@@ -911,6 +914,9 @@ onMounted(async () => {
|
||||
flex: 1; overflow: auto; position: relative; padding: 0;
|
||||
.view-md {
|
||||
padding: 20px;
|
||||
// 覆盖 PyMuPDF get_text("html") 输出的固定宽度
|
||||
:deep(div[style*="width:"]) { width: 100% !important; max-width: 100% !important; }
|
||||
:deep(.pdf-page > div) { width: 100% !important; }
|
||||
:deep(p) { font-size: 15px; line-height: 1.8rem; margin-block-start: 0; }
|
||||
:deep(.highlight) { background: #D0EAC8; }
|
||||
:deep(.note-flag) { width: 23px; height: 28px; line-height: 28px; display: inline-block; text-align: center; font-weight: bold; font-size: 10px; margin-left: 8px; cursor: pointer; background: url("@/assets/images/reading/note.png"); color: #004EA0; background-size: contain !important; background-repeat: no-repeat !important; background-position: center bottom !important; }
|
||||
|
||||
Reference in New Issue
Block a user