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': '🇸🇧'},
];
// 初始化默认选择的国家代码
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 _isLoading = false.obs;
@ -208,6 +223,9 @@ class LoginController extends GetxController {
isChinaMainland.value =
Get.deviceLocale?.countryCode?.toUpperCase() == 'CN';
// 初始化默认国家代码
_initDefaultCountryCode();
_hasAcceptedPrivacy.value =
_storage.read('hasAcceptedPrivacy') ?? false; // 从本地存储中读取是否已接受隐私政策
@ -1041,5 +1059,4 @@ class LoginController extends GetxController {
return false;
}
}
}

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

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

Loading…
Cancel
Save