feat:完成通过自定义Collabora插件实现页面跳转

This commit is contained in:
PingChuan
2025-11-25 14:38:54 +08:00
parent d40e5b261c
commit a475000df5
10 changed files with 205 additions and 147 deletions
+14 -5
View File
@@ -6,7 +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';
import { requestPageInfo, customGotoPage } from '~/components/collabora/lib';
// 导入react-pdf的CSS样式(文本层和注释层必需)
import 'react-pdf/dist/esm/Page/TextLayer.css';
@@ -317,19 +317,28 @@ export function FilePreview({ fileContent, activeReviewPointResultId, targetPage
};
// 处理页码跳转
const handlePageJump = () => {
const handlePageJump = async () => {
if (!pageInputValue) return;
const targetPageNum = parseInt(pageInputValue, 10);
if (isDocx) {
// DOCX 文件:调用 Collabora UNO 命令
if (!collaboraViewerRef.current?.isReady) {
// DOCX 文件:调用自定义页面跳转
const iframeWindow = collaboraViewerRef.current?.getIframeWindow?.();
if (!iframeWindow) {
toastService.warning('文档尚未加载完成,请稍候...');
return;
}
if (targetPageNum > 0) {
collaboraViewerRef.current?.unoCommands.gotoPage(targetPageNum);
try {
await customGotoPage(iframeWindow, targetPageNum);
// 跳转成功,清空输入框
setPageInputValue('');
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
toastService.error(`跳转失败: ${errorMessage}`);
}
} else {
toastService.warning('请输入有效页码');
setPageInputValue('');