Files
flutterApp/lib/features/v2/my/README.md

65 lines
1.7 KiB
Markdown
Raw Normal View History

# 我的页面模块
## 架构说明
采用清洁架构(Clean Architecture)四层划分:
### 1. Domain 层(领域层)
- `entities/` - 实体类(UserProfileEntity, MenuItemEntity)
- `repositories/` - 仓储接口(MyRepository)
- `usecases/` - 用例(GetMenuItemsUseCase, ToggleNightModeUseCase, ClearCacheUseCase)
### 2. Data 层(数据层)
- `models/` - 数据模型(UserProfileModel, MenuItemModel)
- `datasources/` - 数据源接口和实现
- `repositories/` - 仓储实现(MyRepositoryImpl)
### 3. Presentation 层(表现层)
- `states/` - 状态管理(MyState)
- `cubit/` - 业务逻辑(MyCubit)
- `pages/` - 页面(MyPage)
- `widgets/` - UI 组件(UserProfileCard, MenuItemCard)
- `constants/` - 常量定义(MyColors, MyDimensions)
- `routes/` - 路由配置(MyRoutes)
### 4. DI 层(依赖注入)
- `di/` - 依赖注入配置(MyDependencyInjector)
## 功能特性
- 用户信息展示(头像、姓名、角色)
- 菜单列表(个人信息、消息设置、离线缓存、夜间模式等)
- 夜间模式切换
- 缓存清除功能
- 响应式状态管理(Cubit)
## 使用示例
```dart
import 'package:maibu_satabot_v2/features/v2/my/my.dart';
// 在路由配置中使用
GoRoute(
path: 'my',
name: 'my',
builder: (context, state) => const MyPage(),
),
```
## 数据流
1. **初始化**: MyPage 通过 MyDependencyInjector 创建 MyCubit
2. **加载数据**: MyCubit 调用 UseCase 获取数据
3. **状态更新**: 数据通过 Entity → State 传递给 UI
4. **用户交互**: UI 触发 Cubit 方法,更新状态
## 依赖关系
```
Presentation → Domain ← Data
↓ ↓
Cubit UseCase
↓ ↓
State Repository
```