diff --git a/lib/core/translations/language/en_us.dart b/lib/core/translations/language/en_us.dart index d391ef32d..a68fdf01c 100644 --- a/lib/core/translations/language/en_us.dart +++ b/lib/core/translations/language/en_us.dart @@ -984,6 +984,8 @@ const Map enUS = { "phoneUser": "Phone User", "selectSourceLanguage": "Select Source Language", "selectTargetLanguage": "Select Target Language", + "me": "Me", //我 + "counterPart": "Counterpart", //对方 // 翻译历史页 "noTranslationHistory": "No translation history", diff --git a/lib/core/translations/language/zh_cn.dart b/lib/core/translations/language/zh_cn.dart index d56fccb27..37740085c 100644 --- a/lib/core/translations/language/zh_cn.dart +++ b/lib/core/translations/language/zh_cn.dart @@ -904,6 +904,8 @@ const Map zhCN = { "phoneUser": "手机用户", "selectSourceLanguage": "选择源语言", "selectTargetLanguage": "选择目标语言", + "me": "我", //我 + "counterPart": "对方", //对方 // 翻译历史页 (translation_history_view.dart) "noTranslationHistory": "暂无历史记录", diff --git a/lib/data/services/version_update_service.dart b/lib/data/services/version_update_service.dart index c7cef7841..d41b31441 100644 --- a/lib/data/services/version_update_service.dart +++ b/lib/data/services/version_update_service.dart @@ -83,6 +83,13 @@ class VersionUpdateService extends GetxService { final Logger _logger = Logger(); + // @override + // void onInit() { + // getCurrentVersion(); + // getCurrentPlatformInfo(); + // super.onInit(); + // } + /// 获取当前应用版本信息 Future getCurrentVersion() async { try { @@ -224,9 +231,14 @@ class VersionUpdateService extends GetxService { _latestVersion = appInfo.version; _updateUrl = appInfo.address; - // 设置游客登录显示状态 + // 设置游客登录显示状态(先用当前渠道结果作为回退,再用.env渠道覆盖以保持一致) _isShowTourists = appInfo.tourists; - _logger.d('从服务器获取游客登录配置: ${appInfo.tourists}'); + if (_channel != platformInfo.channel) { + //[4]当前渠道与.env渠道不同,需要从.env渠道获取游客登录配置 + await _refreshTouristsFromEnv(); + } + + _logger.d('从服务器获取游客登录配置(最终): ${_isShowTourists}'); // if (channelAppResponse.code != 0 || channelAppResponse.data == null) { // _logger.w('获取版本信息失败: ${channelAppResponse.msg}'); @@ -269,6 +281,30 @@ class VersionUpdateService extends GetxService { } } + /// 从.env文件刷新游客登录配置 + Future _refreshTouristsFromEnv() async { + try { + final envChannelName = dotenv.env['Channel']; + if (envChannelName == null || envChannelName.isEmpty) { + _logger.w('未配置.env Channel,沿用当前渠道的游客配置: ${_isShowTourists}'); + return; + } + final envChannel = UserChannel.fromName(envChannelName); + + final resp = await Api.getChannelApp({'channel': envChannel.value}); + if (resp != null && resp.containsKey('app')) { + final envAppInfo = AppInfo.fromJson(resp['app']); + _isShowTourists = envAppInfo.tourists; + _logger.d( + '游客登录配置已按.env渠道同步: ${envAppInfo.tourists} (channel=$envChannelName)'); + } else { + _logger.w('按.env渠道获取游客配置失败:响应为空或不含app字段'); + } + } catch (e) { + _logger.w('按.env渠道同步游客配置失败: $e'); + } + } + /// 判断是否需要强制更新 /// 当主版本号(第一位数字)不同时返回true bool _shouldForceUpdate(String current, String latest) { diff --git a/lib/modules/translation/controllers/translation_controller.dart b/lib/modules/translation/controllers/translation_controller.dart index 274d585d4..37e624063 100644 --- a/lib/modules/translation/controllers/translation_controller.dart +++ b/lib/modules/translation/controllers/translation_controller.dart @@ -212,10 +212,10 @@ class TranslationController extends GetxController with WidgetsBindingObserver { final sourceLanguageName = _languageManager.getChineseNameByAsrCode(item.sourceLanguageCode) ?? - '未知'; + 'unknown'; final targetLanguageName = _languageManager.getChineseNameByAsrCode(item.targetLanguageCode) ?? - '未知'; + 'unknown'; final data = FloatingWindowData( sourceText: item.sourceText, diff --git a/lib/modules/translation/views/translation_view.dart b/lib/modules/translation/views/translation_view.dart index 1a1fd9aad..09caa31c3 100644 --- a/lib/modules/translation/views/translation_view.dart +++ b/lib/modules/translation/views/translation_view.dart @@ -208,8 +208,9 @@ class TranslationView extends GetView { children: [ // 悬浮窗切换按钮(仅在支持的模式下显示) Obx(() { - if (controller.currentMode.value == 'call' || - controller.currentMode.value == 'audioVideo') { + if (Platform.isAndroid && + (controller.currentMode.value == 'call' || + controller.currentMode.value == 'audioVideo')) { return IconButton( icon: Icon( controller.isFloatingWindowEnabled.value @@ -269,106 +270,150 @@ class TranslationView extends GetView { }), ], bottom: PreferredSize( - preferredSize: Size.fromHeight(50.h), + preferredSize: Size.fromHeight( + controller.currentMode.value == 'call' ? 70.h : 50.h, + ), child: Padding( padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, + child: Column( + mainAxisSize: MainAxisSize.min, children: [ - // 源语言选择 - Expanded( - child: GestureDetector( - onTap: () => LanguageSelectionDialog.show(true, isDarkMode), - child: Container( - padding: - EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h), - decoration: BoxDecoration( - color: isDarkMode - ? Colors.white.withOpacity(0.1) - : Colors.grey[100], - borderRadius: BorderRadius.circular(16.r), + // 原语言选择行 + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // 源语言选择 + Expanded( + child: GestureDetector( + onTap: () => + LanguageSelectionDialog.show(true, isDarkMode), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 8.w, vertical: 4.h), + decoration: BoxDecoration( + color: isDarkMode + ? Colors.white.withOpacity(0.1) + : Colors.grey[100], + borderRadius: BorderRadius.circular(16.r), + ), + child: Obx(() => Text( + '${controller.sourceLanguage.value.split(' ')[0]}' + .tr, + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w600, + color: isDarkMode ? Colors.white : Colors.black, + ), + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, + )), + ), ), - child: Obx(() => Text( - '${controller.sourceLanguage.value.split(' ')[0]}' - .tr, // Just show the Chinese part - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w600, - color: isDarkMode ? Colors.white : Colors.black, - ), - textAlign: TextAlign.center, - overflow: TextOverflow.ellipsis, - )), ), - ), - ), - // 语言互换按钮 - GestureDetector( - onTap: controller.swapLanguages, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 8.w), - padding: EdgeInsets.all(4.r), - decoration: BoxDecoration( - color: isDarkMode - ? AppColors.primary.withOpacity(0.2) - : Colors.blue[50], - shape: BoxShape.circle, + // 语言互换按钮 + GestureDetector( + onTap: controller.swapLanguages, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 8.w), + padding: EdgeInsets.all(4.r), + decoration: BoxDecoration( + color: isDarkMode + ? AppColors.primary.withOpacity(0.2) + : Colors.blue[50], + shape: BoxShape.circle, + ), + child: Icon( + Icons.swap_horiz, + color: isDarkMode ? AppColors.primary : Colors.blue, + size: 20.sp, + ), + ), ), - child: Icon( - Icons.swap_horiz, - color: isDarkMode ? AppColors.primary : Colors.blue, - size: 20.sp, + + // 目标语言选择 + Expanded( + child: GestureDetector( + onTap: () => + LanguageSelectionDialog.show(false, isDarkMode), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 8.w, vertical: 4.h), + decoration: BoxDecoration( + color: isDarkMode + ? Colors.white.withOpacity(0.1) + : Colors.grey[100], + borderRadius: BorderRadius.circular(16.r), + ), + child: Obx(() => Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Flexible( + child: Text( + '${controller.targetLanguage.value.split(' ')[0]}' + .tr, + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w600, + color: isDarkMode + ? Colors.white + : Colors.black, + ), + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, + ), + ), + //只在通话翻译模式下显示电话图标 + if (controller.currentMode.value == 'call') ...[ + SizedBox(width: 4.w), + Icon( + Icons.phone_in_talk, + size: 20.sp, + color: isDarkMode + ? Colors.white70 + : Colors.grey[600], + ), + ], + ], + )), + ), + ), ), - ), + ], ), - // 目标语言选择 - Expanded( - child: GestureDetector( - onTap: () => LanguageSelectionDialog.show(false, isDarkMode), - child: Container( - padding: - EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h), - decoration: BoxDecoration( - color: isDarkMode - ? Colors.white.withOpacity(0.1) - : Colors.grey[100], - borderRadius: BorderRadius.circular(16.r), + // 通话模式下的“对方 / 我”标签行 + if (controller.currentMode.value == 'call') ...[ + SizedBox(height: 6.h), + Row( + children: [ + Expanded( + child: Text( + 'me'.tr, //我 + style: TextStyle( + fontSize: 12.sp, + color: isDarkMode ? Colors.white70 : Colors.black54, + fontWeight: FontWeight.w500, + ), + textAlign: TextAlign.center, + ), ), - child: Obx(() => Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Flexible( - child: Text( - '${controller.targetLanguage.value.split(' ')[0]}' - .tr, - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w600, - color: - isDarkMode ? Colors.white : Colors.black, - ), - textAlign: TextAlign.center, - overflow: TextOverflow.ellipsis, - ), - ), - //只在通话翻译模式下显示电话图标 - if (controller.currentMode.value == 'call') ...[ - SizedBox(width: 4.w), - Icon( - Icons.phone_in_talk, - size: 20.sp, - color: isDarkMode - ? Colors.white70 - : Colors.grey[600], - ), - ], - ], - )), - ), + // 预留与上方互换按钮大致等宽的间距,保证对齐 + SizedBox(width: 44.w), + Expanded( + child: Text( + 'counterPart'.tr, //对方 + style: TextStyle( + fontSize: 12.sp, + color: isDarkMode ? Colors.white70 : Colors.black54, + fontWeight: FontWeight.w500, + ), + textAlign: TextAlign.center, + ), + ), + ], ), - ), + ], ], ), ),