feat: 重构 openInCNB 函数,简化代码逻辑并优化导航处理

This commit is contained in:
2026-02-27 02:29:11 +08:00
parent f05aab2430
commit 364e903d5f

View File

@@ -72,11 +72,16 @@ export function RepoCard({ showReturn = false, repo }: RepoCardProps) {
const handleIssue = (repo: any) => { const handleIssue = (repo: any) => {
window.open(`https://cnb.cool/${repo.path}/-/issues`) window.open(`https://cnb.cool/${repo.path}/-/issues`)
} }
const handleSettings = (repo: any) => { const handleSettings = (repo: any) => {
window.open(`https://cnb.cool/${repo.path}/-/settings`) window.open(`https://cnb.cool/${repo.path}/-/settings`)
} }
const openInCNB = (isDetail = true) => {
if (!showReturn && isDetail) {
navigate({ to: `/repo?repo=${repo.path}` })
} else {
window.open(`https://cnb.cool/${repo.path}`, '_blank')
}
}
return ( return (
<> <>
<Card className="relative p-0 overflow-hidden border border-neutral-200 bg-white hover:shadow-xl hover:border-neutral-300 transition-all duration-300 group pb-14"> <Card className="relative p-0 overflow-hidden border border-neutral-200 bg-white hover:shadow-xl hover:border-neutral-300 transition-all duration-300 group pb-14">
@@ -94,11 +99,7 @@ export function RepoCard({ showReturn = false, repo }: RepoCardProps) {
<div <div
className="text-lg font-bold text-neutral-900 hover:text-neutral-600 transition-colors line-clamp-1 group-hover:underline" className="text-lg font-bold text-neutral-900 hover:text-neutral-600 transition-colors line-clamp-1 group-hover:underline"
onClick={() => { onClick={() => {
if (!showReturn) { openInCNB()
navigate({ to: `/repo?repo=${repo.path}` })
} else {
window.open(`https://cnb.cool/${repo.path}`, '_blank')
}
}} }}
> >
{repo.path} {repo.path}
@@ -299,10 +300,8 @@ export function RepoCard({ showReturn = false, repo }: RepoCardProps) {
)} )}
<Badge variant="outline" className="text-xs border-neutral-300 text-neutral-700 hover:bg-neutral-100 transition-colors">{repo.visibility_level}</Badge> <Badge variant="outline" className="text-xs border-neutral-300 text-neutral-700 hover:bg-neutral-100 transition-colors">{repo.visibility_level}</Badge>
</div> </div>
<div className={clsx("flex flex-col sm:flex-row sm:items-center gap-4", !showReturn && "cursor-pointer")} onClick={() => { <div className={clsx(!showReturn && "cursor-pointer")} onClick={() => {
if (!showReturn) { { !showReturn && openInCNB(false) }
window.open(repo.site, '_blank')
}
}}> }}>
{repo.site && ( {repo.site && (
<div <div