feat:完成Collabora初步集成(返回顶部、文档页数获取)
This commit is contained in:
@@ -6,6 +6,7 @@ import { useState, useEffect, useRef, ChangeEvent } from 'react';
|
||||
import { Document, Page, pdfjs } from 'react-pdf';
|
||||
import { DOCUMENT_URL } from '~/api/axios-client';
|
||||
import { CollaboraViewer, type CollaboraViewerHandle } from '~/components/collabora/CollaboraViewer';
|
||||
import { requestPageInfo } from '~/components/collabora/lib/pageInfo';
|
||||
|
||||
// 设置worker路径为public目录下的worker文件
|
||||
// 使用已经下载的兼容版本 (pdfjs-dist v2.12.313)
|
||||
@@ -96,6 +97,49 @@ export function FilePreview({ fileContent, activeReviewPointResultId, targetPage
|
||||
const isDocx = fileExtension === 'docx';
|
||||
const isPdf = fileExtension === 'pdf';
|
||||
|
||||
// DOCX 页数获取: 使用 requestPageInfo 方法
|
||||
useEffect(() => {
|
||||
if (!isDocx) return;
|
||||
|
||||
// console.log('[FilePreview] DOCX 文档加载,尝试获取页数');
|
||||
|
||||
let intervalCleared = false;
|
||||
|
||||
// 等待 CollaboraViewer 准备就绪
|
||||
const checkInterval = setInterval(() => {
|
||||
if (intervalCleared) return;
|
||||
|
||||
if (!collaboraViewerRef.current?.isReady) {
|
||||
console.log('[FilePreview] 等待 Collabora 就绪...');
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log('[FilePreview] Collabora 已就绪,尝试获取页数');
|
||||
clearInterval(checkInterval);
|
||||
intervalCleared = true;
|
||||
|
||||
const iframeWindow = collaboraViewerRef.current.getIframeWindow?.();
|
||||
if (!iframeWindow) {
|
||||
console.warn('[FilePreview] 无法获取 iframe window');
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用 requestPageInfo 获取页数
|
||||
requestPageInfo(iframeWindow)
|
||||
.then((info) => {
|
||||
setNumPages(info.totalPages);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn('[FilePreview] 获取 DOCX 页数失败:', error.message);
|
||||
});
|
||||
}, 500);
|
||||
|
||||
// 清理定时器
|
||||
return () => {
|
||||
clearInterval(checkInterval);
|
||||
};
|
||||
}, [isDocx]);
|
||||
|
||||
// 拖拽状态管理
|
||||
const [dragMode, setDragMode] = useState(false); // 是否处于拖拽模式
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
|
||||
Reference in New Issue
Block a user