refactor: 完成静态网站转换,移除所有 CMS 和动态功能

- 删除数据库相关代码 (src/db/)
- 删除 API 路由 (src/app/api/)
- 删除认证相关代码 (src/lib/auth/, src/providers/)
- 删除监控和安全中间件 (src/lib/security/, src/lib/monitoring/)
- 删除 hooks (use-news, use-products, use-services)
- 更新组件为静态数据源
- 添加 nginx 静态配置和部署脚本
- 添加 static-link 组件
This commit is contained in:
张翔
2026-04-21 07:53:56 +08:00
parent cd1d6aa28a
commit 6403489954
197 changed files with 654 additions and 24762 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useRef, useState } from 'react';
import Link from 'next/link';
import { StaticLink } from '@/components/ui/static-link';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { BackButton } from '@/components/ui/back-button';
@@ -99,7 +99,7 @@ export function CaseDetailClient({ caseItem }: CaseDetailClientProps) {
我们如何智连未来
</h2>
</div>
<div className="prose prose-sm max-w-none">
<div className="prose prose-base max-w-none [&_h3]:text-xl [&_h3]:font-semibold [&_h3]:text-[#1C1C1C] [&_h3]:mt-8 [&_h3]:mb-4 [&_p]:text-[#5C5C5C] [&_p]:leading-[1.8] [&_p]:mb-4 [&_p]:text-base">
<div dangerouslySetInnerHTML={{ __html: caseItem.content }} />
</div>
</section>
@@ -237,9 +237,9 @@ export function CaseDetailClient({ caseItem }: CaseDetailClientProps) {
className="w-full bg-white text-[#C41E3A] hover:bg-white/90"
asChild
>
<Link href="/contact">
<StaticLink href="/contact">
联系我们
</Link>
</StaticLink>
</Button>
</div>
</div>
+15 -20
View File
@@ -1,30 +1,17 @@
import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { contentService } from '@/lib/api/services';
import { CASES } from '@/lib/constants';
import { CaseDetailClient } from './client';
interface CaseItem {
id: string;
title: string;
excerpt: string;
content: string;
category: string;
slug: string;
date: string;
image?: string;
}
export async function generateStaticParams() {
const cases = await contentService.getCases(100);
return cases.map((caseItem) => ({
return CASES.map((caseItem) => ({
id: caseItem.id,
}));
}
export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
const { id } = await params;
const cases = await contentService.getCases(100);
const caseItem = cases.find((c) => c.id === id);
const caseItem = CASES.find((c) => c.id === id);
if (!caseItem) {
return {
@@ -34,18 +21,26 @@ export async function generateMetadata({ params }: { params: Promise<{ id: strin
return {
title: `${caseItem.title} - 睿新致远`,
description: caseItem.excerpt,
description: caseItem.description,
};
}
export default async function CaseDetailPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const cases = await contentService.getCases(100);
const caseItem = cases.find((c) => c.id === id);
const caseItem = CASES.find((c) => c.id === id);
if (!caseItem) {
notFound();
}
return <CaseDetailClient caseItem={caseItem as CaseItem} />;
return <CaseDetailClient caseItem={{
id: caseItem.id,
title: caseItem.title,
excerpt: caseItem.description,
content: caseItem.content || '',
category: caseItem.industry,
slug: caseItem.id,
date: '2026-01-15',
image: caseItem.image,
}} />;
}
-265
View File
@@ -1,265 +0,0 @@
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
jest.mock('framer-motion', () => ({
motion: {
div: ({ children, className, ...props }: any) => (
<div className={className} {...props}>
{children}
</div>
),
section: ({ children, className, ...props }: any) => (
<section className={className} {...props}>
{children}
</section>
),
},
AnimatePresence: ({ children }: any) => <>{children}</>,
useInView: () => [null, true],
}));
jest.mock('next/link', () => {
return ({ children, href, ...props }: any) => (
<a href={href} {...props}>
{children}
</a>
);
});
jest.mock('lucide-react', () => ({
ArrowRight: () => <span data-testid="arrow-right-icon" />,
ArrowLeft: () => <span data-testid="arrow-left-icon" />,
Building2: () => <span data-testid="building-icon" />,
Calendar: () => <span data-testid="calendar-icon" />,
TrendingUp: () => <span data-testid="trending-up-icon" />,
ChevronLeft: () => <span data-testid="chevron-left-icon" />,
ChevronRight: () => <span data-testid="chevron-right-icon" />,
Filter: () => <span data-testid="filter-icon" />,
Search: () => <span data-testid="search-icon" />,
}));
jest.mock('@/components/ui/button', () => ({
Button: ({ children, className, variant, size, disabled, onClick, ...props }: any) => (
<button
className={className}
data-variant={variant}
data-size={size}
disabled={disabled}
onClick={onClick}
{...props}
>
{children}
</button>
),
}));
jest.mock('@/components/ui/badge', () => ({
Badge: ({ children, className, variant, ...props }: any) => (
<span className={className} data-variant={variant} {...props}>
{children}
</span>
),
}));
jest.mock('@/components/ui/input', () => ({
Input: ({ className, ...props }: any) => (
<input className={className} {...props} />
),
}));
jest.mock('@/components/ui/page-header', () => ({
PageHeader: ({ title, description }: any) => (
<header>
<h1>{title}</h1>
<p>{description}</p>
</header>
),
}));
const mockCases = [
{
id: 'case-1',
title: '数字化转型案例',
excerpt: '帮助客户实现数字化转型',
content: '详细的数字化转型案例内容',
category: '制造业',
slug: 'digital-transformation',
date: '2024-01-15',
},
{
id: 'case-2',
title: 'ERP系统实施案例',
excerpt: 'ERP系统成功实施',
content: '详细的ERP系统实施案例内容',
category: '零售业',
slug: 'erp-implementation',
date: '2024-01-10',
},
{
id: 'case-3',
title: '智能制造升级',
excerpt: '智能制造系统升级',
content: '详细的智能制造升级案例内容',
category: '制造业',
slug: 'smart-manufacturing',
date: '2024-01-05',
},
];
jest.mock('@/lib/api/services', () => ({
contentService: {
getNews: jest.fn(),
},
}));
import CasesPage from './page';
import { contentService } from '@/lib/api/services';
describe('CasesPage', () => {
beforeEach(() => {
jest.clearAllMocks();
(contentService.getNews as jest.Mock).mockResolvedValue(mockCases);
});
describe('Rendering', () => {
it('should render loading state initially', () => {
render(<CasesPage />);
expect(screen.getByText('加载中...')).toBeInTheDocument();
});
it('should render cases page after loading', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const pageContainer = document.querySelector('.min-h-screen');
expect(pageContainer).toBeInTheDocument();
});
it('should render page header', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const title = screen.getByText(/与谁同行/i);
expect(title).toBeInTheDocument();
});
it('should render back to home link', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const backLink = screen.getByText(/返回首页/i);
expect(backLink).toBeInTheDocument();
});
it('should render case cards', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const caseTitles = screen.getAllByRole('heading', { level: 3 });
expect(caseTitles.length).toBeGreaterThan(0);
});
it('should render case categories', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
expect(screen.getByText('全部')).toBeInTheDocument();
expect(screen.getByText('金融')).toBeInTheDocument();
expect(screen.getByText('制造')).toBeInTheDocument();
});
it('should render CTA section', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const cta = screen.getByText(/准备开始您的数字化转型之旅/i);
expect(cta).toBeInTheDocument();
});
});
describe('Navigation', () => {
it('should have case detail links', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const links = screen.getAllByRole('link');
const caseLinks = links.filter(link => link.getAttribute('href')?.startsWith('/cases/'));
expect(caseLinks.length).toBeGreaterThan(0);
});
it('should have contact links', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const links = screen.getAllByRole('link');
const contactLinks = links.filter(link => link.getAttribute('href') === '/contact');
expect(contactLinks.length).toBeGreaterThan(0);
});
});
describe('Accessibility', () => {
it('should have proper heading hierarchy', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const h1 = screen.getByRole('heading', { level: 1 });
expect(h1).toBeInTheDocument();
});
});
describe('Filtering', () => {
it('should render filter buttons', async () => {
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const filterButtons = screen.getAllByRole('button');
expect(filterButtons.length).toBeGreaterThan(0);
});
});
describe('Error Handling', () => {
it('should display error message when API fails', async () => {
(contentService.getNews as jest.Mock).mockRejectedValue(new Error('API Error'));
render(<CasesPage />);
await waitFor(() => {
expect(screen.queryByText('加载中...')).not.toBeInTheDocument();
});
const errorMessage = screen.getByText(/加载案例失败/i);
expect(errorMessage).toBeInTheDocument();
});
});
});
+15 -81
View File
@@ -1,74 +1,35 @@
'use client';
import { useState, useMemo, useRef, useEffect, ChangeEvent } from 'react';
import { useState, useMemo, useRef, ChangeEvent } from 'react';
import { useInView } from 'framer-motion';
import { contentService } from '@/lib/api/services';
import { CASES } from '@/lib/constants';
import { Badge } from '@/components/ui/badge';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { PageHeader } from '@/components/ui/page-header';
import { Search, ArrowLeft, Building2, Calendar, TrendingUp, ChevronLeft, ChevronRight, Filter } from 'lucide-react';
import Link from 'next/link';
import { StaticLink } from '@/components/ui/static-link';
import { motion } from 'framer-motion';
const industries = ['全部', '金融', '制造', '零售', '医疗', '教育'];
const industries = ['全部', ...Array.from(new Set(CASES.map((c) => c.industry)))];
const ITEMS_PER_PAGE = 6;
interface CaseItem {
id: string;
title: string;
description: string;
industry: string;
client: string;
slug: string;
}
export default function CasesPage() {
const [selectedIndustry, setSelectedIndustry] = useState('全部');
const [searchQuery, setSearchQuery] = useState('');
const [currentPage, setCurrentPage] = useState(1);
const [cases, setCases] = useState<CaseItem[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
const contentRef = useRef(null);
const isContentInView = useInView(contentRef, { once: true, margin: '-100px' });
const fetchCases = async () => {
try {
setLoading(true);
setError(null);
const data = await contentService.getNews(['案例'], 100, 'desc');
const caseItems: CaseItem[] = data.map(item => ({
id: item.id,
title: item.title,
description: item.excerpt,
industry: item.category,
client: '客户企业',
slug: item.slug,
}));
setCases(caseItems);
} catch (err) {
setError(err instanceof Error ? err : new Error('Failed to fetch cases'));
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchCases();
}, []);
const filteredCases = useMemo(() => {
if (!cases || cases.length === 0) {return [];}
return cases.filter((caseItem) => {
return CASES.filter((caseItem) => {
const matchesIndustry = selectedIndustry === '全部' || caseItem.industry === selectedIndustry;
const matchesSearch =
const matchesSearch =
caseItem.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
caseItem.description.toLowerCase().includes(searchQuery.toLowerCase());
return matchesIndustry && matchesSearch;
});
}, [cases, selectedIndustry, searchQuery]);
}, [selectedIndustry, searchQuery]);
const totalPages = Math.ceil(filteredCases.length / ITEMS_PER_PAGE);
const paginatedCases = useMemo(() => {
@@ -92,28 +53,6 @@ export default function CasesPage() {
setCurrentPage(1);
};
if (loading) {
return (
<div className="min-h-screen bg-white flex items-center justify-center">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-[#C41E3A] mx-auto mb-4" />
<p className="text-[#5C5C5C]">加载中...</p>
</div>
</div>
);
}
if (error) {
return (
<div className="min-h-screen bg-white flex items-center justify-center">
<div className="text-center">
<p className="text-red-600 mb-4">加载案例失败</p>
<Button onClick={() => window.location.reload()}>重新加载</Button>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-white">
<PageHeader
@@ -123,12 +62,7 @@ export default function CasesPage() {
<div className="container-wide relative z-10 py-16" ref={contentRef}>
<div className="max-w-6xl mx-auto">
<Link href="/" className="inline-flex items-center text-[#5C5C5C] hover:text-[#C41E3A] transition-colors mb-8">
<ArrowLeft className="w-4 h-4 mr-2" />
返回首页
</Link>
<motion.div
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={isContentInView ? { opacity: 1, y: 0 } : {}}
transition={{ duration: 0.6 }}
@@ -183,8 +117,8 @@ export default function CasesPage() {
animate={isContentInView ? { opacity: 1, y: 0 } : {}}
transition={{ duration: 0.5, delay: index * 0.1 }}
>
<Link
href={`/cases/${caseItem.slug}`}
<StaticLink
href={`/cases/${caseItem.id}`}
className="group bg-white rounded-2xl border border-[#E5E5E5] overflow-hidden hover:shadow-xl transition-all duration-300 block"
>
<div className="relative h-48 bg-gradient-to-br from-[#F5F5F5] to-[#E5E5E5] overflow-hidden">
@@ -228,7 +162,7 @@ export default function CasesPage() {
<ArrowLeft className="w-4 h-4 ml-2 rotate-180" />
</div>
</div>
</Link>
</StaticLink>
</motion.div>
))}
</div>
@@ -293,15 +227,15 @@ export default function CasesPage() {
让我们与您同行,共创美好未来
</p>
<div className="flex justify-center gap-4">
<Link href="/contact">
<StaticLink href="/contact">
<Button
size="lg"
variant="outline"
>
联系我们
</Button>
</Link>
<Link href="/contact">
</StaticLink>
<StaticLink href="/contact">
<Button
size="lg"
className="bg-[#C41E3A] hover:bg-[#A01830] text-white"
@@ -309,7 +243,7 @@ export default function CasesPage() {
立即咨询
<ArrowLeft className="ml-2 w-4 h-4 rotate-180" />
</Button>
</Link>
</StaticLink>
</div>
</div>
</motion.div>