Browse Source

feat(登录): 添加游客登录功能配置支持

- 在AppInfo模型中添加tourists字段用于控制游客登录显示
- 修改登录页面根据配置显示/隐藏游客登录按钮
- 在LoginController中添加游客登录状态检查逻辑
- 添加版本信息和渠道相关字段用于后续扩展
weicu
lxm 1 year ago
parent
commit
9b1897b18c
  1. 2
      lib/data/models/appconfig_model.g.dart
  2. 15
      lib/data/models/channel_app_model.dart
  3. 2
      lib/data/models/channel_app_model.g.dart
  4. 1
      lib/data/services/version_update_service.dart
  5. 67
      lib/modules/login/controllers/login_controller.dart
  6. 9
      lib/modules/login/views/login_view.dart
  7. 2
      lib/modules/meeting/views/generate_bottom_sheet.dart

2
lib/data/models/appconfig_model.g.dart

@ -61,7 +61,7 @@ Map<String, dynamic> _$DBAgentToJson(DBAgent instance) => <String, dynamic>{
DBMCPServer _$DBMCPServerFromJson(Map<String, dynamic> json) => DBMCPServer(
servername: json['servername'] as String,
url: json['url'] as String,
tools: json['tools'] as String? ?? '',
tools: json['tools'] as String,
);
Map<String, dynamic> _$DBMCPServerToJson(DBMCPServer instance) =>

15
lib/data/models/channel_app_model.dart

@ -61,11 +61,16 @@ class AppInfo {
@JsonKey(name: 'version')
final String version;
/// 是否显示游客登录
@JsonKey(name: 'tourists')
final bool tourists;
const AppInfo({
required this.address,
required this.channel,
required this.description,
required this.version,
required this.tourists,
});
factory AppInfo.fromJson(Map<String, dynamic> json) =>
@ -104,8 +109,10 @@ class VersionUpdateInfo {
enum UpdateType {
/// 无需更新
none,
/// 可选更新
optional,
/// 强制更新
force,
}
@ -114,20 +121,28 @@ enum UpdateType {
enum AppStoreType {
/// iOS App Store
appStore,
/// Google Play
googlePlay,
/// 华为应用市场
huawei,
/// 小米应用商店
xiaomi,
/// OPPO软件商店
oppo,
/// vivo应用商店
vivo,
/// 荣耀应用市场
honor,
/// 官网下载
official,
/// 未知
unknown,
}

2
lib/data/models/channel_app_model.g.dart

@ -37,6 +37,7 @@ AppInfo _$AppInfoFromJson(Map<String, dynamic> json) => AppInfo(
channel: json['channel'] as String,
description: json['description'] as String,
version: json['version'] as String,
tourists: json['tourists'] as bool,
);
Map<String, dynamic> _$AppInfoToJson(AppInfo instance) => <String, dynamic>{
@ -44,4 +45,5 @@ Map<String, dynamic> _$AppInfoToJson(AppInfo instance) => <String, dynamic>{
'channel': instance.channel,
'description': instance.description,
'version': instance.version,
'tourists': instance.tourists,
};

1
lib/data/services/version_update_service.dart

@ -152,6 +152,7 @@ class VersionUpdateService extends GetxService {
// final appInfo = channelAppResponse.data!.app;
final hasUpdate = _compareVersions(currentVersion, appInfo.version);
//final isShowTourists = appInfo.tourists; // 获取是否显示游客登录的标志
return VersionUpdateInfo(
hasUpdate: hasUpdate,

67
lib/modules/login/controllers/login_controller.dart

@ -14,17 +14,42 @@ import '../../common/webview_page.dart';
import 'package:get_storage/get_storage.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';
import 'package:package_info_plus/package_info_plus.dart';
import '../../../data/services/version_update_service.dart';
enum LoginViewState {
welcome, // 欢迎页面
verification // 验证码页面
}
// 用户渠道枚举
enum UserChannel {
UNKNOWN(0), // 未知渠道
CHINA_HUAWEI(1), // 中国-华为
CHINA_XIAOMI(2), // 中国-小米
CHINA_OPPO(3), // 中国-OPPO
CHINA_VIVO(4), // 中国-VIVO
CHINA_HONOR(5), // 中国-荣耀
OFFICIAL(100), // 官方渠道
GLOBAL_APPLE(101), // 全球-苹果
GLOBAL_GOOGLE(102); // 全球-谷歌
const UserChannel(this.value);
final int value;
}
class LoginController extends GetxController {
static LoginController get to => Get.find();
final GetStorage _storage = GetStorage();
// 添加游客登录显示状态
final _isGuestLoginVisible = false.obs;
bool get isGuestLoginVisible => _isGuestLoginVisible.value;
String _deviceId = '';
String _appVersion = ''; // APP版本号
String _countryCode = ''; // 国家代码
UserChannel _userChannel = UserChannel.OFFICIAL; // 默认渠道
final _hasAcceptedPrivacy = false.obs;
bool get hasAcceptedPrivacy => _hasAcceptedPrivacy.value;
@ -189,6 +214,8 @@ class LoginController extends GetxController {
});
_initDeviceInfo();
_initAppInfo(); // 新增:初始化APP信息
_checkGuestLoginConfig(); // 检查游客登录配置
}
@override
@ -198,6 +225,23 @@ class LoginController extends GetxController {
super.onClose();
}
// 检查游客登录配置
Future<void> _checkGuestLoginConfig() async {
try {
final versionService = VersionUpdateService.to;
final updateInfo = await versionService.checkForUpdate();
if (updateInfo.appInfo != null) {
_isGuestLoginVisible.value = updateInfo.appInfo!.tourists;
Logger().d('游客登录显示状态: ${_isGuestLoginVisible.value}');
}
} catch (e) {
Logger().e('检查游客登录配置失败: $e');
// 默认不显示游客登录
_isGuestLoginVisible.value = false;
}
}
// 显示隐私政策弹窗
void _showPrivacyDialog() {
// 获取当前主题模式
@ -378,6 +422,29 @@ class LoginController extends GetxController {
}
}
// 新增:初始化APP信息(版本号、渠道、国家代码)
Future<void> _initAppInfo() async {
try {
// 获取APP版本号
final packageInfo = await PackageInfo.fromPlatform();
_appVersion = '${packageInfo.version}+${packageInfo.buildNumber}';
Logger().d('appVersion: $_appVersion');
// 获取国家代码
_countryCode = Get.locale?.countryCode ?? 'Unknown';
Logger().d('countryCode: $_countryCode');
// 获取用户渠道(根据平台和设备信息确定)
_userChannel = UserChannel.UNKNOWN;
Logger().d('userChannel: ${_userChannel.value}');
} catch (e) {
Logger().e('获取APP信息失败: $e');
_appVersion = 'Unknown';
_countryCode = 'Unknown';
_userChannel = UserChannel.UNKNOWN;
}
}
// 更新选中的国家编码
void updateCountryCode(String code, String flag) {
_selectedCountryCode.value = code;

9
lib/modules/login/views/login_view.dart

@ -484,9 +484,12 @@ class LoginView extends GetView<LoginController> {
SizedBox(width: 24.w),
_buildSocialButton(
FontAwesomeIcons.facebook, Colors.blue, isDarkMode),
SizedBox(width: 24.w),
_buildSocialButton(FontAwesomeIcons.userSecret, Colors.black,
isDarkMode), //添加游客登录按钮
// 根据配置显示游客登录按钮
if (controller.isGuestLoginVisible) ...[
SizedBox(width: 24.w),
_buildSocialButton(FontAwesomeIcons.userSecret, Colors.black,
isDarkMode), // 游客登录按钮
],
],
),
],

2
lib/modules/meeting/views/generate_bottom_sheet.dart

@ -1,4 +1,4 @@
import 'package:deep_voice/data/services/db/sqflite_api.dart';
import '../../../data/services/db/sqflite_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

Loading…
Cancel
Save