Browse Source

feat(登录): 添加语言代码支持并优化登录请求参数

在登录控制器中添加语言代码字段,并调整登录API请求参数结构,将版本号、渠道等信息从phonemodel中分离出来作为独立参数传递。同时在闪屏控制器中添加版本服务依赖,用于在获取登录token时传递当前版本号。
newdev_shunjiawei
lxm 1 year ago
parent
commit
490d3f4a55
  1. 15
      lib/modules/login/controllers/login_controller.dart
  2. 7
      lib/modules/splash/controllers/splash_controller.dart

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

@ -37,6 +37,7 @@ class LoginController extends GetxController {
String _deviceId = '';
String _appVersion = ''; // APP版本号
String _countryCode = ''; // 国家代码
String _languageCode = ''; // 语言代码
UserChannel _userChannel = UserChannel.OFFICIAL; // 默认渠道
final isChinaMainland = false.obs; //是否中国大陆地区
@ -310,6 +311,10 @@ class LoginController extends GetxController {
_countryCode = Get.locale?.countryCode ?? 'Unknown';
Logger().d('countryCode: $_countryCode');
// 获取语言代码
_languageCode = Get.locale?.languageCode ?? 'Unknown';
Logger().d('languageCode: $_languageCode');
// 获取用户渠道(根据平台和设备信息确定)
_userChannel = versionService.cachedChannel;
Logger().d('userChannel: ${_userChannel.value}');
@ -317,6 +322,8 @@ class LoginController extends GetxController {
Logger().e('获取APP信息失败: $e');
_appVersion = 'Unknown';
_countryCode = 'Unknown';
_languageCode = 'Unknown';
_userChannel = UserChannel.UNKNOWN;
}
}
@ -790,8 +797,7 @@ class LoginController extends GetxController {
"stype": loginType,
"vcode": "",
"ttoken": "",
"phonemodel":
_appVersion + _countryCode + _userChannel.toString(),
"phonemodel": _countryCode + _userChannel.toString(),
"phonemac": _deviceId,
"name": "",
"avatar": "",
@ -834,10 +840,13 @@ class LoginController extends GetxController {
"stype": params["stype"],
"vcode": params["vcode"],
"ttoken": params["ttoken"],
"phonemodel": _appVersion + _countryCode + _userChannel.toString(),
"phonemodel": _countryCode,
"phonemac": params["phonemac"],
"name": params["name"],
"avatar": params["avatar"],
"language": _languageCode,
"channel": _userChannel.toString(),
"version": _appVersion,
}).timeout(
const Duration(seconds: 30), // 30秒超时
onTimeout: () {

7
lib/modules/splash/controllers/splash_controller.dart

@ -21,6 +21,8 @@ class SplashController extends GetxController {
final GetStorage _storage = GetStorage();
static const String _tag = 'SplashCtrl';
final versionService = VersionUpdateService.to;
// 进度条动画控制
final _loadingProgress = 0.0.obs;
double get loadingProgress => _loadingProgress.value;
@ -259,7 +261,10 @@ class SplashController extends GetxController {
/// 异步获取登录Token
Future<bool> getLoginToken() async {
try {
final response = await Api.tokenlogin();
final appVersion = versionService.cachedAppVersion;
final response = await Api.tokenlogin({
'version': appVersion,
});
if (response?['user'] != null && response['user'] != '') {
final user = User.fromJson(response);
await _storage.write('user_info', user.toJson());

Loading…
Cancel
Save