fix: 1.接入ai_suggestion.

2. 接入合同起草功能。
This commit is contained in:
2025-12-05 00:04:45 +08:00
parent eca98fc540
commit 33f10896a0
29 changed files with 3184 additions and 981 deletions
@@ -13,7 +13,7 @@
*/
import React, { useState, useRef, useEffect } from "react";
import { DiffEditor } from "@monaco-editor/react";
import { DiffEditor, loader } from "@monaco-editor/react";
import type { editor } from "monaco-editor";
import { pdfjs } from 'react-pdf';
import mammoth from 'mammoth';
@@ -23,6 +23,33 @@ import { DOCUMENT_URL } from '~/config/api-config';
// Setup PDF.js worker
pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.js';
// 配置 Monaco Editor 使用本地资源(避免 CDN 加载超时)
// Monaco Editor 资源已通过 npm run copy-monaco 复制到 public/monaco-editor
if (typeof window !== 'undefined') {
console.log('[Monaco] 使用本地资源加载');
loader.config({
paths: {
vs: '/monaco-editor/vs'
}
});
// 添加加载超时监控和错误处理
const initTimeout = setTimeout(() => {
console.error('[Monaco] 加载超时(30秒)');
toastService.error('代码编辑器加载超时,请刷新页面重试');
}, 30000);
loader.init().then(() => {
clearTimeout(initTimeout);
console.log('[Monaco] ✅ 加载成功');
}).catch((error: Error) => {
clearTimeout(initTimeout);
console.error('[Monaco] ❌ 加载失败:', error);
toastService.error(`代码编辑器加载失败: ${error.message}`);
});
}
// Document type enum
type DocumentType = 'pdf' | 'docx' | 'unknown';
@@ -600,7 +627,7 @@ export function ComparePreview({ doc1Path, doc2Path }: ComparePreviewProps): JSX
<strong></strong>
<span style={{ marginLeft: '8px' }}>
<span style={{ color: '#dc3545', fontWeight: 'bold' }}></span> |
<span style={{ color: '#28a745', fontWeight: 'bold', marginLeft: '8px' }}>绿</span> |
<span style={{ color: '#28a745', fontWeight: 'bold', marginLeft: '8px' }}>绿</span> |
<span style={{ color: '#666', fontWeight: 'bold', marginLeft: '8px' }}></span>
</span>
</div>
@@ -389,7 +389,7 @@ export function PdfPreview({
>
<i className="ri-zoom-out-line text-sm"></i>
</button>
{/* 页码跳转控件 */}
{/* 页码跳转控件
<div className="inline-flex items-center flex-shrink-0 gap-1">
<input
type="text"
@@ -412,7 +412,38 @@ export function PdfPreview({
/ {numPages}
</span>
)}
</div> */}
{/* 页码跳转控件 */}
<div className="inline-flex items-center bg-white border border-gray-300 rounded-lg shadow-sm hover:shadow-md transition-shadow duration-200 flex-shrink-0 overflow-hidden">
<div className="flex items-center px-2 py-1">
<i className="ri-file-list-line text-sm text-gray-400 mr-1.5"></i>
<input
type="text"
className="w-10 h-5 px-1 text-xs text-center text-gray-700 bg-transparent border-0 outline-none focus:text-primary transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed"
placeholder="页码"
value={pageInputValue}
onChange={handlePageInputChange}
onKeyDown={handlePageInputKeyDown}
/>
{numPages && (
<span className="text-xs text-gray-400 mx-0.5">/</span>
)}
{numPages && (
<span className="text-xs text-gray-500 font-medium min-w-[1.5rem] text-center">
{numPages}
</span>
)}
</div>
<button
className="flex items-center justify-center h-7 px-2.5 text-white bg-primary hover:bg-primary-hover transition-colors duration-200 outline-none disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-primary border-l border-primary-hover/20"
onClick={handlePageJump}
disabled={!numPages}
title="跳转"
>
<i className="ri-skip-forward-mini-line text-sm"></i>
</button>
</div>
<span className="text-xs text-gray-500 hidden sm:hidden md:hidden lg:hidden xl:inline whitespace-nowrap flex-shrink-0">
{zoomLevel}%
</span>