Browse Source

feat(登录): 根据用户地区初始化默认登录方式

为中国大陆用户默认选择手机号登录(+86),非中国大陆用户默认选择邮箱登录
隐藏中国大陆用户的国家选择器和相关提示
调整社交登录按钮的显示逻辑
newdev_shunjiawei
lxm 1 year ago
parent
commit
e70d1c09e2
  1. 19
      lib/modules/login/controllers/login_controller.dart
  2. 48
      lib/modules/login/views/login_view.dart

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

@ -180,6 +180,21 @@ class LoginController extends GetxController {
{'name': '所罗门群岛', 'code': '+677', 'flag': '🇸🇧'}, {'name': '所罗门群岛', 'code': '+677', 'flag': '🇸🇧'},
]; ];
// 初始化默认选择的国家代码
void _initDefaultCountryCode() {
if (isChinaMainland.value) {
// 中国大陆用户默认选择+86
_selectedCountryCode.value = '+86';
_selectedCountryFlag.value = '🇨🇳';
loginType = 1; // 设置为手机号登录类型
} else {
// 非中国大陆用户默认选择邮箱
_selectedCountryCode.value = '';
_selectedCountryFlag.value = '✉️';
loginType = 0; // 设置为邮箱登录类型
}
}
// 状态管理 // 状态管理
final _viewState = LoginViewState.welcome.obs; final _viewState = LoginViewState.welcome.obs;
final _isLoading = false.obs; final _isLoading = false.obs;
@ -208,6 +223,9 @@ class LoginController extends GetxController {
isChinaMainland.value = isChinaMainland.value =
Get.deviceLocale?.countryCode?.toUpperCase() == 'CN'; Get.deviceLocale?.countryCode?.toUpperCase() == 'CN';
// 初始化默认国家代码
_initDefaultCountryCode();
_hasAcceptedPrivacy.value = _hasAcceptedPrivacy.value =
_storage.read('hasAcceptedPrivacy') ?? false; // 从本地存储中读取是否已接受隐私政策 _storage.read('hasAcceptedPrivacy') ?? false; // 从本地存储中读取是否已接受隐私政策
@ -1041,5 +1059,4 @@ class LoginController extends GetxController {
return false; return false;
} }
} }
} }

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

@ -161,13 +161,14 @@ class LoginView extends GetView<LoginController> {
), ),
), ),
SizedBox(height: 4.h), SizedBox(height: 4.h),
Text( if (!controller.isChinaMainland.value)
'loginTips'.tr, // 请使用手机号或邮箱登录/注册 Text(
style: TextStyle( 'loginTips'.tr, // 请使用手机号或邮箱登录/注册
fontSize: 14.sp, style: TextStyle(
color: isDarkMode ? Colors.grey[400] : Colors.black54, fontSize: 14.sp,
color: isDarkMode ? Colors.grey[400] : Colors.black54,
),
), ),
),
], ],
); );
} }
@ -214,11 +215,12 @@ class LoginView extends GetView<LoginController> {
color: isDarkMode ? Colors.white : Colors.black, color: isDarkMode ? Colors.white : Colors.black,
), ),
)), )),
Icon( if (!controller.isChinaMainland.value)
Icons.arrow_drop_down, Icon(
color: isDarkMode ? Colors.grey[400] : Colors.black54, Icons.arrow_drop_down,
size: 20.sp, color: isDarkMode ? Colors.grey[400] : Colors.black54,
), size: 20.sp,
),
], ],
), ),
), ),
@ -263,6 +265,10 @@ class LoginView extends GetView<LoginController> {
// 添加国家选择底部弹窗 // 添加国家选择底部弹窗
void _showCountryPicker(bool isDarkMode) { void _showCountryPicker(bool isDarkMode) {
// 中国大陆用户不显示国家选择器
if (controller.isChinaMainland.value) {
return;
}
Get.bottomSheet( Get.bottomSheet(
Container( Container(
height: 400.h, height: 400.h,
@ -477,14 +483,20 @@ class LoginView extends GetView<LoginController> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildSocialButton(FontAwesomeIcons.google, Colors.red, isDarkMode), if (controller.isChinaMainland.value) ...[
SizedBox(width: 24.w), _buildSocialButton(
_buildSocialButton( FontAwesomeIcons.weixin, Colors.green, isDarkMode),
FontAwesomeIcons.weixin, Colors.green, isDarkMode), SizedBox(width: 24.w)
] else ...[
_buildSocialButton(
FontAwesomeIcons.google, Colors.red, isDarkMode),
SizedBox(width: 24.w),
],
// Apple登录按钮(仅在iOS上显示) // Apple登录按钮(仅在iOS上显示)
if (GetPlatform.isIOS) ...[ if (GetPlatform.isIOS) ...[
SizedBox(width: 24.w), _buildSocialButton(
_buildSocialButton(FontAwesomeIcons.apple, Colors.black, isDarkMode), FontAwesomeIcons.apple, Colors.black, isDarkMode),
], ],
// SizedBox(width: 24.w), // SizedBox(width: 24.w),
// _buildSocialButton( // _buildSocialButton(
@ -492,7 +504,7 @@ class LoginView extends GetView<LoginController> {
// 根据配置显示游客登录按钮 // 根据配置显示游客登录按钮
if (controller.isGuestLoginVisible) ...[ if (controller.isGuestLoginVisible) ...[
SizedBox(width: 24.w), SizedBox(width: 24.w),
_buildSocialButton(FontAwesomeIcons.userSecret, Colors.grey, _buildSocialButton(FontAwesomeIcons.userSecret, Colors.black,
isDarkMode), // 游客登录按钮 isDarkMode), // 游客登录按钮
], ],
], ],

Loading…
Cancel
Save