feat: 修复测试套件问题并添加Woodpecker CI配置

- 修复API测试认证问题:创建全局认证设置,更新Playwright配置
- 优化回归测试稳定性:增加超时时间到15秒,修复定位器
- 创建Woodpecker CI工作流:CI、部署和质量门禁配置
- 添加Jest配置和测试脚本
- 移除登录页面的默认账号密码显示(安全问题修复)
This commit is contained in:
张翔
2026-03-09 10:26:02 +08:00
parent 96c96fe75d
commit 6d92024b63
68 changed files with 5584 additions and 167 deletions
+161
View File
@@ -0,0 +1,161 @@
import { auth } from '@/lib/auth';
import { db } from '@/db';
import { content, users } from '@/db/schema';
import { desc, eq, sql } from 'drizzle-orm';
import Link from 'next/link';
import { FileText, Settings, Users, TrendingUp } from 'lucide-react';
async function getStats() {
const [
contentCount,
publishedCount,
draftCount,
userCount,
recentContent,
] = await Promise.all([
db.select({ count: sql<number>`count(*)` }).from(content),
db.select({ count: sql<number>`count(*)` }).from(content).where(eq(content.status, 'published')),
db.select({ count: sql<number>`count(*)` }).from(content).where(eq(content.status, 'draft')),
db.select({ count: sql<number>`count(*)` }).from(users),
db.select().from(content).orderBy(desc(content.createdAt)).limit(5),
]);
return {
contentCount: contentCount[0]?.count || 0,
publishedCount: publishedCount[0]?.count || 0,
draftCount: draftCount[0]?.count || 0,
userCount: userCount[0]?.count || 0,
recentContent,
};
}
export default async function AdminDashboard() {
const session = await auth();
const stats = await getStats();
const statCards = [
{
name: '总内容数',
value: stats.contentCount,
icon: FileText,
color: 'bg-blue-500',
href: '/admin/content'
},
{
name: '已发布',
value: stats.publishedCount,
icon: TrendingUp,
color: 'bg-green-500',
href: '/admin/content?status=published'
},
{
name: '草稿',
value: stats.draftCount,
icon: FileText,
color: 'bg-yellow-500',
href: '/admin/content?status=draft'
},
{
name: '用户数',
value: stats.userCount,
icon: Users,
color: 'bg-purple-500',
href: '/admin/users'
},
];
return (
<div className="space-y-8">
<div>
<h1 className="text-2xl font-bold text-gray-900">仪表盘</h1>
<p className="text-gray-600 mt-1">欢迎回来,{session?.user?.name}</p>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
{statCards.map((stat) => (
<Link
key={stat.name}
href={stat.href}
className="bg-white rounded-xl shadow-sm border border-gray-200 p-6 hover:shadow-md transition-shadow"
>
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-600">{stat.name}</p>
<p className="text-3xl font-bold text-gray-900 mt-2">{stat.value}</p>
</div>
<div className={`${stat.color} p-3 rounded-lg`}>
<stat.icon className="h-6 w-6 text-white" />
</div>
</div>
</Link>
))}
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex items-center justify-between mb-4">
<h2 className="text-lg font-semibold text-gray-900">最近内容</h2>
<Link
href="/admin/content"
className="text-sm text-[#C41E3A] hover:underline"
>
查看全部
</Link>
</div>
{stats.recentContent.length === 0 ? (
<p className="text-gray-500 text-center py-8">暂无内容</p>
) : (
<div className="space-y-4">
{stats.recentContent.map((item) => (
<div
key={item.id}
className="flex items-center justify-between py-3 border-b border-gray-100 last:border-0"
>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-gray-900 truncate">
{item.title}
</p>
<p className="text-xs text-gray-500 mt-1">
{item.type} · {item.status === 'published' ? '已发布' : '草稿'}
</p>
</div>
<Link
href={`/admin/content/${item.id}`}
className="text-sm text-[#C41E3A] hover:underline ml-4"
>
编辑
</Link>
</div>
))}
</div>
)}
</div>
<div className="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
<div className="flex items-center justify-between mb-4">
<h2 className="text-lg font-semibold text-gray-900">快捷操作</h2>
</div>
<div className="grid grid-cols-2 gap-4">
<Link
href="/admin/content/new"
className="flex flex-col items-center justify-center p-6 rounded-lg border-2 border-dashed border-gray-300 hover:border-[#C41E3A] hover:bg-red-50 transition-colors"
>
<FileText className="h-8 w-8 text-gray-400 mb-2" />
<span className="text-sm font-medium text-gray-600">新建内容</span>
</Link>
<Link
href="/admin/config"
className="flex flex-col items-center justify-center p-6 rounded-lg border-2 border-dashed border-gray-300 hover:border-[#C41E3A] hover:bg-red-50 transition-colors"
>
<Settings className="h-8 w-8 text-gray-400 mb-2" />
<span className="text-sm font-medium text-gray-600">配置中心</span>
</Link>
</div>
</div>
</div>
</div>
);
}