所有一级页面和不分二级页面
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
92
lib/features/v2/my/data/models/my_models.dart
Normal file
92
lib/features/v2/my/data/models/my_models.dart
Normal 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];
|
||||
}
|
||||
53
lib/features/v2/my/data/repositories/my_repository_impl.dart
Normal file
53
lib/features/v2/my/data/repositories/my_repository_impl.dart
Normal 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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user