所有一级页面和不分二级页面

This commit is contained in:
2026-05-25 12:58:29 +08:00
parent b9f747de05
commit afef5c4ef1
158 changed files with 13082 additions and 1602 deletions

View File

@@ -0,0 +1,64 @@
# 我的页面模块
## 架构说明
采用清洁架构(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
```

View File

@@ -0,0 +1,78 @@
import 'package:maibu_satabot_v2/features/v2/my/data/datasources/my_remote_datasource.dart';
import 'package:maibu_satabot_v2/features/v2/my/data/models/my_models.dart';
/// 我的页面远程数据源实现(模拟数据)
class MyRemoteDataSourceImpl implements MyRemoteDataSource {
@override
Future<UserProfileModel> getUserProfile() async {
await Future.delayed(const Duration(milliseconds: 300));
return UserProfileModel(
name: '张工程师',
role: '运维工程师',
avatar: 'assets/images/avatar_engineer.png',
userId: 'ENG2024001',
);
}
@override
Future<List<MenuItemModel>> getMenuItems() async {
await Future.delayed(const Duration(milliseconds: 300));
return [
MenuItemModel(
id: 'personal_info',
title: '个人信息',
icon: 'person',
),
MenuItemModel(
id: 'message_settings',
title: '消息设置',
icon: 'notifications',
),
MenuItemModel(
id: 'offline_cache',
title: '离线缓存',
icon: 'cloud_download',
subTitle: '1.26 GB',
),
MenuItemModel(
id: 'night_mode',
title: '夜间模式',
icon: 'dark_mode',
hasSwitch: true,
switchValue: false,
),
MenuItemModel(
id: 'system_settings',
title: '系统设置',
icon: 'settings',
),
MenuItemModel(
id: 'help_feedback',
title: '帮助与反馈',
icon: 'help',
),
MenuItemModel(
id: 'about_us',
title: '关于我们',
icon: 'info',
subTitle: 'V2.1.0',
),
];
}
@override
Future<bool> toggleNightMode(bool enabled) async {
await Future.delayed(const Duration(milliseconds: 200));
// 模拟保存设置
return true;
}
@override
Future<bool> clearCache() async {
await Future.delayed(const Duration(seconds: 1));
// 模拟清除缓存
return true;
}
}

View File

@@ -0,0 +1,16 @@
import 'package:maibu_satabot_v2/features/v2/my/data/models/my_models.dart';
/// 我的页面远程数据源抽象
abstract class MyRemoteDataSource {
/// 获取用户信息
Future<UserProfileModel> getUserProfile();
/// 获取菜单列表
Future<List<MenuItemModel>> getMenuItems();
/// 切换夜间模式
Future<bool> toggleNightMode(bool enabled);
/// 清除缓存
Future<bool> clearCache();
}

View File

@@ -0,0 +1,92 @@
import 'package:equatable/equatable.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
/// 用户信息数据模型
class UserProfileModel extends Equatable {
const UserProfileModel({
required this.name,
required this.role,
required this.avatar,
required this.userId,
});
final String name;
final String role;
final String avatar;
final String userId;
/// 转换为实体
UserProfileEntity toEntity() {
return UserProfileEntity(
name: name,
role: role,
avatar: avatar,
userId: userId,
);
}
@override
List<Object?> get props => [name, role, avatar, userId];
}
/// 菜单项数据模型
class MenuItemModel extends Equatable {
const MenuItemModel({
required this.id,
required this.title,
required this.icon,
this.subTitle,
this.hasSwitch = false,
this.switchValue = false,
this.hasBadge = false,
this.badgeCount = 0,
});
final String id;
final String title;
final String icon;
final String? subTitle;
final bool hasSwitch;
final bool switchValue;
final bool hasBadge;
final int badgeCount;
/// 转换为实体
MenuItemEntity toEntity() {
return MenuItemEntity(
id: id,
title: title,
icon: icon,
subTitle: subTitle,
hasSwitch: hasSwitch,
switchValue: switchValue,
hasBadge: hasBadge,
badgeCount: badgeCount,
);
}
MenuItemModel copyWith({
String? id,
String? title,
String? icon,
String? subTitle,
bool? hasSwitch,
bool? switchValue,
bool? hasBadge,
int? badgeCount,
}) {
return MenuItemModel(
id: id ?? this.id,
title: title ?? this.title,
icon: icon ?? this.icon,
subTitle: subTitle ?? this.subTitle,
hasSwitch: hasSwitch ?? this.hasSwitch,
switchValue: switchValue ?? this.switchValue,
hasBadge: hasBadge ?? this.hasBadge,
badgeCount: badgeCount ?? this.badgeCount,
);
}
@override
List<Object?> get props => [id, title, icon, subTitle, hasSwitch, switchValue, hasBadge, badgeCount];
}

View File

@@ -0,0 +1,53 @@
import 'package:fpdart/fpdart.dart';
import 'package:maibu_satabot_v2/core/error/failure.dart';
import 'package:maibu_satabot_v2/features/v2/my/data/datasources/my_remote_datasource.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/repositories/my_repository.dart';
/// 我的页面仓储实现
class MyRepositoryImpl implements MyRepository {
MyRepositoryImpl(this._remoteDataSource);
final MyRemoteDataSource _remoteDataSource;
@override
Future<Either<Failure, UserProfileEntity>> getUserProfile() async {
try {
final model = await _remoteDataSource.getUserProfile();
return right(model.toEntity());
} catch (e) {
return left(ServerFailure('获取用户信息失败: $e'));
}
}
@override
Future<Either<Failure, List<MenuItemEntity>>> getMenuItems() async {
try {
final models = await _remoteDataSource.getMenuItems();
final entities = models.map((model) => model.toEntity()).toList();
return right(entities);
} catch (e) {
return left(ServerFailure('获取菜单列表失败: $e'));
}
}
@override
Future<Either<Failure, bool>> toggleNightMode(bool enabled) async {
try {
final result = await _remoteDataSource.toggleNightMode(enabled);
return right(result);
} catch (e) {
return left(ServerFailure('切换夜间模式失败: $e'));
}
}
@override
Future<Either<Failure, bool>> clearCache() async {
try {
final result = await _remoteDataSource.clearCache();
return right(result);
} catch (e) {
return left(ServerFailure('清除缓存失败: $e'));
}
}
}

View File

@@ -0,0 +1,32 @@
import 'package:maibu_satabot_v2/features/v2/my/data/datasources/my_remote_datasource.dart';
import 'package:maibu_satabot_v2/features/v2/my/data/datasources/impl/my_remote_datasource_impl.dart';
import 'package:maibu_satabot_v2/features/v2/my/data/repositories/my_repository_impl.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/repositories/my_repository.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/usecases/clear_cache_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/usecases/get_menu_items_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/usecases/toggle_night_mode_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/cubit/my_cubit.dart';
/// 我的页面依赖注入
class MyDependencyInjector {
/// 创建 MyCubit 实例
static MyCubit createMyCubit() {
// 创建数据源
final MyRemoteDataSource remoteDataSource = MyRemoteDataSourceImpl();
// 创建仓储
final MyRepository repository = MyRepositoryImpl(remoteDataSource);
// 创建用例
final GetMenuItemsUseCase getMenuItemsUseCase = GetMenuItemsUseCase(repository);
final ToggleNightModeUseCase toggleNightModeUseCase = ToggleNightModeUseCase(repository);
final ClearCacheUseCase clearCacheUseCase = ClearCacheUseCase(repository);
// 创建 Cubit
return MyCubit(
getMenuItemsUseCase: getMenuItemsUseCase,
toggleNightModeUseCase: toggleNightModeUseCase,
clearCacheUseCase: clearCacheUseCase,
);
}
}

View File

@@ -0,0 +1,81 @@
import 'package:equatable/equatable.dart';
/// 用户信息实体
class UserProfileEntity extends Equatable {
const UserProfileEntity({
required this.name,
required this.role,
required this.avatar,
required this.userId,
});
final String name;
final String role;
final String avatar;
final String userId;
@override
List<Object?> get props => [name, role, avatar, userId];
UserProfileEntity copyWith({
String? name,
String? role,
String? avatar,
String? userId,
}) {
return UserProfileEntity(
name: name ?? this.name,
role: role ?? this.role,
avatar: avatar ?? this.avatar,
userId: userId ?? this.userId,
);
}
}
/// 我的页面菜单项实体
class MenuItemEntity extends Equatable {
const MenuItemEntity({
required this.id,
required this.title,
required this.icon,
this.subTitle,
this.hasSwitch = false,
this.switchValue = false,
this.hasBadge = false,
this.badgeCount = 0,
});
final String id;
final String title;
final String icon;
final String? subTitle;
final bool hasSwitch;
final bool switchValue;
final bool hasBadge;
final int badgeCount;
@override
List<Object?> get props => [id, title, icon, subTitle, hasSwitch, switchValue, hasBadge, badgeCount];
MenuItemEntity copyWith({
String? id,
String? title,
String? icon,
String? subTitle,
bool? hasSwitch,
bool? switchValue,
bool? hasBadge,
int? badgeCount,
}) {
return MenuItemEntity(
id: id ?? this.id,
title: title ?? this.title,
icon: icon ?? this.icon,
subTitle: subTitle ?? this.subTitle,
hasSwitch: hasSwitch ?? this.hasSwitch,
switchValue: switchValue ?? this.switchValue,
hasBadge: hasBadge ?? this.hasBadge,
badgeCount: badgeCount ?? this.badgeCount,
);
}
}

View File

@@ -0,0 +1,18 @@
import 'package:fpdart/fpdart.dart';
import 'package:maibu_satabot_v2/core/error/failure.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
/// 我的页面仓储接口
abstract class MyRepository {
/// 获取用户信息
Future<Either<Failure, UserProfileEntity>> getUserProfile();
/// 获取菜单列表
Future<Either<Failure, List<MenuItemEntity>>> getMenuItems();
/// 切换夜间模式
Future<Either<Failure, bool>> toggleNightMode(bool enabled);
/// 清除缓存
Future<Either<Failure, bool>> clearCache();
}

View File

@@ -0,0 +1,14 @@
import 'package:fpdart/fpdart.dart';
import 'package:maibu_satabot_v2/core/error/failure.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/repositories/my_repository.dart';
/// 清除缓存用例
class ClearCacheUseCase {
ClearCacheUseCase(this._repository);
final MyRepository _repository;
Future<Either<Failure, bool>> call() async {
return await _repository.clearCache();
}
}

View File

@@ -0,0 +1,15 @@
import 'package:fpdart/fpdart.dart';
import 'package:maibu_satabot_v2/core/error/failure.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/repositories/my_repository.dart';
/// 获取菜单列表用例
class GetMenuItemsUseCase {
GetMenuItemsUseCase(this._repository);
final MyRepository _repository;
Future<Either<Failure, List<MenuItemEntity>>> call() async {
return await _repository.getMenuItems();
}
}

View File

@@ -0,0 +1,14 @@
import 'package:fpdart/fpdart.dart';
import 'package:maibu_satabot_v2/core/error/failure.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/repositories/my_repository.dart';
/// 切换夜间模式用例
class ToggleNightModeUseCase {
ToggleNightModeUseCase(this._repository);
final MyRepository _repository;
Future<Either<Failure, bool>> call(bool enabled) async {
return await _repository.toggleNightMode(enabled);
}
}

View File

@@ -0,0 +1,23 @@
library;
export 'domain/entities/my_entities.dart';
export 'domain/repositories/my_repository.dart';
export 'domain/usecases/get_menu_items_usecase.dart';
export 'domain/usecases/toggle_night_mode_usecase.dart';
export 'domain/usecases/clear_cache_usecase.dart';
export 'data/models/my_models.dart';
export 'data/datasources/my_remote_datasource.dart';
export 'data/datasources/impl/my_remote_datasource_impl.dart';
export 'data/repositories/my_repository_impl.dart';
export 'presentation/states/my_state.dart';
export 'presentation/cubit/my_cubit.dart';
export 'presentation/pages/my_page.dart';
export 'presentation/constants/my_constants.dart';
export 'presentation/routes/my_routes.dart';
export 'presentation/widgets/user_profile_card.dart';
export 'presentation/widgets/quick_action_card.dart';
export 'presentation/widgets/menu_item_card.dart';
export 'di/my_di.dart';

View File

@@ -0,0 +1,41 @@
/// 我的页面全局常量
/// 包含颜色、尺寸等全局配置
library;
import 'package:flutter/material.dart';
/// 颜色常量
class MyColors {
/// 主色调
static const Color primary = Color(0xFF165DFF);
/// 背景色
static const Color background = Color(0xFFF5F7FA);
/// 卡片背景色
static const Color cardBackground = Color(0xFFFFFFFF);
/// 主要文字色
static const Color textPrimary = Color(0xFF1D2129);
/// 次要文字色
static const Color textSecondary = Color(0xFF4E5969);
/// 辅助文字色
static const Color textTertiary = Color(0xFF86909C);
}
/// 尺寸常量
class MyDimensions {
/// 通用圆角
static const double borderRadius = 12.0;
/// 水平边距
static const double horizontalPadding = 16.0;
/// 模块间距
static const double moduleSpacing = 16.0;
/// 卡片阴影模糊半径
static const double cardShadowBlur = 8.0;
}

View File

@@ -0,0 +1,102 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/usecases/clear_cache_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/usecases/get_menu_items_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/usecases/toggle_night_mode_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/states/my_state.dart';
/// 我的页面 Cubit
class MyCubit extends Cubit<MyState> {
MyCubit({
required GetMenuItemsUseCase getMenuItemsUseCase,
required ToggleNightModeUseCase toggleNightModeUseCase,
required ClearCacheUseCase clearCacheUseCase,
}) : _getMenuItemsUseCase = getMenuItemsUseCase,
_toggleNightModeUseCase = toggleNightModeUseCase,
_clearCacheUseCase = clearCacheUseCase,
super(MyInitial());
final GetMenuItemsUseCase _getMenuItemsUseCase;
final ToggleNightModeUseCase _toggleNightModeUseCase;
final ClearCacheUseCase _clearCacheUseCase;
/// 加载数据
Future<void> loadData() async {
emit(MyLoading());
try {
final menuResult = await _getMenuItemsUseCase();
final menuItems = menuResult.fold(
(failure) => <MenuItemEntity>[],
(items) => items,
);
if (menuItems.isEmpty) {
emit(const MyError('加载菜单失败'));
return;
}
// 模拟用户信息(实际应从 Auth 模块获取)
final userProfile = UserProfileEntity(
name: '张工程师',
role: '运维工程师',
avatar: '',
userId: 'ENG2024001',
);
emit(MyLoaded(
userProfile: userProfile,
menuItems: menuItems,
));
} catch (e) {
emit(MyError('加载数据失败: $e'));
}
}
/// 切换夜间模式
Future<void> toggleNightMode(bool enabled) async {
final currentState = state;
if (currentState is MyLoaded) {
// 乐观更新 UI
emit(currentState.copyWith(isNightMode: enabled));
final result = await _toggleNightModeUseCase(enabled);
result.fold(
(failure) {
// 如果失败,回滚状态
emit(currentState.copyWith(isNightMode: !enabled));
emit(MyError('切换夜间模式失败'));
},
(_) {
// 成功,保持当前状态
},
);
}
}
/// 清除缓存
Future<void> clearCache() async {
final currentState = state;
if (currentState is! MyLoaded) return;
emit(MyLoading());
final result = await _clearCacheUseCase();
result.fold(
(failure) {
emit(MyError('清除缓存失败: ${failure.message}'));
},
(success) {
emit(currentState.copyWith(cacheSize: '0 MB'));
},
);
}
/// 刷新数据
Future<void> refresh() async {
await loadData();
}
}

View File

@@ -0,0 +1,173 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/services.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/cubit/my_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/states/my_state.dart';
import 'package:maibu_satabot_v2/features/v2/my/di/my_di.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/constants/my_constants.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/widgets/user_profile_card.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/widgets/quick_action_card.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/widgets/menu_item_card.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/pages/system_settings_page.dart';
/// 我的页面(100% 还原设计稿)
class MyPage extends StatelessWidget {
const MyPage({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => MyDependencyInjector.createMyCubit()..loadData(),
child: _MyPageContent(),
);
}
}
class _MyPageContent extends StatelessWidget {
const _MyPageContent();
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
),
child: Scaffold(
extendBodyBehindAppBar: true,
backgroundColor: MyColors.background,
body: BlocConsumer<MyCubit, MyState>(
listener: (context, state) {
if (state is MyError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.message)),
);
}
},
builder: (context, state) {
if (state is MyLoading) {
return const Center(
child: CircularProgressIndicator(color: MyColors.primary),
);
}
if (state is MyLoaded) {
final cubit = context.read<MyCubit>();
return Column(
children: [
// 用户信息卡片(延伸到状态栏)
UserProfileCard(
name: state.userProfile.name,
role: state.userProfile.role,
onTap: () {
// TODO: 跳转到个人信息页面
debugPrint('点击个人信息');
},
),
// 快捷入口卡片(负margin向上重叠)
Transform.translate(
offset: const Offset(0, -15),
child: QuickActionCard(
onMessageTap: () {
debugPrint('我的消息');
},
onFavoriteTap: () {
debugPrint('我的收藏');
},
onWorkOrderTap: () {
debugPrint('我的工单');
},
),
),
// 菜单列表(白色卡片)
Container(
margin: const EdgeInsets.only(top: 15, left: 16, right: 16, bottom: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: const Color(0x0D000000),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.5,
),
child: ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.zero,
itemCount: state.menuItems.length,
itemBuilder: (context, index) {
final item = state.menuItems[index];
return MenuItemCard(
item: item,
onTap: () => _handleMenuItemTap(context, cubit, item),
onSwitchChanged: item.hasSwitch
? (value) => cubit.toggleNightMode(value)
: null,
);
},
),
),
],
);
}
return const SizedBox.shrink();
},
),
),
);
}
/// 处理菜单项点击
void _handleMenuItemTap(BuildContext context, MyCubit cubit, dynamic item) {
switch (item.id) {
case 'offline_cache':
_showClearCacheDialog(context, cubit);
break;
case 'night_mode':
// 由 Switch 处理
break;
case 'system_settings':
// 跳转到系统设置页面
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SystemSettingsPage(),
),
);
break;
default:
debugPrint('点击菜单: ${item.title}');
// TODO: 根据 ID 跳转到对应页面
}
}
/// 显示清除缓存对话框
void _showClearCacheDialog(BuildContext context, MyCubit cubit) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('清除缓存'),
content: const Text('确定要清除所有缓存数据吗?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
TextButton(
onPressed: () {
Navigator.pop(context);
cubit.clearCache();
},
child: const Text('确定'),
),
],
),
);
}
}

View File

@@ -0,0 +1,284 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import 'package:maibu_satabot_v2/core/localization/locale_cubit.dart';
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
/// 系统设置综合页面
class SystemSettingsPage extends StatefulWidget {
const SystemSettingsPage({super.key});
@override
State<SystemSettingsPage> createState() => _SystemSettingsPageState();
}
class _SystemSettingsPageState extends State<SystemSettingsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F6F8),
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Color(0xFF1D2129)),
onPressed: () => Navigator.pop(context),
),
title: Text(
AppLocalizations.of(context).translate('my.settings'),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
centerTitle: true,
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
// Tab 设置
_buildTabSettingsSection(),
const SizedBox(height: 12),
// 语言设置
_buildLanguageSection(),
const SizedBox(height: 12),
// 退出登录
_buildLogoutButton(context),
const SizedBox(height: 20),
],
),
);
}
/// Tab 设置
Widget _buildTabSettingsSection() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Tab 设置',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 16),
BlocBuilder<TabConfigCubit, dynamic>(
builder: (context, state) {
if (state.runtimeType.toString() != 'TabConfigLoaded') {
return const Center(child: CircularProgressIndicator());
}
final tabs = state.config.items;
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: tabs.length,
itemBuilder: (context, index) {
final tab = tabs[index];
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Row(
children: [
Expanded(
child: Text(
tab.name,
style: const TextStyle(
fontSize: 14,
color: Color(0xFF1D2129),
),
),
),
Switch(
value: tab.isEnabled,
onChanged: (value) {
context.read<TabConfigCubit>().toggleTab(tab.id);
},
activeColor: const Color(0xFF165DFF),
),
],
),
);
},
);
},
),
],
),
);
}
/// 语言设置
Widget _buildLanguageSection() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(context).translate('my.language'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 16),
BlocBuilder<LocaleCubit, Locale>(
builder: (context, locale) {
return Column(
children: [
_buildLanguageOption(
AppLocalizations.of(context).translate('my.chinese'),
'zh',
locale.languageCode == 'zh',
() => context.read<LocaleCubit>().setLocale(const Locale('zh', 'CN')),
),
const SizedBox(height: 12),
_buildLanguageOption(
AppLocalizations.of(context).translate('my.english'),
'en',
locale.languageCode == 'en',
() => context.read<LocaleCubit>().setLocale(const Locale('en', 'US')),
),
],
);
},
),
],
),
);
}
Widget _buildLanguageOption(String label, String code, bool isSelected, VoidCallback onTap) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: isSelected ? const Color(0xFF165DFF).withOpacity(0.1) : Colors.transparent,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isSelected ? const Color(0xFF165DFF) : const Color(0xFFE5E6EB),
width: 1,
),
),
child: Row(
children: [
Expanded(
child: Text(
label,
style: TextStyle(
fontSize: 14,
color: isSelected ? const Color(0xFF165DFF) : const Color(0xFF1D2129),
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
),
),
),
if (isSelected)
const Icon(
Icons.check_circle,
color: Color(0xFF165DFF),
size: 20,
),
],
),
),
);
}
/// 退出登录按钮
Widget _buildLogoutButton(BuildContext context) {
return GestureDetector(
onTap: () {
_showLogoutDialog(context);
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
child: Center(
child: Text(
AppLocalizations.of(context).translate('login.logout'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFFF53F3F),
),
),
),
),
);
}
/// 显示退出登录确认对话框
void _showLogoutDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(AppLocalizations.of(context).translate('login.logout')),
content: const Text('确定要退出登录吗?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
TextButton(
onPressed: () async {
Navigator.pop(context);
// 执行退出登录逻辑
await GetIt.I<UserStorage>().deleteUser();
GetIt.I<AuthCubit>().logout();
context.go(RoutePaths.login);
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xFFF53F3F),
),
child: const Text('确定'),
),
],
),
);
}
}

View File

@@ -0,0 +1,13 @@
import 'package:go_router/go_router.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/pages/my_page.dart';
/// 我的页面路由配置
class MyRoutes {
static List<RouteBase> get routes => [
GoRoute(
path: 'my',
name: 'my',
builder: (context, state) => const MyPage(),
),
];
}

View File

@@ -0,0 +1,58 @@
import 'package:equatable/equatable.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
/// 我的页面状态基类
abstract class MyState extends Equatable {
const MyState();
@override
List<Object?> get props => [];
}
/// 初始状态
class MyInitial extends MyState {}
/// 加载中状态
class MyLoading extends MyState {}
/// 加载成功状态
class MyLoaded extends MyState {
const MyLoaded({
required this.userProfile,
required this.menuItems,
this.isNightMode = false,
this.cacheSize = '1.26 GB',
});
final UserProfileEntity userProfile;
final List<MenuItemEntity> menuItems;
final bool isNightMode;
final String cacheSize;
@override
List<Object?> get props => [userProfile, menuItems, isNightMode, cacheSize];
MyLoaded copyWith({
UserProfileEntity? userProfile,
List<MenuItemEntity>? menuItems,
bool? isNightMode,
String? cacheSize,
}) {
return MyLoaded(
userProfile: userProfile ?? this.userProfile,
menuItems: menuItems ?? this.menuItems,
isNightMode: isNightMode ?? this.isNightMode,
cacheSize: cacheSize ?? this.cacheSize,
);
}
}
/// 加载失败状态
class MyError extends MyState {
const MyError(this.message);
final String message;
@override
List<Object?> get props => [message];
}

View File

@@ -0,0 +1,118 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
/// 菜单项卡片组件(100% 还原设计稿)
class MenuItemCard extends StatelessWidget {
const MenuItemCard({
super.key,
required this.item,
this.onTap,
this.onSwitchChanged,
});
final MenuItemEntity item;
final VoidCallback? onTap;
final ValueChanged<bool>? onSwitchChanged;
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
height: 56,
child: GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: Row(
children: [
// 图标
Icon(
_getIconData(item.icon),
size: 20,
color: const Color(0xFF4E5969),
),
const SizedBox(width: 12),
// 标题
Expanded(
child: Text(
item.title,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Color(0xFF1D2129),
),
),
),
// 副标题或开关
if (item.subTitle != null) ...[
Text(
item.subTitle!,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF86909C),
),
),
const SizedBox(width: 6),
],
if (item.hasSwitch) ...[
Transform.scale(
scale: 0.85,
child: Switch(
value: item.switchValue,
onChanged: onSwitchChanged,
activeColor: const Color(0xFF165DFF),
activeTrackColor: const Color(0xFF165DFF).withOpacity(0.3),
inactiveThumbColor: const Color(0xFFC9CDD4),
inactiveTrackColor: const Color(0xFFE5E6EB),
),
),
],
Icon(
Icons.chevron_right,
color: const Color(0xFFC9CDD4),
size: 20,
),
],
),
),
),
),
// 分割线
Padding(
padding: const EdgeInsets.only(left: 48),
child: Divider(
height: 1,
thickness: 0.5,
color: const Color(0xFFF0F0F0),
),
),
],
);
}
/// 根据字符串获取 IconData
IconData _getIconData(String iconName) {
switch (iconName) {
case 'person':
return Icons.person_outline;
case 'notifications':
return Icons.notifications_outlined;
case 'cloud_download':
return Icons.cloud_download_outlined;
case 'dark_mode':
return Icons.dark_mode_outlined;
case 'settings':
return Icons.settings_outlined;
case 'help':
return Icons.help_outline;
case 'info':
return Icons.info_outline;
default:
return Icons.label_outline;
}
}
}

View File

@@ -0,0 +1,122 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/constants/my_constants.dart';
/// 快捷入口卡片组件(我的消息、我的收藏、我的工单)
class QuickActionCard extends StatelessWidget {
const QuickActionCard({
super.key,
required this.onMessageTap,
required this.onFavoriteTap,
required this.onWorkOrderTap,
});
final VoidCallback onMessageTap;
final VoidCallback onFavoriteTap;
final VoidCallback onWorkOrderTap;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.symmetric(vertical: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: const Color(0x0D000000),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// 我的消息
_buildQuickActionItem(
icon: Icons.notifications_outlined,
label: '我的消息',
onTap: onMessageTap,
showBadge: true,
),
// 分割线
Container(
width: 1,
height: 40,
color: const Color(0xFFF0F0F0),
),
// 我的收藏
_buildQuickActionItem(
icon: Icons.favorite_border,
label: '我的收藏',
onTap: onFavoriteTap,
),
// 分割线
Container(
width: 1,
height: 40,
color: const Color(0xFFF0F0F0),
),
// 我的工单
_buildQuickActionItem(
icon: Icons.assignment_outlined,
label: '我的工单',
onTap: onWorkOrderTap,
),
],
),
);
}
Widget _buildQuickActionItem({
required IconData icon,
required String label,
required VoidCallback onTap,
bool showBadge = false,
}) {
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: SizedBox(
width: 80,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
clipBehavior: Clip.none,
children: [
Icon(
icon,
size: 24,
color: MyColors.primary,
),
if (showBadge)
Positioned(
right: -4,
top: -4,
child: Container(
width: 12,
height: 12,
decoration: const BoxDecoration(
color: Color(0xFFFF4D4F),
shape: BoxShape.circle,
),
),
),
],
),
const SizedBox(height: 8),
Text(
label,
style: const TextStyle(
fontSize: 13,
color: MyColors.textSecondary,
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,99 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/constants/my_constants.dart';
/// 用户信息卡片组件(100% 还原设计稿)
class UserProfileCard extends StatelessWidget {
const UserProfileCard({
super.key,
required this.name,
required this.role,
this.onTap,
});
final String name;
final String role;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(20, 70, 20, 50),
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFF165DFF),
Color(0xFF0E42CC),
],
),
),
child: Row(
children: [
// 头像
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 2,
),
),
child: ClipOval(
child: Image.asset(
'assets/images/app_logo.png',
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
color: Colors.white,
child: Icon(
Icons.person,
size: 32,
color: const Color(0xFF165DFF),
),
);
},
),
),
),
const SizedBox(width: 14),
// 用户信息
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 0.5,
),
),
const SizedBox(height: 6),
Text(
role,
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(0.85),
letterSpacing: 0.3,
),
),
],
),
),
// 箭头
Icon(
Icons.chevron_right,
color: Colors.white.withOpacity(0.9),
size: 24,
),
],
),
);
}
}