From 63cfacad95b78072c7c29a4579a86b739d5a56e6 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Fri, 5 Dec 2025 17:27:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(explore):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=8E=A2=E7=B4=A2=E9=A1=B5=E9=9D=A2=E5=B8=83=E5=B1=80=E5=92=8C?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除未使用的搜索功能和FunctionScene类 简化AI功能列表和导航逻辑 调整探索页面布局为2x2网格 添加用量统计功能到主网格 --- .../controllers/explore_controller.dart | 175 +------ lib/modules/explore/views/explore_view.dart | 481 +++--------------- 2 files changed, 84 insertions(+), 572 deletions(-) diff --git a/lib/modules/explore/controllers/explore_controller.dart b/lib/modules/explore/controllers/explore_controller.dart index 6376e3fa4..ebd64067a 100644 --- a/lib/modules/explore/controllers/explore_controller.dart +++ b/lib/modules/explore/controllers/explore_controller.dart @@ -27,30 +27,7 @@ class AIFeature { }); } -class FunctionScene { - final String title; - final String description; - final IconData icon; - final Color startColor; - final Color endColor; - final Color iconColor; - final String targetRoute; - - FunctionScene({ - required this.title, - required this.description, - required this.icon, - required this.startColor, - required this.endColor, - required this.iconColor, - required this.targetRoute, - }); -} - class ExploreController extends GetxController { - // 搜索关键词 - final searchController = TextEditingController(); - // AI功能列表 final List aiFeatures = [ AIFeature( @@ -75,42 +52,6 @@ class ExploreController extends GetxController { agentId: 'simultaneous_interpreter', targetRoute: Routes.translationMiddleware, ), - // AIFeature( - // title: 'conferenceAssistant'.tr, // 商务会议助手 - // description: 'conferenceAssistantInfo'.tr, // 实时记录会议纪要,多语言翻译 - // icon: Icons.people, - // startColor: const Color(0xFFab47bc), - // endColor: const Color(0xFFec407a), - // iconBgColor: const Color(0xFFd81b60).withOpacity(0.2), - // iconColor: const Color(0xFFd81b60), - // agentId: 'meeting_assistant', - // targetRoute: Routes.meeting, - // ), - // AIFeature( - // title: 'aiGirlfriend'.tr, // 亲子陪伴 - // description: 'aiGirlfriendInfo'.tr, // 智能陪伴,随时聊天 - // icon: Icons.favorite, - // startColor: const Color(0xFFE91E63), - // endColor: const Color(0xFFFF5252), - // iconBgColor: const Color(0xFFE91E63).withOpacity(0.2), - // iconColor: const Color(0xFFE91E63), - // agentId: 'cyber_girlfriend', - // targetRoute: Routes.chat, - // ), - // AIFeature( - // title: 'healthConsultant'.tr, // 健康顾问 - // description: 'healthConsultantInfo'.tr, // 提供科学健康建议 - // icon: Icons.healing, - // startColor: const Color(0xFFFFC107), - // endColor: const Color(0xFFFF9800), - // iconBgColor: const Color(0xFFFFC107).withOpacity(0.2), - // iconColor: const Color(0xFFFFC107), - // agentId: 'health_advisor', - // targetRoute: Routes.chat, - // ), - ]; - - final List aiFeaturesWide = [ AIFeature( title: 'conferenceAssistant'.tr, // 商务会议助手 description: 'conferenceAssistantInfo'.tr, // 实时记录会议纪要,多语言翻译 @@ -122,90 +63,42 @@ class ExploreController extends GetxController { agentId: 'meeting_assistant', targetRoute: Routes.meeting, ), + AIFeature( + title: 'usageStats'.tr, + description: 'usageStatsInfo'.tr, + icon: Icons.analytics_outlined, + startColor: const Color(0xFF2196F3), // 科技蓝 + endColor: const Color(0xFF00BCD4), // 青蓝色 + iconBgColor: const Color(0xFF2196F3).withOpacity(0.2), + iconColor: const Color(0xFF2196F3), + agentId: 'usage_stats', + targetRoute: Routes.usageStats, + ) ]; - // 热门功能场景列表 - final List functionScenes = [ - FunctionScene( + final List aiFeaturesWide = [ + AIFeature( title: 'conferenceAssistant'.tr, // 商务会议助手 description: 'conferenceAssistantInfo'.tr, // 实时记录会议纪要,多语言翻译 icon: Icons.people, startColor: const Color(0xFFab47bc), endColor: const Color(0xFFec407a), + iconBgColor: const Color(0xFFd81b60).withOpacity(0.2), iconColor: const Color(0xFFd81b60), + agentId: 'meeting_assistant', targetRoute: Routes.meeting, ), - FunctionScene( - title: 'studyAssistant'.tr, // 语言学习助手 - description: 'studyAssistantInfo'.tr, // 发音纠正,实时练习口语 - icon: Icons.school, - startColor: const Color(0xFF4CAF50), - endColor: const Color(0xFF009688), - iconColor: const Color(0xFF4CAF50), - targetRoute: Routes.realtime, - ), - FunctionScene( - title: 'travelTranslator'.tr, // 旅行翻译助手 - description: 'travelTranslatorInfo'.tr, // 实时语音翻译,旅游景点介绍 - icon: Icons.language, - startColor: const Color(0xFFFFC107), - endColor: const Color(0xFFFF9800), - iconColor: const Color(0xFFFFC107), - targetRoute: '', - ), ]; - // 搜索功能 - void search() { - if (searchController.text.isEmpty) return; - - Get.snackbar( - 'search'.tr, // 搜索 - '${'beSearching'.tr} ${searchController.text}', // 正在搜索: - snackPosition: SnackPosition.TOP, - ); - - // 实际应用中,这里应该实现真正的搜索逻辑 - searchController.clear(); - } - // 点击AI功能 void onAIFeatureTap(int index) { if (index < 0 || index >= aiFeatures.length) return; final feature = aiFeatures[index]; - final agent = AgentProvider.getAgentById(feature.agentId); - - if (agent == null) { - Get.snackbar( - 'error'.tr, // 错误 - 'noAssistantFound'.tr, // 未找到对应的AI助手 - snackPosition: SnackPosition.TOP, - ); - return; - } + if (feature.targetRoute.isEmpty) return; // 根据目标路由进行跳转 - if (feature.targetRoute == Routes.chat) { - // 跳转到聊天页面 - Get.toNamed(feature.targetRoute, arguments: { - 'agentId': agent.id, - 'agentName': agent.name, - 'agentVoice': agent.voice, - 'agentAvatar': agent.avatarUrl, - 'agentSubtitle': agent.description, - 'systemPrompt': agent.systemPrompt, - 'welcomeMessage': agent.welcomeMessage, - }); - } else if (feature.targetRoute == Routes.translationMiddleware) { - // 跳转到翻译页面 - Get.toNamed(feature.targetRoute); - } else if (feature.targetRoute == Routes.agent) { - Get.toNamed(feature.targetRoute); - } else if (feature.targetRoute == Routes.meeting) { - // 跳转到会议页面 - Get.toNamed(feature.targetRoute); - } + Get.toNamed(feature.targetRoute); } // 点击AI功能(宽版本) @@ -235,42 +128,8 @@ class ExploreController extends GetxController { } } - // 点击功能场景 - void onFunctionSceneTap(int index) { - if (index < 0 || index >= functionScenes.length) return; - - final scene = functionScenes[index]; - - if (scene.targetRoute.isNotEmpty) { - Get.toNamed(scene.targetRoute); - } else { - Get.snackbar( - 'scene'.tr, // 场景 - '${'youHaveSelected'.tr} ${functionScenes[index].title}', // 您选择了: - snackPosition: SnackPosition.TOP, - ); - } - } - - // 尝试新功能 - void tryNewFeature() { - Get.snackbar( - 'newFunction'.tr, // 新功能 - '${'youChoseTry'.tr}${'aiSinger'.tr}', // 您选择了尝试 // AI歌手模式 - snackPosition: SnackPosition.TOP, - ); - - // 实际应用中,这里应该跳转到新功能页面 - } - // 跳转到用量统计页面 void goToUsageStats() { Get.toNamed(Routes.usageStats); } - - @override - void onClose() { - searchController.dispose(); - super.onClose(); - } } diff --git a/lib/modules/explore/views/explore_view.dart b/lib/modules/explore/views/explore_view.dart index c501ab04b..f4504e26e 100644 --- a/lib/modules/explore/views/explore_view.dart +++ b/lib/modules/explore/views/explore_view.dart @@ -25,7 +25,7 @@ class ExploreView extends GetView { child: SingleChildScrollView( //physics: const BouncingScrollPhysics(), child: Padding( - padding: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0.h), + padding: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 0.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -66,14 +66,6 @@ class ExploreView extends GetView { // AI功能列表 SizedBox(height: 24.h), _buildCustomAILayout(isDarkMode), - - // 热门功能场景 - SizedBox(height: 24.h), - //_buildFunctionScenesSection(isDarkMode), - - // 新功能推荐 - SizedBox(height: 24.h), - //_buildNewFeatureSection(isDarkMode), ], ), ), @@ -104,59 +96,27 @@ class ExploreView extends GetView { color: isDarkMode ? Colors.white : Colors.grey[800], ), ), - Container( - width: 32.w, - height: 32.w, - decoration: BoxDecoration( - color: isDarkMode - ? Colors.white.withOpacity(0.1) - : Colors.grey[200], - shape: BoxShape.circle, - ), - child: IconButton( - icon: Icon( - Icons.analytics_outlined, - size: 16.sp, - color: isDarkMode ? Colors.white : Colors.grey[700], - ), - padding: EdgeInsets.zero, - onPressed: controller.goToUsageStats, - ), - ), + // Container( + // width: 32.w, + // height: 32.w, + // decoration: BoxDecoration( + // color: isDarkMode + // ? Colors.white.withOpacity(0.1) + // : Colors.grey[200], + // shape: BoxShape.circle, + // ), + // child: IconButton( + // icon: Icon( + // Icons.analytics_outlined, + // size: 16.sp, + // color: isDarkMode ? Colors.white : Colors.grey[700], + // ), + // padding: EdgeInsets.zero, + // onPressed: controller.goToUsageStats, + // ), + // ), ], ), - - // // 搜索框 - // SizedBox(height: 16.h), - // Container( - // decoration: BoxDecoration( - // color: - // isDarkMode ? Colors.white.withOpacity(0.1) : Colors.grey[100], - // borderRadius: BorderRadius.circular(12.r), - // ), - // child: TextField( - // controller: controller.searchController, - // decoration: InputDecoration( - // hintText: 'searchAi'.tr, // 搜索AI功能... - // hintStyle: TextStyle( - // fontSize: 14.sp, - // color: isDarkMode ? Colors.grey[400] : Colors.grey[400], - // ), - // prefixIcon: Icon( - // Icons.search, - // size: 20.sp, - // color: isDarkMode ? Colors.grey[400] : Colors.grey[400], - // ), - // border: InputBorder.none, - // contentPadding: EdgeInsets.symmetric(vertical: 12.h), - // ), - // textInputAction: TextInputAction.search, - // onSubmitted: (_) => controller.search(), - // style: TextStyle( - // color: isDarkMode ? Colors.white : Colors.black, - // ), - // ), - // ), ], ), ); @@ -250,23 +210,8 @@ class ExploreView extends GetView { ); } - // 自定义AI功能布局:2x2网格,商务会议助手占据下方两个网格位置 + // 自定义AI功能布局:2x2网格 Widget _buildCustomAILayout(bool isDarkMode) { - // 找到AI全能助手 - final aiAssistantIndex = controller.aiFeatures.indexWhere( - (feature) => feature.agentId == 'personal_assistant', - ); - - // 找到同声传译 - final translationIndex = controller.aiFeatures.indexWhere( - (feature) => feature.agentId == 'simultaneous_interpreter', - ); - - // 找到商务会议助手(在aiFeaturesWide中) - final meetingFeature = controller.aiFeaturesWide.isNotEmpty - ? controller.aiFeaturesWide.first - : null; - return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -287,47 +232,65 @@ class ExploreView extends GetView { Row( children: [ // 左上角:AI全能助手 - if (aiAssistantIndex != -1) - Expanded( - child: AspectRatio( - aspectRatio: 1.0, // 正方形 - child: _buildAIFeatureItem( - controller.aiFeatures[aiAssistantIndex], - aiAssistantIndex, - isDarkMode, - ), + Expanded( + child: AspectRatio( + aspectRatio: 1.0, // 正方形 + child: _buildAIFeatureItem( + controller.aiFeatures[0], + 0, + isDarkMode, ), ), + ), SizedBox(width: 16.w), // 右上角:同声传译 - if (translationIndex != -1) - Expanded( - child: AspectRatio( - aspectRatio: 1.0, // 正方形 - child: _buildAIFeatureItem( - controller.aiFeatures[translationIndex], - translationIndex, - isDarkMode, - ), + Expanded( + child: AspectRatio( + aspectRatio: 1.0, // 正方形 + child: _buildAIFeatureItem( + controller.aiFeatures[1], + 1, + isDarkMode, ), ), + ), ], ), SizedBox(height: 16.h), - // 下层:商务会议助手(横跨整行) - if (meetingFeature != null) - AspectRatio( - aspectRatio: 2.0, // 宽高比2:1,横跨两个网格位置 - child: _buildAIFeatureItemWideForMeeting( - meetingFeature, - 0, // 使用固定索引,因为这是aiFeaturesWide中的项目 - isDarkMode, + // 下层:商务会议助手+用量统计 + Row( + children: [ + // 左下角:商务会议助手 + Expanded( + child: AspectRatio( + aspectRatio: 1.0, // 正方形 + child: _buildAIFeatureItem( + controller.aiFeatures[2], + 2, + isDarkMode, + ), + ), ), - ), + + SizedBox(width: 16.w), + + // 右下角:用量统计 + Expanded( + child: AspectRatio( + aspectRatio: 1.0, // 正方形 + child: _buildAIFeatureItem( + controller.aiFeatures[3], + 3, + isDarkMode, + ), + ), + ), + ], + ), ], ), ], @@ -417,121 +380,9 @@ class ExploreView extends GetView { ); } -//整行布局 - Widget _buildAIFeaturesWideSection(bool isDarkMode) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Text( - // 'aiFunction'.tr, // AI功能 - // style: TextStyle( - // fontSize: 18.sp, - // fontWeight: FontWeight.w600, - // color: isDarkMode ? Colors.white : Colors.grey[800], - // ), - // ), - // SizedBox(height: 16.h), - // 直接使用 Column 包裹宽版卡片 - Column( - children: controller.aiFeaturesWide.map((feature) { - return Padding( - padding: EdgeInsets.only(bottom: 16.h), // 卡片间距 - child: _buildAIFeatureItemWide( - feature, - controller.aiFeatures.indexOf(feature), - isDarkMode, - ), - ); - }).toList(), - ), - ], - ); - } - - // AI功能项(宽版本,用于横跨整行的AI全能助手) + // AI功能项(宽版本) Widget _buildAIFeatureItemWide( AIFeature feature, int index, bool isDarkMode) { - return GestureDetector( - onTap: () => controller.onAIFeatureTap(index), - child: Container( - padding: EdgeInsets.all(20.w), - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - feature.startColor.withOpacity(isDarkMode ? 0.3 : 0.3), - feature.endColor.withOpacity(isDarkMode ? 0.3 : 0.3), - ], - ), - borderRadius: BorderRadius.circular(20.r), - boxShadow: [ - BoxShadow( - color: isDarkMode - ? Colors.black.withOpacity(0.2) - : Colors.grey.withOpacity(0.1), - blurRadius: 8.w, - offset: const Offset(0, 4), - ), - ], - ), - child: Row( - children: [ - // 图标圆圈 - Container( - width: 48.w, - height: 48.w, - decoration: BoxDecoration( - color: feature.iconColor.withValues(alpha: 0.2), - shape: BoxShape.circle, - ), - child: Icon( - feature.icon, - size: 24.sp, - color: feature.iconColor, - ), - ), - SizedBox(width: 16.w), - // 文本内容 - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // 标题 - Text( - feature.title, - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w600, - color: isDarkMode ? Colors.white : Colors.grey[800], - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - SizedBox(height: 4.h), - // 描述 - Text( - feature.description, - style: TextStyle( - fontSize: 12.sp, - color: isDarkMode ? Colors.grey[400] : Colors.grey[600], - ), - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), - ], - ), - ), - ], - ), - ), - ); - } - - // AI功能项(宽版本,专门用于商务会议助手) - Widget _buildAIFeatureItemWideForMeeting( - AIFeature feature, int index, bool isDarkMode) { return GestureDetector( onTap: () => controller.onAIFeatureWideTap(index), child: Container( @@ -609,202 +460,4 @@ class ExploreView extends GetView { ), ); } - - // 热门功能场景部分 - Widget _buildFunctionScenesSection(bool isDarkMode) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Text( - // 'popularFunction'.tr, // 热门功能场景 - // style: TextStyle( - // fontSize: 18.sp, - // fontWeight: FontWeight.w600, - // color: isDarkMode ? Colors.white : Colors.grey[800], - // ), - // ), - // SizedBox(height: 16.h), - ListView.builder( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemCount: controller.functionScenes.length, - itemBuilder: (context, index) { - final scene = controller.functionScenes[index]; - return Padding( - padding: EdgeInsets.only(bottom: 16.h), - child: _buildFunctionSceneItem(scene, index, isDarkMode), - ); - }, - ), - ], - ); - } - - // 功能场景项 - Widget _buildFunctionSceneItem( - FunctionScene scene, int index, bool isDarkMode) { - return GestureDetector( - onTap: () => controller.onFunctionSceneTap(index), - child: Container( - padding: EdgeInsets.all(16.w), - decoration: BoxDecoration( - color: isDarkMode - ? Colors.white.withValues(alpha: 0.05) - : Colors.grey[100], - borderRadius: BorderRadius.circular(16.r), - boxShadow: [ - BoxShadow( - color: isDarkMode - ? Colors.black.withValues(alpha: 0.2) - : Colors.grey.withValues(alpha: 0.1), - blurRadius: 4, - offset: const Offset(0, 2), - ), - ], - ), - child: Row( - children: [ - // 图标 - Container( - width: 48.w, - height: 48.w, - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - scene.startColor.withOpacity(isDarkMode ? 0.3 : 0.3), - scene.endColor.withOpacity(isDarkMode ? 0.3 : 0.3), - ], - ), - borderRadius: BorderRadius.circular(12.r), - ), - child: Icon( - scene.icon, - size: 24.sp, - color: scene.iconColor, - ), - ), - SizedBox(width: 16.w), - - // 文本内容 - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - scene.title, - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w600, - color: isDarkMode ? Colors.white : Colors.grey[800], - ), - ), - SizedBox(height: 4.h), - Text( - scene.description, - style: TextStyle( - fontSize: 12.sp, - color: isDarkMode ? Colors.grey[400] : Colors.grey[600], - ), - ), - ], - ), - ), - ], - ), - ), - ); - } - - // 新功能推荐部分 - Widget _buildNewFeatureSection(bool isDarkMode) { - return Container( - padding: EdgeInsets.all(20.w), - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - const Color(0xFF9C27B0).withOpacity(isDarkMode ? 0.3 : 0.3), - const Color(0xFFE91E63).withOpacity(isDarkMode ? 0.3 : 0.3), - ], - ), - borderRadius: BorderRadius.circular(16.r), - boxShadow: [ - BoxShadow( - color: isDarkMode - ? Colors.black.withOpacity(0.2) - : Colors.grey.withOpacity(0.1), - blurRadius: 8, - offset: const Offset(0, 4), - ), - ], - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // 图标 - Container( - width: 48.w, - height: 48.w, - decoration: BoxDecoration( - color: const Color(0xFF9C27B0).withOpacity(0.2), - borderRadius: BorderRadius.circular(12.r), - ), - child: Icon( - Icons.lightbulb_outline, - size: 24.sp, - color: const Color(0xFF9C27B0), - ), - ), - SizedBox(height: 16.h), - - // 标题 - Text( - 'aiSinger'.tr, // AI歌手模式 - style: TextStyle( - fontSize: 20.sp, - fontWeight: FontWeight.bold, - color: isDarkMode ? Colors.white : Colors.grey[800], - ), - ), - SizedBox(height: 8.h), - - // 描述 - Text( - 'aiSingerInfo'.tr, // 用你喜欢的歌手声音演唱任何歌曲,甚至是你自己创作的歌曲 - style: TextStyle( - fontSize: 14.sp, - color: isDarkMode ? Colors.grey[300] : Colors.grey[600], - ), - ), - SizedBox(height: 16.h), - - // 按钮 - ElevatedButton( - onPressed: controller.tryNewFeature, - style: ElevatedButton.styleFrom( - backgroundColor: isDarkMode - ? const Color(0xFF9C27B0) - : Colors.white.withOpacity(0.2), - foregroundColor: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 10.h), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12.r), - ), - ), - child: Text( - 'tryNow'.tr, // 立即尝试 - style: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.w500, - color: isDarkMode ? Colors.white : Colors.grey[800], - ), - ), - ), - ], - ), - ); - } }