feat: 完善前后端核心功能模块

后端:
- 新增认证(auth)、任务(tasks)、映射(mappings)、对账(reconciliation)、异常(exceptions)、导出(exports) API
- 新增核心模块: database, security, permissions, tenant, exceptions, error_handlers
- 新增数据模型: user, company, reconciliation_task, field_mapping, uploaded_file 等
- 新增服务层: ai_recognizer, file_parser, file_storage, mapping, reconciliation 等
- 添加数据库迁移脚本

前端:
- 新增登录页面和仪表盘页面
- 新增任务列表、任务详情、字段映射页面
- 新增异常处理页面和规则设置页面
- 新增 API 代理路由 /api/[...path]
- 新增 UI 组件库 (button, card, dialog, input, table 等)
- 新增 auth 组件 (ProtectedRoute, PermissionGate)
- 新增 layout 组件 (Header, Sidebar)
- 新增 mapping 组件 (FieldMappingTable, AISuggestionPanel)
- 新增 API 客户端和 hooks (useAsync, useToast, usePermission 等)
- 新增状态管理 (auth-store, company-store, ui-store)
- 集成 Tailwind CSS 和 shadcn/ui 组件库

其他:
- 添加 Alembic 数据库迁移配置
- 添加初始化示例数据脚本
- 更新项目文档
This commit is contained in:
freedakgmail
2026-07-07 09:04:47 +08:00
parent 8487f6eadf
commit 33b4c734aa
117 changed files with 22070 additions and 295 deletions
+82
View File
@@ -0,0 +1,82 @@
"use client";
import { useRouter } from "next/navigation";
import { LogOut, User } from "lucide-react";
import { useAuthStore } from "@/lib/stores/auth-store";
import { Button } from "@/components/ui/button";
import { api } from "@/lib/api/client";
import ENDPOINTS from "@/lib/api/endpoints";
export function Header() {
const router = useRouter();
const { user, logout } = useAuthStore();
const handleLogout = async () => {
try {
// 调用后端登出接口
await api.post(ENDPOINTS.AUTH.LOGOUT);
} catch {
// 即使后端失败也清除本地状态
}
// 清除本地状态
logout();
// 跳转到登录页
router.push("/login");
};
if (!user) return null;
return (
<header className="sticky top-0 z-50 w-full border-b border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<div className="flex h-14 items-center justify-between px-6">
{/* 左侧 - Logo 和系统名称 */}
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="lucide lucide-shield w-4 h-4 text-primary"
aria-hidden="true"
>
<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"></path>
</svg>
</div>
<span className="font-semibold text-foreground">AI助手</span>
</div>
{/* 右侧 - 用户信息和登出 */}
<div className="flex items-center gap-4">
{/* 用户信息 */}
<div className="flex items-center gap-3 text-sm">
<div className="flex items-center gap-2 px-3 py-1.5 rounded-lg bg-muted/50">
<User className="w-4 h-4 text-muted-foreground" />
<span className="font-medium text-foreground">{user.full_name}</span>
<span className="text-muted-foreground">·</span>
<span className="text-muted-foreground">{user.role}</span>
</div>
</div>
{/* 登出按钮 */}
<Button
variant="ghost"
size="sm"
onClick={handleLogout}
className="gap-2 text-muted-foreground hover:text-foreground"
>
<LogOut className="w-4 h-4" />
<span></span>
</Button>
</div>
</div>
</header>
);
}
+105
View File
@@ -0,0 +1,105 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { motion } from "motion/react";
import {
LayoutDashboard,
FileText,
AlertTriangle,
Settings,
ChevronLeft,
ChevronRight
} from "lucide-react";
import { cn } from "@/lib/utils";
import { useState } from "react";
const navItems = [
{
label: "工作台",
href: "/dashboard",
icon: LayoutDashboard
},
{
label: "对账任务",
href: "/tasks",
icon: FileText
},
{
label: "异常处理",
href: "/exceptions",
icon: AlertTriangle
},
{
label: "规则设置",
href: "/settings/rules",
icon: Settings
},
];
export function Sidebar() {
const pathname = usePathname();
const [collapsed, setCollapsed] = useState(false);
return (
<aside
className={cn(
"sticky top-14 h-[calc(100vh-3.5rem)] border-r border-border bg-background transition-all duration-300 flex flex-col",
collapsed ? "w-16" : "w-56"
)}
>
{/* Navigation */}
<nav className="flex-1 p-3 space-y-1">
{navItems.map((item) => {
const isActive = pathname === item.href || pathname.startsWith(item.href + "/");
const Icon = item.icon;
return (
<Link
key={item.href}
href={item.href}
className={cn(
"flex items-center gap-3 px-3 py-2.5 rounded-lg transition-all relative group",
isActive
? "bg-primary/10 text-primary"
: "text-muted-foreground hover:bg-muted hover:text-foreground",
collapsed && "justify-center px-0"
)}
>
{isActive && (
<motion.div
layoutId="activeNav"
className="absolute inset-0 bg-primary/10 rounded-lg -z-10"
transition={{ type: "spring", bounce: 0.2, duration: 0.4 }}
/>
)}
<Icon className={cn("w-5 h-5 shrink-0", isActive && "text-primary")} />
{!collapsed && (
<span className="text-body font-medium">{item.label}</span>
)}
{/* Tooltip for collapsed state */}
{collapsed && (
<div className="absolute left-full ml-2 px-2 py-1 bg-foreground text-background text-xs rounded opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all whitespace-nowrap z-50">
{item.label}
</div>
)}
</Link>
);
})}
</nav>
{/* Collapse toggle */}
<button
onClick={() => setCollapsed(!collapsed)}
className="flex items-center justify-center h-10 border-t border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors"
>
{collapsed ? (
<ChevronRight className="w-4 h-4" />
) : (
<ChevronLeft className="w-4 h-4" />
)}
</button>
</aside>
);
}