修复下载,更改logo,优化评查详情内容的显示,修改sidebar的首页,修复文件上传合同的异步上传时序问题,首页最近文件的自动更新文件状态
This commit is contained in:
+60
-3
@@ -76,7 +76,9 @@ export async function loader() {
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
const { homeData, recentFiles } = useLoaderData<typeof loader>();
|
||||
const { homeData, recentFiles: initialRecentFiles } = useLoaderData<typeof loader>();
|
||||
// 使用useState存储最近文档数据,初始值为loader加载的数据
|
||||
const [recentFiles, setRecentFiles] = useState<DocumentUI[]>(initialRecentFiles || []);
|
||||
const [currentDateTime, setCurrentDateTime] = useState({
|
||||
date: '',
|
||||
time: ''
|
||||
@@ -102,16 +104,71 @@ export default function Index() {
|
||||
// 清理函数,组件卸载时清除计时器
|
||||
return () => clearInterval(timerID);
|
||||
}, []);
|
||||
|
||||
|
||||
// 修改useEffect定时器,每10秒自动获取最近文档数据
|
||||
// 按照定时器更新最近文档
|
||||
useEffect(() => {
|
||||
// 定义一个函数用于获取最新的文档数据
|
||||
const fetchLatestDocuments = async () => {
|
||||
try {
|
||||
const documentSearchParams = {
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
order: 'updated_at.desc'
|
||||
};
|
||||
|
||||
console.log('定时获取最新文档数据...');
|
||||
const responseDocuments = await getDocuments(documentSearchParams);
|
||||
|
||||
if (responseDocuments.error) {
|
||||
console.error('获取最近文档数据失败', responseDocuments.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取新的文档数据
|
||||
const newRecentFiles = responseDocuments.data?.documents || [];
|
||||
|
||||
// 检查数据是否有变化
|
||||
if (JSON.stringify(newRecentFiles) !== JSON.stringify(recentFiles)) {
|
||||
console.log('文档数据已更新,直接更新状态');
|
||||
// 直接更新状态,不需要刷新页面
|
||||
setRecentFiles(newRecentFiles);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('自动获取文档数据失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 设置10秒的定时器
|
||||
const timerID = setInterval(fetchLatestDocuments, 10000);
|
||||
|
||||
// 组件卸载时清除定时器
|
||||
return () => {
|
||||
console.log('清除文档数据自动更新定时器');
|
||||
clearInterval(timerID);
|
||||
};
|
||||
}, []); // 不再依赖recentFiles,避免循环依赖
|
||||
|
||||
return (
|
||||
<div className="dashboard-container">
|
||||
{/* 页面头部 */}
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h2 className="text-xl font-medium">系统概览</h2>
|
||||
<div className="text-sm text-gray-500">
|
||||
<div className="text-sm text-gray-500 flex flex-row items-center justify-between">
|
||||
<div className="flex items-center">
|
||||
<span id="current-date">{currentDateTime.date}</span>
|
||||
<span className="mx-2">|</span>
|
||||
<span id="current-time">{currentDateTime.time}</span>
|
||||
</div>
|
||||
<div className="user-profile p-4 border-b border-gray-100 flex items-center">
|
||||
<div className="avatar w-10 h-10 rounded-full bg-primary text-white flex items-center justify-center">
|
||||
<span>管</span>
|
||||
</div>
|
||||
<div className="ml-3">
|
||||
<p className="text-sm font-medium">系统管理员</p>
|
||||
<p className="text-xs text-gray-500">超级管理员</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user