This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Halolight Angular 是一个基于 Angular 21 + Tailwind CSS 4 的现代化中文后台管理系统,使用 TypeScript、Standalone Components 和 Signals 构建。这是 Halolight 系列的 Angular 版本实现。
- 核心框架: Angular 21 (Standalone Components + Signals) + TypeScript 5.9
- 路由: @angular/router (with View Transitions)
- 状态管理: Angular Signals + RxJS 7.8
- 数据请求: HttpClient + TanStack Angular Query
- 样式: Tailwind CSS 4、自定义 UI 组件 (shadcn 风格)、class-variance-authority
- 图表: ECharts + ngx-echarts
- 拖拽布局: angular-gridster2
- Mock: Mock.js
- 图标: lucide-angular
- 构建/规范: npm 11、Prettier
- 测试: Vitest + jsdom
npm start # 启动开发服务器 (http://localhost:4200)
npm run build # 生产构建
npm run watch # 开发模式监听构建
npm test # 运行单元测试 (Vitest)
ng generate # Angular CLI 代码生成器注意: Angular 21 需要 Node.js 20.19+ 或 22.12+
Angular 应用通过 bootstrapApplication 使用 Standalone API 初始化:
bootstrapApplication(App, appConfig)export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideRouter(routes, withComponentInputBinding(), withViewTransitions()),
provideHttpClient(withInterceptors([authInterceptor])),
provideAnimationsAsync(),
provideAngularQuery(queryClient),
],
};src/
├── app/
│ ├── app.ts # 根组件 (Standalone)
│ ├── app.config.ts # 应用配置 (Providers)
│ ├── app.routes.ts # 路由配置
│ ├── core/ # 核心模块
│ │ ├── guards/ # 路由守卫
│ │ │ └── auth.guard.ts # authGuard, guestGuard
│ │ ├── interceptors/ # HTTP 拦截器
│ │ │ └── auth.interceptor.ts
│ │ └── services/ # 单例服务
│ │ ├── auth.service.ts # 认证服务 (Signals + localStorage)
│ │ └── http.service.ts # HTTP 封装
│ ├── shared/ # 共享模块
│ │ ├── components/ui/ # UI 组件 (shadcn 风格)
│ │ │ ├── button/ # ButtonComponent
│ │ │ ├── input/ # InputComponent (ControlValueAccessor)
│ │ │ └── card/ # Card 系列组件
│ │ └── lib/
│ │ └── utils.ts # cn() 工具函数
│ ├── features/ # 功能模块
│ │ ├── auth/ # 认证模块
│ │ │ ├── login/ # LoginPage
│ │ │ └── register/ # RegisterPage
│ │ └── dashboard/ # 仪表盘模块
│ │ └── dashboard.page.ts
│ ├── layouts/ # 布局组件
│ │ ├── admin-layout/ # AdminLayout (Sidebar + Header)
│ │ └── auth-layout/ # AuthLayout
│ ├── config/ # 配置
│ ├── store/ # 状态管理
│ └── environments/ # 环境配置
├── styles.css # 全局样式 (Tailwind + CSS 变量主题)
├── index.html # HTML 入口
└── main.ts # 应用启动入口
- API 请求:
core/services/http.service.ts封装 HttpClient → TanStack Query 或直接在组件中使用 - 状态管理:
- 响应式状态: 使用 Angular Signals (
signal,computed,effect) - 认证状态:
AuthService使用 Signals + localStorage 持久化 - 异步流: 复杂场景使用 RxJS Observables
- 响应式状态: 使用 Angular Signals (
- Mock 数据: 开发环境下可通过 Mock.js 拦截
在 src/app/app.config.ts 中配置:
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5, // 5 分钟
gcTime: 1000 * 60 * 30, // 30 分钟
refetchOnWindowFocus: false,
retry: 1,
},
},
});使用 CSS 变量实现暗色/亮色主题切换:
- 暗色主题 (默认):
:root中定义 - 亮色主题:
.light类中覆盖 - 变量包括:
--background,--foreground,--primary,--card,--border等 - 图表颜色:
--chart-1到--chart-5
- 组件风格: 严格使用 Angular 21 Standalone Components
- 响应式: 优先使用 Signals (
signal,computed,model,input,output) - 模板: 使用新的控制流语法 (
@if,@for,@switch) - 样式: 使用 Tailwind Utility Classes +
cn()合并类名 - 类型安全: 严格模式 (
strict: true),避免使用any - 组件前缀: UI 组件使用
ui-前缀,页面使用app-前缀
自定义组件库 (shadcn/ui 风格):
- ButtonComponent: 支持 variant、size、disabled、type
- InputComponent: 实现 ControlValueAccessor,支持 Reactive Forms
- CardComponent: Card、CardHeader、CardTitle、CardDescription、CardContent、CardFooter
使用 class-variance-authority 管理变体样式。
- Token 存储: localStorage (通过 AuthService 管理)
- 路由守卫:
authGuard(需认证) 和guestGuard(仅游客) - HTTP 拦截器: 自动附加 Authorization header,处理 401 错误
- 在
src/app/features/下创建功能模块目录 - 创建页面组件 (Standalone):
@Component({ selector: 'app-xxx-page', standalone: true, imports: [...], template: `...`, }) export class XxxPage {}
- 在
src/app/app.routes.ts中注册路由 (支持懒加载):{ path: 'xxx', loadComponent: () => import('./features/xxx/xxx.page').then(m => m.XxxPage), }
- 在
AdminLayout的menuItems中添加导航项
- 在
src/app/core/services/创建服务文件 - 使用
@Injectable({ providedIn: 'root' })声明单例服务 - 注入
HttpService或直接使用HttpClient - 可选: 使用 TanStack Query 封装
- 在
src/app/shared/components/ui/下创建组件目录 - 使用
class-variance-authority定义变体 - 使用
cn()合并类名 - 在
index.ts中导出
- 在
src/app/features/dashboard/widgets/创建部件组件 - 使用 Signal-based 数据绑定
- 集成 ngx-echarts 图表
- 在 Dashboard 页面中组合部件
本项目使用 Angular 21 最新特性:
- Standalone Components: 无需 NgModule,组件直接声明依赖
- Signals:
signal(),computed(),effect(),model(),input(),output() - 新控制流语法:
@if,@for,@switch,@defer - View Transitions: 页面切换动画
- Function-based Guards:
CanActivateFn - Function-based Interceptors:
HttpInterceptorFn
- Node.js 版本: 需要 20.19+ 或 22.12+
- Standalone 组件: 所有组件必须在
imports数组中声明依赖 - Signal 绑定: 模板中调用 signal 需要使用
()(e.g.,{{ title() }}) - model(): 用于双向绑定,替代
@Input()+@Output() - Tailwind CSS 4: 使用
@import "tailwindcss"和@theme扩展
| 功能 | Angular 版本 | Vue 版本 | Next.js 版本 |
|---|---|---|---|
| 状态管理 | Signals + RxJS | Pinia | Zustand |
| 数据请求 | TanStack Angular Query | TanStack Vue Query | React Query |
| UI 组件 | 自定义 (shadcn 风格) | shadcn-vue | shadcn/ui |
| 路由 | @angular/router | Vue Router | Next.js App Router |
| 表单 | Reactive Forms + Zod | Vue + Zod | React Hook Form + Zod |
| 构建工具 | Angular CLI / esbuild | Vite (Rolldown) | Next.js |