Skip to content

C 端 Web(ArchForgeWeb)

ArchForgeWeb 是 ArchForge 的 C 端 Next.js 客户端。只对接 server-web:8081),覆盖国际化、Sa-Token 认证、文章、仪表盘与 Playwright E2E 测试。

技术栈

类别技术版本用途
框架Next.js16.2.12React 框架,App Router
UIReact19.2.8组件库
语言TypeScript5.8.3类型安全的 JavaScript
样式Tailwind CSS4.3.3原子化 CSS
组件shadcn/ui + lucide-react无头 UI 原语与图标
国际化next-intl4.13.4英文 / 中文多语言
认证Sa-Token(server-web)C 端 Token 认证
Markdownreact-markdown + remark-gfm + rehype-highlight文章内容渲染
E2E 测试Playwright1.61.1端到端测试
构建Turborepo + pnpm workspacesmonorepo 编排

项目结构

apps/web/
├── src/
│   ├── app/                    # Next.js App Router 页面
│   │   ├── page.tsx            # 仪表盘 / 首页
│   │   ├── articles/           # 文章列表与详情
│   │   ├── articles/me/        # 我的文章
│   │   ├── write/              # 写文章
│   │   ├── login/              # 登录页
│   │   ├── profile/            # 个人中心
│   │   ├── change-password/    # 修改密码
│   │   └── notifications/      # 通知中心
│   ├── components/             # React 组件
│   │   ├── Header.tsx          # 顶部导航(桌面端)
│   │   ├── BottomNav.tsx       # 底部导航(移动端)
│   │   ├── ArticleCard.tsx     # 文章卡片
│   │   ├── LocaleSwitcher.tsx  # 语言切换
│   │   ├── Markdown.tsx        # Markdown 渲染
│   │   └── providers/
│   │       └── AuthProvider.tsx # 认证上下文
│   ├── components/ui/          # shadcn/ui 原语
│   └── lib/                    # API 客户端与工具
│       ├── api.ts              # server-web 接口调用
│       └── utils.ts            # cn() 等工具函数
├── messages/
│   ├── en.json                 # 英文翻译
│   └── zh.json                 # 中文翻译
├── i18n/
│   ├── request.ts              # next-intl 请求配置
│   └── routing.ts              # next-intl 路由配置
├── middleware.ts               # next-intl 中间件
├── e2e/                        # Playwright E2E 测试
├── next.config.ts
└── package.json

功能特性

认证

  • 使用与 admin 相同的开发账号(如 admin / admin123)登录。
  • C 端 API 采用 Sa-Token,tokentokenName 存储在 localStorage
  • AuthProvider 保护需要登录的页面(/articles/me/write/profile/notifications/change-password)。
  • 未登录访问受保护页面会被重定向到 /login

国际化

  • 默认语言:英文(en
  • 支持语言:enzh
  • 翻译文件位于 apps/web/messages/
  • next-intl 配置为 localePrefix: 'never',URL 不随语言变化。
  • 页面顶部语言按钮设置 NEXT_LOCALE Cookie 并刷新页面。

仪表盘

首页(/)展示:

  • 基于时间的问候语(早上好/下午好/晚上好)。
  • 运营指标:用户总数、当前在线、今日登录、今日操作。
  • 快捷入口:文章、写文章、个人中心、通知。
  • 最新通知与操作日志。

文章

  • 公开文章列表/articles):支持分类筛选与分页。
  • 文章详情/articles/{slug}):Markdown 渲染,支持封面图。
  • 我的文章/articles/me):登录后查看。
  • 写文章/write):填写标题、摘要、分类、上传封面图、Markdown 正文。

个人中心与设置

  • /profile — 展示当前用户信息。
  • /change-password — 修改密码(旧密码、新密码、确认密码)。
  • /notifications — 系统通知列表。

响应式布局

  • 桌面端:顶部 Header 导航 + 语言切换。
  • 移动端:底部 Tab 导航。
  • 使用 Tailwind CSS 工具类实现间距与网格自适应。

API 基础地址

前端连接 server-web(默认 http://localhost:8081)。

text
# apps/web/.env.local
NEXT_PUBLIC_API_BASE_URL=http://localhost:8081

管理端(:8080)成功响应包装为 {code, message, data}。C 端(:8081)错误使用 RFC 9457 ProblemDetail

主要 API 接口

接口方法说明
/web/loginPOST用户名密码登录
/web/logoutPOST退出登录
/web/user/profileGET当前用户信息
/web/user/change-passwordPOST修改密码
/web/user/articlesGET我的文章(分页)
/web/dashboard/metricsGET仪表盘指标
/web/noticesGET最新通知
/web/operation-logsGET最近操作日志
/web/categoriesGET文章分类
/web/articlesGET公开文章(分页)
/web/articles/{slug}GET文章详情
/web/articlesPOST创建文章
/web/file/uploadPOST上传封面图

可用脚本

bash
pnpm dev              # 启动 Next.js 开发服务器(端口 3000)
pnpm build            # 生产构建
pnpm start            # 启动生产服务器
pnpm typecheck        # TypeScript 类型检查
pnpm lint             # Next.js 代码检查
pnpm test:e2e         # 运行 Playwright E2E 测试
pnpm test:e2e:ui      # Playwright UI 模式
pnpm test:e2e:debug   # Playwright 调试模式

测试

Playwright E2E

e2e/ 目录覆盖核心用户路径:

  • home.spec.ts — 首页问候语与导航到文章列表。
  • locale.spec.ts — 中英文切换。
  • articles.spec.ts — 文章列表与详情页。
  • auth.spec.ts — 登录、访问受保护页面、登出。

Playwright 配置通过 webServer 自动启动 pnpm dev,目标浏览器为 Chromium。

快速开始

  1. 配置 API 基础地址:
bash
cp .env.example .env.local
# 编辑 apps/web/.env.local
  1. 安装依赖:
bash
pnpm install
  1. 启动后端(server-web 端口 8081):
bash
# 在 ArchForge 仓库中
./gradlew :archforge-server-web:bootRun
  1. 启动开发服务器:
bash
pnpm dev

打开 http://localhost:3000

说明

  • C 端与管理端是两套 sa-token 登录类型(StpWebUtil / StpAdminUtil),不是 JWT vs sa-token。
  • 文章详情页结合 next-intlreact-markdown 做服务端渲染。
  • 认证 Cookie(tokentokenNamerefreshToken)会镜像到 localStorageserver-web 错误为 RFC 9457 ProblemDetail。

相关页面

Released under the MIT License.