Browse Source

手机登陆

weicu
fdp 2 years ago
parent
commit
dc73c789b9
  1. 51
      lib/modules/login/controllers/login_controller.dart

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

@ -27,10 +27,10 @@ class LoginController extends GetxController {
String get selectedCountryCode => _selectedCountryCode.value; String get selectedCountryCode => _selectedCountryCode.value;
String get selectedCountryFlag => _selectedCountryFlag.value; String get selectedCountryFlag => _selectedCountryFlag.value;
// 预设国家编码列表 // 预设国家编码列表
final List<Map<String, String>> countryCodes = [ final List<Map<String, String>> countryCodes = [
{'name': '邮箱', 'code': '', 'flag': '✉️'}, // 保持首位 {'name': '邮箱', 'code': '', 'flag': '✉️'}, // 保持首位
{'name': '中国', 'code': '+86', 'flag': '🇨🇳'}, // 保持第二位 {'name': '中国', 'code': '+86', 'flag': '🇨🇳'}, // 保持第二位
// 按国家代码数字升序排列(去除+号后排序) // 按国家代码数字升序排列(去除+号后排序)
{'name': '俄罗斯', 'code': '+7', 'flag': '🇷🇺'}, {'name': '俄罗斯', 'code': '+7', 'flag': '🇷🇺'},
{'name': '英国', 'code': '+44', 'flag': '🇬🇧'}, {'name': '英国', 'code': '+44', 'flag': '🇬🇧'},
@ -59,13 +59,12 @@ class LoginController extends GetxController {
{'name': '阿根廷', 'code': '+54', 'flag': '🇦🇷'}, {'name': '阿根廷', 'code': '+54', 'flag': '🇦🇷'},
{'name': '澳大利亚', 'code': '+61', 'flag': '🇦🇺'}, {'name': '澳大利亚', 'code': '+61', 'flag': '🇦🇺'},
{'name': '新西兰', 'code': '+64', 'flag': '🇳🇿'}, {'name': '新西兰', 'code': '+64', 'flag': '🇳🇿'},
// 中国地区(保持最后) // 中国地区(保持最后)
{'name': '中国香港', 'code': '+852', 'flag': '🇭🇰'}, {'name': '中国香港', 'code': '+852', 'flag': '🇭🇰'},
{'name': '中国澳门', 'code': '+853', 'flag': '🇲🇴'}, {'name': '中国澳门', 'code': '+853', 'flag': '🇲🇴'},
{'name': '中国台湾', 'code': '+886', 'flag': '🇹🇼'}, {'name': '中国台湾', 'code': '+886', 'flag': '🇹🇼'},
]; ];
// 状态管理 // 状态管理
final _viewState = LoginViewState.welcome.obs; final _viewState = LoginViewState.welcome.obs;
@ -248,8 +247,8 @@ class LoginController extends GetxController {
if (isEmialContactController() || isPhoneContactController()) { if (isEmialContactController() || isPhoneContactController()) {
_startCountdown(); _startCountdown();
var response = await Api.getCode({ var response = await Api.getCode({
"addr": contactController.text, "addr": selectedCountryCode + contactController.text,
"vtype": 0, "vtype": loginType,
}); });
if (response != null) { if (response != null) {
print("请求后台数据验证码params=${response}"); print("请求后台数据验证码params=${response}");
@ -295,8 +294,8 @@ class LoginController extends GetxController {
// 检查每个元素是否为单个字母或数字字符 // 检查每个元素是否为单个字母或数字字符
final text = contactController.text; final text = contactController.text;
return (text.length > 5 && return (text.length > 5 &&
RegExp(r'^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') RegExp(r'^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$')
.hasMatch(text)); .hasMatch(text));
} }
// 检查手机号码格式 // 检查手机号码格式
@ -310,7 +309,7 @@ class LoginController extends GetxController {
bool isVerificationCodeComplete() { bool isVerificationCodeComplete() {
// 检查每个元素是否为单个字母或数字字符 // 检查每个元素是否为单个字母或数字字符
final text = verificationCodeController.text; final text = verificationCodeController.text;
print("数据获取Facebook${text.length}"); print("数据获取Facebook${text.length}");
return text.length == 4 && RegExp(r'^[0-9]+$').hasMatch(text); return text.length == 4 && RegExp(r'^[0-9]+$').hasMatch(text);
} }
@ -323,7 +322,7 @@ class LoginController extends GetxController {
// 模拟验证过程 // 模拟验证过程
switch (loginType) { switch (loginType) {
case 0 || 1: case 0:
{ {
if (!isVerificationCodeComplete()) { if (!isVerificationCodeComplete()) {
Get.snackbar( Get.snackbar(
@ -337,7 +336,32 @@ class LoginController extends GetxController {
} }
requestLogin({ requestLogin({
"mail": contactController.text, "mail": contactController.text,
"phone": "", "phone": selectedCountryCode + contactController.text,
"stype": loginType,
"vcode": verificationCodeController.text,
"ttoken": "",
"phonemodel": "",
"phonemac": "",
"name": "",
"avatar": "",
});
break;
}
case 1:
{
if (!isVerificationCodeComplete()) {
Get.snackbar(
'提示',
'请输入完整的验证码',
snackPosition: SnackPosition.TOP,
backgroundColor: Colors.red.withOpacity(0.1),
colorText: Colors.red,
);
break;
}
requestLogin({
"mail": "",
"phone": selectedCountryCode + contactController.text,
"stype": loginType, "stype": loginType,
"vcode": verificationCodeController.text, "vcode": verificationCodeController.text,
"ttoken": "", "ttoken": "",
@ -348,7 +372,6 @@ class LoginController extends GetxController {
}); });
break; break;
} }
case 4: case 4:
{ {
print("数据获取Facebook"); print("数据获取Facebook");

Loading…
Cancel
Save