fix:优化数据

This commit is contained in:
丹尼尔
2026-03-15 16:38:59 +08:00
parent a609f81a36
commit 3aa1a586e5
43 changed files with 14565 additions and 294 deletions

View File

@@ -2,27 +2,63 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect, useState, useCallback } from "react";
import {
FileText,
FolderArchive,
Settings,
Building2,
Globe,
PiggyBank,
FileStack,
Settings2,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { Separator } from "@/components/ui/separator";
import { Button } from "@/components/ui/button";
import { HistoricalReferences } from "@/components/historical-references";
const QUICK_LINKS = [
{ label: "国家税务总局门户", href: "https://www.chinatax.gov.cn", icon: Building2 },
{ label: "电子税务局", href: "https://etax.chinatax.gov.cn", icon: Globe },
{ label: "公积金管理中心", href: "https://www.12329.com.cn", icon: PiggyBank },
];
import { cloudDocsApi, portalLinksApi, type CloudDocLinkRead, type PortalLinkRead } from "@/lib/api/client";
export function AppSidebar() {
const pathname = usePathname();
const [cloudDocs, setCloudDocs] = useState<CloudDocLinkRead[]>([]);
const [portalLinks, setPortalLinks] = useState<PortalLinkRead[]>([]);
const loadCloudDocs = useCallback(async () => {
try {
const list = await cloudDocsApi.list();
setCloudDocs(list);
} catch {
setCloudDocs([]);
}
}, []);
useEffect(() => {
loadCloudDocs();
}, [loadCloudDocs]);
useEffect(() => {
const onCloudDocsChanged = () => loadCloudDocs();
window.addEventListener("cloud-docs-changed", onCloudDocsChanged);
return () => window.removeEventListener("cloud-docs-changed", onCloudDocsChanged);
}, [loadCloudDocs]);
const loadPortalLinks = useCallback(async () => {
try {
const list = await portalLinksApi.list();
setPortalLinks(list);
} catch {
setPortalLinks([]);
}
}, []);
useEffect(() => {
loadPortalLinks();
}, [loadPortalLinks]);
useEffect(() => {
const onPortalLinksChanged = () => loadPortalLinks();
window.addEventListener("portal-links-changed", onPortalLinksChanged);
return () => window.removeEventListener("portal-links-changed", onPortalLinksChanged);
}, [loadPortalLinks]);
const nav = [
{ href: "/workspace", label: "需求与方案", icon: FileText },
@@ -54,25 +90,70 @@ export function AppSidebar() {
))}
</nav>
<Separator />
<div className="p-2">
<p className="text-xs font-medium text-muted-foreground px-2 mb-2">
</p>
<div className="flex flex-col gap-1">
{QUICK_LINKS.map((link) => (
<a
key={link.href}
href={link.href}
target="_blank"
rel="noopener noreferrer"
className={cn(
"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground"
)}
<div className="flex-1 min-h-0 overflow-y-auto flex flex-col">
<div className="p-2 shrink-0">
<div className="flex items-center justify-between px-2 mb-2">
<p className="text-xs font-medium text-muted-foreground"></p>
<Link
href="/settings/cloud-docs"
className="text-xs text-muted-foreground hover:text-foreground"
title="管理云文档入口"
>
<link.icon className="h-4 w-4 shrink-0" />
{link.label}
</a>
))}
<Settings2 className="h-3.5 w-3.5" />
</Link>
</div>
<div className="flex flex-col gap-1">
{cloudDocs.length === 0 ? (
<p className="text-xs text-muted-foreground px-2"></p>
) : (
cloudDocs.map((doc) => (
<a
key={doc.id}
href={doc.url}
target="_blank"
rel="noopener noreferrer"
className={cn(
"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground"
)}
>
<FileStack className="h-4 w-4 shrink-0" />
<span className="truncate">{doc.name}</span>
</a>
))
)}
</div>
</div>
<div className="p-2 shrink-0">
<div className="flex items-center justify-between px-2 mb-2">
<p className="text-xs font-medium text-muted-foreground"></p>
<Link
href="/settings/portal-links"
className="text-xs text-muted-foreground hover:text-foreground"
title="管理快捷门户"
>
<Settings2 className="h-3.5 w-3.5" />
</Link>
</div>
<div className="flex flex-col gap-1">
{portalLinks.length === 0 ? (
<p className="text-xs text-muted-foreground px-2"></p>
) : (
portalLinks.map((link) => (
<a
key={link.id}
href={link.url}
target="_blank"
rel="noopener noreferrer"
className={cn(
"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground"
)}
>
<Globe className="h-4 w-4 shrink-0" />
<span className="truncate">{link.name}</span>
</a>
))
)}
</div>
</div>
</div>
{pathname === "/workspace" && <HistoricalReferences />}