fix: 1. 修改dockerFile
2. 修复一些合同起草的刷新报错问题
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
*/
|
||||
|
||||
import type { ActionFunctionArgs, LoaderFunctionArgs, MetaFunction } from '@remix-run/node';
|
||||
import { useFetcher, useLoaderData, useNavigate } from '@remix-run/react';
|
||||
import { redirect } from '@remix-run/node';
|
||||
import { isRouteErrorResponse, useFetcher, useLoaderData, useNavigate, useParams, useRouteError } from '@remix-run/react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { downloadFile } from '~/api/axios-client';
|
||||
import type { ContractTemplate } from '~/api/contract-template/templates';
|
||||
@@ -56,12 +57,16 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
const templateId = url.searchParams.get('templateId');
|
||||
const title = url.searchParams.get('title');
|
||||
|
||||
if (!filePath) {
|
||||
throw new Response('文件路径参数缺失', { status: 400 });
|
||||
}
|
||||
// 如果参数缺失(可能是刷新导致),重定向到模板列表
|
||||
if (!filePath || !templateId) {
|
||||
console.log('[Loader] URL参数缺失,可能是刷新导致,重定向到模板列表');
|
||||
console.log('[Loader] filePath:', filePath, 'templateId:', templateId);
|
||||
|
||||
if (!templateId) {
|
||||
throw new Response('模板ID参数缺失', { status: 400 });
|
||||
// 如果有 templateId,重定向到模板详情页;否则重定向到模板列表
|
||||
if (templateId) {
|
||||
return redirect(`/contract-template/detail/${templateId}`);
|
||||
}
|
||||
return redirect('/contract-template');
|
||||
}
|
||||
|
||||
console.log('[Loader] 起草合同:', { filePath, templateId, title });
|
||||
@@ -94,7 +99,12 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
// console.log('[Loader] 生成的 schema:', JSON.stringify(placeholderSchema, null, 2));
|
||||
} catch (error) {
|
||||
console.error('[Loader] 提取占位符失败:', error);
|
||||
placeholderSchema = null;
|
||||
console.error('[Loader] 错误类型:', error instanceof Error ? 'Error' : typeof error);
|
||||
console.error('[Loader] 错误消息:', error instanceof Error ? error.message : String(error));
|
||||
|
||||
// 无论什么错误,都重定向回模板详情页(因为文件可能已被刷新删除)
|
||||
console.log('[Loader] 发生错误,重定向到模板详情页');
|
||||
return redirect(`/contract-template/detail/${templateId}`);
|
||||
}
|
||||
|
||||
// 创建模板对象
|
||||
@@ -254,20 +264,6 @@ export default function ContractDraftPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleBeforeUnload = () => {
|
||||
deleteFileSync();
|
||||
};
|
||||
|
||||
// 监听页面卸载事件
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
// 清理事件监听器
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
// 组件卸载时(路由切换),执行删除
|
||||
deleteFileSync();
|
||||
};
|
||||
}, [draft.file_path]);
|
||||
|
||||
// 单个替换占位符
|
||||
@@ -276,12 +272,14 @@ export default function ContractDraftPage() {
|
||||
console.log(`[Draft] 单个替换: ${placeholder} -> ${value}`);
|
||||
|
||||
// 设置 AI 建议替换参数,触发 FilePreview 中的静默替换
|
||||
// 添加唯一的时间戳,确保每次点击都会触发新的替换操作(即使值相同)
|
||||
setAiSuggestionReplace({
|
||||
searchText: placeholder,
|
||||
replaceText: value,
|
||||
pageNumber: 1, // 从第一页开始搜索
|
||||
silentReplace: true // 静默替换,不显示搜索替换面板
|
||||
});
|
||||
silentReplace: true, // 静默替换,不显示搜索替换面板
|
||||
timestamp: Date.now() // 添加时间戳,确保对象始终是新的
|
||||
} as any);
|
||||
|
||||
// 短暂延迟后清除参数,以便下次可以重新触发
|
||||
setTimeout(() => {
|
||||
@@ -368,8 +366,12 @@ export default function ContractDraftPage() {
|
||||
console.log('[Complete] 步骤3:下载文件');
|
||||
await handleExportDocument();
|
||||
|
||||
// 步骤4:删除 MinIO 文件
|
||||
console.log('[Complete] 步骤4:删除 MinIO 文件');
|
||||
// 步骤4:清除会话标记
|
||||
const sessionKey = `contract-draft-${draft.id}-loaded`;
|
||||
sessionStorage.removeItem(sessionKey);
|
||||
|
||||
// 步骤5:删除 MinIO 文件
|
||||
console.log('[Complete] 步骤5:删除 MinIO 文件');
|
||||
const formData = new FormData();
|
||||
formData.append('_action', 'deleteFile');
|
||||
formData.append('filePath', draft.file_path);
|
||||
@@ -393,6 +395,10 @@ export default function ContractDraftPage() {
|
||||
confirmText: '确定返回',
|
||||
cancelText: '取消',
|
||||
onConfirm: () => {
|
||||
// 清除会话标记
|
||||
const sessionKey = `contract-draft-${draft.id}-loaded`;
|
||||
sessionStorage.removeItem(sessionKey);
|
||||
|
||||
// 删除 MinIO 文件
|
||||
const formData = new FormData();
|
||||
formData.append('_action', 'deleteFile');
|
||||
@@ -427,6 +433,13 @@ export default function ContractDraftPage() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
{/* 刷新提醒 */}
|
||||
<div className="flex items-center gap-2 px-3 py-2 text-sm text-yellow-700 bg-yellow-50 border border-yellow-200 rounded-lg">
|
||||
<i className="ri-alert-line text-base"></i>
|
||||
<span>请勿刷新页面,否则临时文件将被删除</span>
|
||||
</div>
|
||||
|
||||
{/* 草稿状态标签 */}
|
||||
<span className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg bg-gradient-to-r from-blue-50 to-blue-100 text-blue-700 border border-blue-200 shadow-sm">
|
||||
<i className="ri-draft-line text-base"></i>
|
||||
<span>{draft.status === 'draft' ? '草稿' : draft.status === 'completed' ? '已完成' : '已归档'}</span>
|
||||
@@ -485,3 +498,36 @@ export default function ContractDraftPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误边界组件 - 处理页面加载错误时自动重定向
|
||||
*/
|
||||
export function ErrorBoundary() {
|
||||
const error = useRouteError();
|
||||
const params = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
console.error('[ErrorBoundary] 捕获到错误:', error);
|
||||
|
||||
// 自动重定向到模板详情页
|
||||
const templateId = new URLSearchParams(window.location.search).get('templateId');
|
||||
if (templateId) {
|
||||
console.log('[ErrorBoundary] 自动重定向到模板详情页:', templateId);
|
||||
// 使用 replace 避免返回到错误页面
|
||||
navigate(`/contract-template/detail/${templateId}`, { replace: true });
|
||||
} else {
|
||||
console.log('[ErrorBoundary] 无法获取 templateId,重定向到模板列表');
|
||||
navigate('/contract-template', { replace: true });
|
||||
}
|
||||
}, [error, navigate]);
|
||||
|
||||
// 显示一个简单的加载提示(用户几乎看不到,因为会立即重定向)
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
||||
<div className="text-center">
|
||||
<div className="text-gray-600">正在返回...</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user