This commit is contained in:
DESKTOP-PB0N82B\admin 2026-01-15 16:57:15 +08:00
parent 90a7fbd0b0
commit 725409a24b
2 changed files with 30 additions and 20 deletions

View File

@ -127,7 +127,7 @@ export const giteaApi = {
page, page,
limit limit
}, },
timeout: 30000 // 处理缓慢的 git 操作 timeout: 60000 // 处理缓慢的 git 操作
}); });
return response.data; return response.data;
} catch (error) { } catch (error) {

View File

@ -1,7 +1,6 @@
import { useState, useEffect, useCallback, useMemo } from 'react' import { useState, useEffect, useCallback, useMemo } from 'react'
import { import {
Folder, Folder,
RefreshCw,
Plus, Plus,
FileCode, FileCode,
FileText, FileText,
@ -73,7 +72,7 @@ interface TreeItem {
} }
export default function ProjectLibrary() { export default function ProjectLibrary() {
const { success, error: showError } = useToast() const { toast, success, error: showError } = useToast()
const { startDownload } = useDownloadManager() const { startDownload } = useDownloadManager()
// 使用缓存Hook获取仓库列表 // 使用缓存Hook获取仓库列表
@ -81,9 +80,7 @@ export default function ProjectLibrary() {
const cacheConfig = useMemo(() => ({ namespace: 'projects' }), []) const cacheConfig = useMemo(() => ({ namespace: 'projects' }), [])
const { const {
data: repos, data: repos
loading: repoLoading,
refresh: refreshRepos
} = useCache<GiteaRepository[]>( } = useCache<GiteaRepository[]>(
'project-library-repos', // 缓存键 'project-library-repos', // 缓存键
fetchRepos, // 数据获取函数 fetchRepos, // 数据获取函数
@ -212,15 +209,20 @@ export default function ProjectLibrary() {
return return
} }
console.log('调用API获取提交记录') console.log(`调用API获取提交记录: owner=${selectedRepo.owner.username}, repo=${selectedRepo.name}`)
const data = await giteaApi.getRepoCommits(selectedRepo.owner.username, selectedRepo.name, 1, 5) const data = await giteaApi.getRepoCommits(selectedRepo.owner.username, selectedRepo.name, 1, 20)
setCommits(data) setCommits(data)
// 缓存提交记录 // 缓存提交记录
await cacheUtils.setJSON(cacheKey, data, { namespace: 'projects', maxAge: 1000 * 60 * 5 }) // 5分钟缓存 await cacheUtils.setJSON(cacheKey, data, { namespace: 'projects', maxAge: 1000 * 60 * 5 }) // 5分钟缓存
} catch (error) { } catch (error: any) {
console.error("Failed to fetch commits:", error) console.error("Failed to fetch commits:", error)
setCommits([]) setCommits([])
// 如果是超时错误,给用户明确提示
if (error.code === 'ECONNABORTED' || error.message?.includes('timeout')) {
toast(`获取提交记录超时 (60s),请检查网络或稍后重试`, { type: 'error' })
}
} finally { } finally {
setCommitsLoading(false) setCommitsLoading(false)
} }
@ -749,14 +751,6 @@ export default function ProjectLibrary() {
<GitCommitHorizontal className="w-4 h-4" /> <GitCommitHorizontal className="w-4 h-4" />
Git同步 Git同步
</Button> </Button>
<Button
variant="ghost"
className="gap-2 h-9 text-slate-600 hover:text-[#0e7490] hover:bg-[#e0f2fe]"
onClick={refreshRepos}
>
<RefreshCw className={cn("w-4 h-4", repoLoading && "animate-spin")} />
</Button>
</div> </div>
</div> </div>
@ -773,8 +767,24 @@ export default function ProjectLibrary() {
<div className="space-y-2"> <div className="space-y-2">
<div className="text-slate-400 text-xs"></div> <div className="text-slate-400 text-xs"></div>
<div className="text-slate-700 font-medium truncate" title="修复光学渲染bug(a87b9c3)"> <div className="text-slate-700 font-medium truncate">
bug(a87b9c3) {commitsLoading ? (
<span className="text-slate-400 italic">...</span>
) : commits.length > 0 ? (
<div className="flex flex-col">
<span className="truncate" title={`${commits[0].commit.message} (${commits[0].sha.substring(0, 7)})`}>
{commits[0].commit.message}
<span className="ml-2 font-mono text-[10px] text-[#0e7490] bg-cyan-50 px-1 rounded">
{commits[0].sha.substring(0, 7)}
</span>
</span>
<span className="text-[10px] text-slate-400 mt-0.5">
{new Date(commits[0].commit.author.date).toLocaleString()}
</span>
</div>
) : (
<span className="text-slate-400 italic"></span>
)}
</div> </div>
</div> </div>
@ -842,7 +852,7 @@ export default function ProjectLibrary() {
<GitCommitHorizontal className="w-4 h-4 text-[#0e7490]" /> <GitCommitHorizontal className="w-4 h-4 text-[#0e7490]" />
Git提交记录 Git提交记录
</h3> </h3>
<div className="bg-slate-50 border border-slate-100 rounded-lg divide-y divide-slate-100"> <div className="bg-slate-50 border border-slate-100 rounded-lg divide-y divide-slate-100 max-h-[420px] overflow-y-auto">
{commitsLoading ? ( {commitsLoading ? (
<div className="p-4 text-sm text-slate-400 text-center">...</div> <div className="p-4 text-sm text-slate-400 text-center">...</div>
) : commits.length === 0 ? ( ) : commits.length === 0 ? (