优化评查详情中用户操作的更新刷新为热更新
This commit is contained in:
@@ -77,12 +77,9 @@ export async function loader() {
|
||||
|
||||
export default function Index() {
|
||||
const { homeData, recentFiles } = useLoaderData<typeof loader>();
|
||||
const [currentDateTime, setCurrentDateTime] = useState<{
|
||||
date: string;
|
||||
time: string;
|
||||
}>({
|
||||
date: dayjs().format('YYYY年MM月DD日'),
|
||||
time: dayjs().format('HH:mm:ss')
|
||||
const [currentDateTime, setCurrentDateTime] = useState({
|
||||
date: '',
|
||||
time: ''
|
||||
});
|
||||
|
||||
// 更新当前时间
|
||||
|
||||
+181
-100
@@ -46,6 +46,7 @@ import {
|
||||
import { type ReviewPoint } from '~/components/reviews';
|
||||
import { messageService } from "~/components/ui/MessageModal";
|
||||
import { loadingBarService } from "~/components/ui/LoadingBar";
|
||||
import { Breadcrumb } from "~/components/layout/Breadcrumb";
|
||||
|
||||
/**
|
||||
* 文件信息组件
|
||||
@@ -151,9 +152,7 @@ interface ReviewData {
|
||||
aiAnalysis: AnalysisData;
|
||||
}
|
||||
|
||||
interface LoaderData {
|
||||
previousRoute: string;
|
||||
}
|
||||
|
||||
export const meta: MetaFunction = () => {
|
||||
return [
|
||||
{ title: "评查详情 - 中国烟草AI合同及卷宗审核系统" },
|
||||
@@ -169,33 +168,9 @@ export function links() {
|
||||
}
|
||||
|
||||
export const handle = {
|
||||
breadcrumb: "评查详情",
|
||||
// 添加一个previousRoute属性用于支持自定义的面包屑导航
|
||||
previousRoute: (data:LoaderData)=>{
|
||||
if(data.previousRoute){
|
||||
if(data.previousRoute === 'filesUpload'){
|
||||
return {
|
||||
title: "文件上传",
|
||||
to: "/files/upload"
|
||||
}
|
||||
}
|
||||
if(data.previousRoute === 'documents'){
|
||||
return {
|
||||
title: "文档列表",
|
||||
to: "/documents"
|
||||
}
|
||||
}
|
||||
if(data.previousRoute === 'rulesFiles'){
|
||||
return {
|
||||
title: "评查文件列表",
|
||||
to: "/rules-files"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hideBreadcrumb: true
|
||||
};
|
||||
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
@@ -320,76 +295,76 @@ export default function ReviewDetails() {
|
||||
};
|
||||
|
||||
// 刷新评审数据
|
||||
async function refreshReviewData(documentId: string) {
|
||||
// 设置加载状态
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// 获取最新的评审数据
|
||||
const response = await getReviewPoints(documentId);
|
||||
// async function refreshReviewData(documentId: string) {
|
||||
// // 设置加载状态
|
||||
// setIsLoading(true);
|
||||
// try {
|
||||
// // 获取最新的评审数据
|
||||
// const response = await getReviewPoints(documentId);
|
||||
|
||||
if ('error' in response && response.error) {
|
||||
console.error('刷新评审数据失败:', response.error);
|
||||
alert(`刷新评审数据失败: ${response.error}`);
|
||||
return;
|
||||
}
|
||||
// if ('error' in response && response.error) {
|
||||
// console.error('刷新评审数据失败:', response.error);
|
||||
// toastService.error(`刷新评审数据失败: ${response.error}`);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 确保response有效且具有预期的属性
|
||||
if ('data' in response && 'stats' in response && 'reviewInfo' in response) {
|
||||
const reviewPointsData = response.data || [];
|
||||
const statisticsData = response.stats || { total: 0, success: 0, warning: 0, error: 0, score: 0 };
|
||||
const reviewInfoData = response.reviewInfo || {
|
||||
reviewTime: '',
|
||||
reviewModel: '',
|
||||
ruleGroup: '',
|
||||
result: '',
|
||||
issueCount: 0
|
||||
};
|
||||
// // 确保response有效且具有预期的属性
|
||||
// if ('data' in response && 'stats' in response && 'reviewInfo' in response) {
|
||||
// const reviewPointsData = response.data || [];
|
||||
// const statisticsData = response.stats || { total: 0, success: 0, warning: 0, error: 0, score: 0 };
|
||||
// const reviewInfoData = response.reviewInfo || {
|
||||
// reviewTime: '',
|
||||
// reviewModel: '',
|
||||
// ruleGroup: '',
|
||||
// result: '',
|
||||
// issueCount: 0
|
||||
// };
|
||||
|
||||
// 更新评审数据和统计信息
|
||||
setReviewData(prevData => {
|
||||
if (!prevData) {
|
||||
// 如果prevData为null,创建一个新的ReviewData对象
|
||||
return {
|
||||
fileInfo: {
|
||||
fileName: document?.name || "",
|
||||
contractNumber: document?.documentNumber || "",
|
||||
fileSize: document?.size ? formatFileSize(document.size) : "",
|
||||
fileFormat: document?.fileType ? document.fileType.toUpperCase() : "",
|
||||
pageCount: document?.pageCount || 0,
|
||||
uploadTime: document?.uploadTime || "",
|
||||
uploadUser: document?.uploadUser || "",
|
||||
auditStatus: document?.auditStatus || 0
|
||||
},
|
||||
contractInfo: getMockReviewData().contractInfo,
|
||||
reviewInfo: reviewInfoData as ReviewInfo,
|
||||
statistics: statisticsData as Statistics,
|
||||
fileContent: getMockReviewData().fileContent,
|
||||
reviewPoints: reviewPointsData as unknown as ReviewPoint[],
|
||||
aiAnalysis: getMockReviewData().aiAnalysis
|
||||
};
|
||||
}
|
||||
// // 更新评审数据和统计信息
|
||||
// setReviewData(prevData => {
|
||||
// if (!prevData) {
|
||||
// // 如果prevData为null,创建一个新的ReviewData对象
|
||||
// return {
|
||||
// fileInfo: {
|
||||
// fileName: document?.name || "",
|
||||
// contractNumber: document?.documentNumber || "",
|
||||
// fileSize: document?.size ? formatFileSize(document.size) : "",
|
||||
// fileFormat: document?.fileType ? document.fileType.toUpperCase() : "",
|
||||
// pageCount: document?.pageCount || 0,
|
||||
// uploadTime: document?.uploadTime || "",
|
||||
// uploadUser: document?.uploadUser || "",
|
||||
// auditStatus: document?.auditStatus || 0
|
||||
// },
|
||||
// contractInfo: getMockReviewData().contractInfo,
|
||||
// reviewInfo: reviewInfoData as ReviewInfo,
|
||||
// statistics: statisticsData as Statistics,
|
||||
// fileContent: getMockReviewData().fileContent,
|
||||
// reviewPoints: reviewPointsData as unknown as ReviewPoint[],
|
||||
// aiAnalysis: getMockReviewData().aiAnalysis
|
||||
// };
|
||||
// }
|
||||
|
||||
// 处理prevData非null的情况
|
||||
return {
|
||||
...prevData,
|
||||
reviewPoints: reviewPointsData as unknown as ReviewPoint[],
|
||||
statistics: statisticsData as Statistics,
|
||||
reviewInfo: reviewInfoData as ReviewInfo
|
||||
};
|
||||
});
|
||||
// // 处理prevData非null的情况
|
||||
// return {
|
||||
// ...prevData,
|
||||
// reviewPoints: reviewPointsData as unknown as ReviewPoint[],
|
||||
// statistics: statisticsData as Statistics,
|
||||
// reviewInfo: reviewInfoData as ReviewInfo
|
||||
// };
|
||||
// });
|
||||
|
||||
toastService.success('评审数据已更新');
|
||||
} else {
|
||||
console.error('返回的数据格式不正确');
|
||||
toastService.error('刷新评审数据失败: 返回的数据格式不正确');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('刷新评审数据失败:', error);
|
||||
toastService.error(`刷新评审数据失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
// toastService.success('评审数据已更新');
|
||||
// } else {
|
||||
// console.error('返回的数据格式不正确');
|
||||
// toastService.error('刷新评审数据失败: 返回的数据格式不正确');
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error('刷新评审数据失败:', error);
|
||||
// toastService.error(`刷新评审数据失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||
// } finally {
|
||||
// setIsLoading(false);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 处理评审点状态变更
|
||||
const handleReviewPointStatusChange = async (reviewPointResultId: string, editAuditStatusId: string | number, newStatus: string, message: string) => {
|
||||
@@ -417,25 +392,66 @@ export default function ReviewDetails() {
|
||||
|
||||
// 更新本地状态
|
||||
if (reviewData) {
|
||||
// 找到要更新的评查点和它的原始状态
|
||||
const reviewPointToUpdate = reviewData.reviewPoints.find(point => point.id === reviewPointResultId);
|
||||
const oldStatus = reviewPointToUpdate?.status || '';
|
||||
const wasSuccess = reviewPointToUpdate?.result === true;
|
||||
const newIsSuccess = newStatus === 'true';
|
||||
|
||||
// 更新评查点
|
||||
const updatedReviewPoints = reviewData.reviewPoints.map(point =>
|
||||
point.id === reviewPointResultId ? {
|
||||
...point,
|
||||
result: newStatus === 'true' ? true : (newStatus === 'false' ? false : point.result),
|
||||
message: message
|
||||
editAuditStatus: boolResult === 'review' ? 0 : 1,
|
||||
title: message
|
||||
} : point
|
||||
);
|
||||
|
||||
// 更新统计数据
|
||||
const updatedStatistics = { ...reviewData.statistics };
|
||||
|
||||
// 只处理结果实际变化的情况,即从通过变为不通过,或从不通过变为通过
|
||||
if (newStatus !== 'review' && wasSuccess !== newIsSuccess) {
|
||||
if (newIsSuccess) {
|
||||
// 从不通过变为通过
|
||||
updatedStatistics.success += 1;
|
||||
// 减少对应的错误或警告数量
|
||||
if (oldStatus === 'warning') {
|
||||
updatedStatistics.warning = Math.max(0, updatedStatistics.warning - 1);
|
||||
} else if (oldStatus === 'error') {
|
||||
updatedStatistics.error = Math.max(0, updatedStatistics.error - 1);
|
||||
}
|
||||
} else {
|
||||
// 从通过变为不通过
|
||||
updatedStatistics.success = Math.max(0, updatedStatistics.success - 1);
|
||||
// 增加对应的错误或警告数量
|
||||
if (oldStatus === 'warning') {
|
||||
updatedStatistics.warning += 1;
|
||||
} else if (oldStatus === 'error') {
|
||||
updatedStatistics.error += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新 UI 状态
|
||||
setReviewData({
|
||||
...reviewData,
|
||||
reviewPoints: updatedReviewPoints,
|
||||
// statistics: calculateStatistics(updatedReviewPoints)
|
||||
statistics: updatedStatistics
|
||||
});
|
||||
|
||||
// 从API获取最新数据刷新列表
|
||||
if (document && document.id && newStatus !== 'review') {
|
||||
await refreshReviewData(document.id.toString());
|
||||
// 显示成功消息
|
||||
if(document && document.id && newStatus !== 'review'){
|
||||
toastService.success('评查点状态已更新');
|
||||
}
|
||||
|
||||
console.log("newReviewPoints",updatedReviewPoints);
|
||||
|
||||
// 如果是review操作才调用API刷新
|
||||
// if (document && document.id && newStatus === 'review') {
|
||||
// await refreshReviewData(document.id.toString());
|
||||
// }
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('更新评查结果出错:', error);
|
||||
@@ -475,6 +491,26 @@ export default function ReviewDetails() {
|
||||
}
|
||||
};
|
||||
|
||||
// 构建自定义面包屑项
|
||||
const getBreadcrumbItems = () => {
|
||||
const items = [
|
||||
{ title: "评查详情", to: `/reviews?id=${document?.id}` }
|
||||
];
|
||||
|
||||
// 添加前置路由
|
||||
if (loaderData.previousRoute) {
|
||||
if (loaderData.previousRoute === 'filesUpload') {
|
||||
items.unshift({ title: "文件上传", to: "/files/upload" });
|
||||
} else if (loaderData.previousRoute === 'documents') {
|
||||
items.unshift({ title: "文档列表", to: "/documents" });
|
||||
} else if (loaderData.previousRoute === 'rulesFiles') {
|
||||
items.unshift({ title: "评查文件列表", to: "/rules-files" });
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
{isLoading ? (
|
||||
@@ -484,19 +520,64 @@ export default function ReviewDetails() {
|
||||
</div>
|
||||
) : reviewData && (
|
||||
<>
|
||||
{/* 自定义面包屑 */}
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
<Breadcrumb
|
||||
items={getBreadcrumbItems()}
|
||||
className="items-center flex !mb-0"
|
||||
/>
|
||||
|
||||
{/* 在面包屑右侧显示精简版的FileInfo */}
|
||||
<div className=" ml-10 text-left flex-1 flex flex-row flex-wrap">
|
||||
<span className="text-xl font-medium">
|
||||
{reviewData.fileInfo.fileName}
|
||||
</span>
|
||||
<div className="ml-2 text-xs text-gray-500 flex items-center">
|
||||
合同编号:{reviewData.fileInfo.contractNumber}
|
||||
{reviewData.fileInfo.fileSize && (
|
||||
<span className="text-xs text-gray-500 ml-2">
|
||||
| {reviewData.fileInfo.fileSize} | {reviewData.fileInfo.fileFormat} | {reviewData.fileInfo.pageCount}页
|
||||
</span>
|
||||
)}
|
||||
{reviewData.fileInfo.uploadTime && (
|
||||
<div className="text-xs text-gray-500">
|
||||
| 上传时间:{reviewData.fileInfo.uploadTime} | 上传用户:{reviewData.fileInfo.uploadUser}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="text-xs text-gray-500 flex items-center mb-1">
|
||||
合同编号:{reviewData.fileInfo.contractNumber}
|
||||
{reviewData.fileInfo.fileSize && (
|
||||
<span className="text-xs text-gray-500 ml-2">
|
||||
| {reviewData.fileInfo.fileSize} | {reviewData.fileInfo.fileFormat} | {reviewData.fileInfo.pageCount}页
|
||||
</span>
|
||||
)}
|
||||
{reviewData.fileInfo.uploadTime && (
|
||||
<div className="text-xs text-gray-500">
|
||||
| 上传时间:{reviewData.fileInfo.uploadTime} | 上传用户:{reviewData.fileInfo.uploadUser}
|
||||
</div>
|
||||
)}
|
||||
</div> */}
|
||||
|
||||
{/* 文件信息和操作按钮 */}
|
||||
<FileInfo
|
||||
{/* <FileInfo
|
||||
fileInfo={{
|
||||
...reviewData.fileInfo,
|
||||
previousRoute: loaderData.previousRoute
|
||||
}}
|
||||
onConfirmResults={handleConfirmResults}
|
||||
/>
|
||||
/> */}
|
||||
|
||||
{/* 选项卡 */}
|
||||
<ReviewTabs
|
||||
activeTab={activeTab}
|
||||
onTabChange={handleTabChange}
|
||||
fileInfo={{
|
||||
previousRoute: loaderData.previousRoute
|
||||
}}
|
||||
onConfirmResults={handleConfirmResults}
|
||||
>
|
||||
{/* 评查结果选项卡内容 */}
|
||||
{activeTab === 'preview' && (
|
||||
|
||||
Reference in New Issue
Block a user