Browse Source

feat(usage): 添加AI聊天统计视图的切换功能

实现通过快速点击翻译统计标题三次来切换显示/隐藏AI聊天统计视图
修改底部导航栏根据显示状态动态调整项目
newdev_shunjiawei
lxm 11 months ago
parent
commit
01be27d6b2
  1. 19
      lib/modules/usage/controllers/translation_stats_controller.dart
  2. 29
      lib/modules/usage/controllers/usage_controller.dart
  3. 15
      lib/modules/usage/views/translation_stats_view.dart
  4. 32
      lib/modules/usage/views/usage_view.dart

19
lib/modules/usage/controllers/translation_stats_controller.dart

@ -2,6 +2,7 @@ import 'package:get/get.dart';
import '../../../data/services/usage_stats_service.dart'; import '../../../data/services/usage_stats_service.dart';
import '../../../data/models/translation_usage_stats.dart'; import '../../../data/models/translation_usage_stats.dart';
import '../../../core/utils/logger.dart'; import '../../../core/utils/logger.dart';
import 'usage_controller.dart';
class TranslationStatsController extends GetxController { class TranslationStatsController extends GetxController {
final UsageStatsService _usageService = Get.find<UsageStatsService>(); final UsageStatsService _usageService = Get.find<UsageStatsService>();
@ -297,6 +298,24 @@ class TranslationStatsController extends GetxController {
return '¥${cost.toStringAsFixed(2)}'; return '¥${cost.toStringAsFixed(2)}';
} }
int _titleTapCount = 0;
int _lastTitleTapTs = 0;
void onTitleTap() {
final now = DateTime.now().millisecondsSinceEpoch;
if (now - _lastTitleTapTs <= 800) {
_titleTapCount++;
} else {
_titleTapCount = 1;
}
_lastTitleTapTs = now;
if (_titleTapCount >= 3) {
_titleTapCount = 0;
final uc = Get.find<UsageController>();
uc.toggleAiChat(!uc.showAiChat.value);
}
}
String formatNumber(int number) { String formatNumber(int number) {
if (number < 1000) { if (number < 1000) {
return number.toString(); return number.toString();

29
lib/modules/usage/controllers/usage_controller.dart

@ -8,15 +8,34 @@ class UsageController extends GetxController {
late PageController pageController; late PageController pageController;
final RxInt pageIndex = 0.obs; final RxInt pageIndex = 0.obs;
final List<Widget> pageList = const [ final RxBool showAiChat = false.obs;
AiChatStatsView(),
TranslationStatsView(), List<Widget> get pageList => showAiChat.value
MeetingStatsView(), ? const [
]; AiChatStatsView(),
TranslationStatsView(),
MeetingStatsView(),
]
: const [
TranslationStatsView(),
MeetingStatsView(),
];
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
pageController = PageController(initialPage: 0); pageController = PageController(initialPage: 0);
} }
void toggleAiChat(bool enable) {
if (showAiChat.value == enable) return;
showAiChat.value = enable;
final int maxIndex = pageList.length - 1;
if (pageIndex.value > maxIndex) {
pageIndex.value = maxIndex;
pageController.jumpToPage(maxIndex);
} else {
pageController.jumpToPage(pageIndex.value);
}
}
} }

15
lib/modules/usage/views/translation_stats_view.dart

@ -33,12 +33,15 @@ class TranslationStatsView extends GetView<TranslationStatsController> {
), ),
backgroundColor: isDarkMode ? AppColors.darkBackground : Colors.white, backgroundColor: isDarkMode ? AppColors.darkBackground : Colors.white,
elevation: 0.5, elevation: 0.5,
title: Text( title: GestureDetector(
'翻译统计', onTap: controller.onTitleTap,
style: TextStyle( child: Text(
fontSize: 17.sp, '翻译统计',
fontWeight: FontWeight.w600, style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black, fontSize: 17.sp,
fontWeight: FontWeight.w600,
color: isDarkMode ? Colors.white : Colors.black,
),
), ),
), ),
centerTitle: true, centerTitle: true,

32
lib/modules/usage/views/usage_view.dart

@ -7,13 +7,6 @@ import '../controllers/usage_controller.dart';
class UsageView extends GetView<UsageController> { class UsageView extends GetView<UsageController> {
const UsageView({super.key}); const UsageView({super.key});
// 1. 将导航栏配置提取为常量,提高可维护性
static const _navItems = [
_NavItem(Icons.chat_bubble_outline, 'AI chat'),
_NavItem(Icons.translate, 'interpretation'),
_NavItem(Icons.people, 'meeting'),
];
// 2. 颜色配置集中管理 // 2. 颜色配置集中管理
Color _getBgColor(bool isDark) => Color _getBgColor(bool isDark) =>
isDark ? Colors.black : const Color(0xFFF9FAFB); isDark ? Colors.black : const Color(0xFFF9FAFB);
@ -28,11 +21,11 @@ class UsageView extends GetView<UsageController> {
return Scaffold( return Scaffold(
backgroundColor: isDarkMode ? AppColors.darkBackground : Colors.grey[50], backgroundColor: isDarkMode ? AppColors.darkBackground : Colors.grey[50],
body: PageView( body: Obx(() => PageView(
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
controller: controller.pageController, controller: controller.pageController,
children: controller.pageList, children: controller.pageList,
), )),
bottomNavigationBar: Obx( bottomNavigationBar: Obx(
() { () {
final currentIndex = controller.pageIndex.value; final currentIndex = controller.pageIndex.value;
@ -48,7 +41,16 @@ class UsageView extends GetView<UsageController> {
// 3. 添加安全区域适配(针对刘海屏) // 3. 添加安全区域适配(针对刘海屏)
child: BottomNavigationBar( child: BottomNavigationBar(
// 4. 使用生成的导航项 // 4. 使用生成的导航项
items: _navItems items: (controller.showAiChat.value
? const [
_NavItem(Icons.chat_bubble_outline, 'AI chat'),
_NavItem(Icons.translate, 'interpretation'),
_NavItem(Icons.people, 'meeting'),
]
: const [
_NavItem(Icons.translate, 'interpretation'),
_NavItem(Icons.people, 'meeting'),
])
.map((item) => BottomNavigationBarItem( .map((item) => BottomNavigationBarItem(
icon: Icon(item.icon), icon: Icon(item.icon),
activeIcon: Icon(item.icon, activeIcon: Icon(item.icon,
@ -70,8 +72,8 @@ class UsageView extends GetView<UsageController> {
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
// 7. 增加图标和文字的间距 // 7. 增加图标和文字的间距
iconSize: 22.w, // 响应式图标尺寸 iconSize: 22.w, // 响应式图标尺寸
selectedLabelStyle: TextStyle(height: 1.5), // 文字垂直间距 selectedLabelStyle: TextStyle(height: 1.5.sp), // 文字垂直间距
unselectedLabelStyle: TextStyle(height: 1.5), unselectedLabelStyle: TextStyle(height: 1.5.sp),
), ),
); );
}, },

Loading…
Cancel
Save