diff --git a/lib/pages/login_page/account/bloc/login_account_bloc.dart b/lib/pages/login_page/account/bloc/login_account_bloc.dart index 5617a32..70d3907 100644 --- a/lib/pages/login_page/account/bloc/login_account_bloc.dart +++ b/lib/pages/login_page/account/bloc/login_account_bloc.dart @@ -58,18 +58,18 @@ class LoginAccountBloc extends Bloc { Stream _mapLoginTypeVcodeEventToState(LoginAccountTypeVcodeEvent event) async* { var result = await repository.loginTypeVcode(event); if (!EmptyUtil.isEmpty(result)) - yield LoginAccountTypeVcodeLoginSuccessState(model: result); + yield LoginAccountLoginSuccessState(model: result); else - yield LoginAccountTypeVcodeLoginErrorState(); + yield LoginAccountLoginErrorState(); } /// 密码登陆 Stream _mapLoginTypePassEventToState(LoginAccountTypePasswordEvent event) async* { var result = await repository.loginTypePass(event); if(!EmptyUtil.isEmpty(result)) - yield LoginAccountTypeVcodeLoginSuccessState(model: result); + yield LoginAccountLoginSuccessState(model: result); else - yield LoginAccountTypeVcodeLoginErrorState(); + yield LoginAccountLoginErrorState(); } } diff --git a/lib/pages/login_page/account/bloc/login_account_state.dart b/lib/pages/login_page/account/bloc/login_account_state.dart index a98673a..0d85a8b 100644 --- a/lib/pages/login_page/account/bloc/login_account_state.dart +++ b/lib/pages/login_page/account/bloc/login_account_state.dart @@ -43,19 +43,19 @@ class LoginAccountGetVcodeErrorState extends LoginAccountState { const LoginAccountGetVcodeErrorState({this.msg}); } -/// 验证码登陆成功 -class LoginAccountTypeVcodeLoginSuccessState extends LoginAccountState { +/// 登陆成功 +class LoginAccountLoginSuccessState extends LoginAccountState { final UserInfoModel model; - const LoginAccountTypeVcodeLoginSuccessState({@required this.model}); + const LoginAccountLoginSuccessState({@required this.model}); @override List get props => [this.model]; } -/// 验证码登陆失败 -class LoginAccountTypeVcodeLoginErrorState extends LoginAccountState { +/// 登陆失败 +class LoginAccountLoginErrorState extends LoginAccountState { final String msg; - const LoginAccountTypeVcodeLoginErrorState({this.msg}); -} + const LoginAccountLoginErrorState({this.msg}); +} \ No newline at end of file diff --git a/lib/pages/login_page/account/login_account_page.dart b/lib/pages/login_page/account/login_account_page.dart index d795b76..4ff4c8e 100644 --- a/lib/pages/login_page/account/login_account_page.dart +++ b/lib/pages/login_page/account/login_account_page.dart @@ -52,6 +52,8 @@ class _LoginAccountPageContianerState extends State i FocusNode _phoneFN; FocusNode _passFN; FocusNode _vcodeFN; + // 是否登录中 + bool _isLogging = false; /// 跳转到邀请码页面 void _openInvitePage() { @@ -67,11 +69,7 @@ class _LoginAccountPageContianerState extends State i /// 登陆成功页面 void _openLoginSuccessPage() { RouterUtil.hideKeyboard(context); - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)), - (Route route) => false, - ); + Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)), (Route route) => false,); } /// 返回上一页 @@ -84,14 +82,17 @@ class _LoginAccountPageContianerState extends State i /// 登陆 void _submitOnClick() { print('登陆'); - if (_checkParam(true)) { + if (_checkParam(true) && !_isLogging) { + setState(() { + _isLogging = true; + }); if (_useVcode) { - BlocProvider.of(context) - .add(LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? '')); + BlocProvider.of(context).add(LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? '')); } else { - BlocProvider.of(context) - .add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', password: _passEdController?.text?.toString()?.trim() ?? '')); + BlocProvider.of(context).add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', password: _passEdController?.text?.toString()?.trim() ?? '')); } + }else{ + Logger.log('参数有误 或者 正在登录中。。。'); } } @@ -255,16 +256,20 @@ class _LoginAccountPageContianerState extends State i Widget build(BuildContext context) { return BlocConsumer( listener: (context, state) { - if (state is LoginAccountTypeVcodeLoginSuccessState) {} + if (state is LoginAccountLoginSuccessState) {} }, buildWhen: (prev, current) { - // 验证码登陆失败 - if (current is LoginAccountTypeVcodeLoginErrorState) { + // 登陆失败 + if (current is LoginAccountLoginErrorState) { // Fluttertoast.showToast(msg: '登陆失败'); + setState(() { + _isLogging = false; + }); + return false; } - // 验证码登陆成功 - if (current is LoginAccountTypeVcodeLoginSuccessState) { + // 登陆成功 + if (current is LoginAccountLoginSuccessState) { /// 缓存登陆数据 Provider.of(context, listen: false)?.setUserInfo(current.model); if (current?.model?.registerInviteCodeEnable != '1') { @@ -327,7 +332,7 @@ class _LoginAccountPageContianerState extends State i /// 切换登陆方式tip Padding(padding: const EdgeInsets.only(top: 15), child: _getChangeTipWidget(model)), - /// 按钮 + /// 登录按钮 Padding(padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 30), child: _getSubmiBtnWidget(model)), /// 协议 @@ -488,7 +493,7 @@ class _LoginAccountPageContianerState extends State i color: Colors.white, child: RaisedButton( child: Text( - model?.mobile?.btnLoginText ?? '立即登录', + _isLogging ? '登录中...' : model?.mobile?.btnLoginText ?? '立即登录', style: TextStyle(fontSize: 15), ), textColor: HexColor.fromHex(model?.mobile?.btnLoginTextColor ?? '#FFFFFF'), diff --git a/lib/pages/login_page/invite/login_invite_page.dart b/lib/pages/login_page/invite/login_invite_page.dart index 2255bf5..0e8c2ab 100644 --- a/lib/pages/login_page/invite/login_invite_page.dart +++ b/lib/pages/login_page/invite/login_invite_page.dart @@ -39,6 +39,9 @@ class _LoginInvitePageContainerState extends State { FocusNode _focusNode; bool _showInviteInfo = false; + // 是否登录中 + bool _isLogging = false; + /// 返回上一页 void _openPop() { if (Navigator.canPop(context)) { diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index dd4220e..10033e4 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -93,7 +93,7 @@ class NetUtil { } /// 同步请求 - static Future post(String path, {Map params, NetMethod method = NetMethod.POST, bool cache = false}) async { + static Future post(String path, {Map params, Map queryParameters, NetMethod method = NetMethod.POST, bool cache = false}) async { if (params == null) { params = {}; } @@ -112,6 +112,7 @@ class NetUtil { path, data: !EmptyUtil.isEmpty(bodyParams) ? bodyParams : null, options: Options(method: enumToString(method), headers: headParam), + queryParameters: !EmptyUtil.isEmpty(queryParameters) ? queryParameters : null, ); } on DioError catch (e) { _formatError(e); @@ -138,15 +139,14 @@ class NetUtil { } // 退出登陆 - if(result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '401003'){ + if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '401003') { try { Future.delayed(Duration(seconds: 0)).then((onValue) { BuildContext context = navigatorKey.currentState.overlay.context; Provider.of(context, listen: false).unLogin(); }); - - }catch(e,s ){ - Logger.error(e,s ); + } catch (e, s) { + Logger.error(e, s); } } @@ -158,7 +158,7 @@ class NetUtil { } /// 异步请求 - static void request(String path, {NetMethod method = NetMethod.GET, Map params, OnSuccess onSuccess, OnError onError, OnCache onCache}) async { + static void request(String path, {NetMethod method = NetMethod.GET, Map params,Map queryParameters, OnSuccess onSuccess, OnError onError, OnCache onCache}) async { if (params == null) { params = {}; } @@ -171,7 +171,7 @@ class NetUtil { } try { - Map result = await NetUtil.post(path, method: method, params: params); + Map result = await NetUtil.post(path, method: method, params: params, queryParameters: queryParameters); // TODO 解密? if (isSuccess(result)) { if (onSuccess != null) { @@ -291,7 +291,6 @@ class NetUtil { // idfa params['idfa'] = iosInfo?.identifierForVendor?.toString(); - } else if (Platform.isAndroid) { AndroidDeviceInfo androidInfo = await DeviceInfoPlugin().androidInfo; // 设备 @@ -349,10 +348,10 @@ class NetUtil { } /// 获取Android imei - static Future _getImei() async{ - try{ + static Future _getImei() async { + try { return await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: true); - }catch(e, s){ + } catch (e, s) { Logger.error(e, s); } return null; diff --git a/lib/util/turn_chain/turn_chain_util.dart b/lib/util/turn_chain/turn_chain_util.dart index 62ad40d..1ea6cd9 100644 --- a/lib/util/turn_chain/turn_chain_util.dart +++ b/lib/util/turn_chain/turn_chain_util.dart @@ -86,6 +86,7 @@ class TurnChainUtil { } else if (!EmptyUtil.isEmpty(webUrl)) { RouterUtil.openWebview(webUrl, context); } else { + Fluttertoast.cancel(); Fluttertoast.showToast(msg: '购买链接不存在'); } @@ -98,6 +99,7 @@ class TurnChainUtil { } else if (!EmptyUtil.isEmpty(webUrl)) { RouterUtil.openWebview(webUrl, context); } else { + Fluttertoast.cancel(); Fluttertoast.showToast(msg: '购买链接不存在'); } break; @@ -117,11 +119,13 @@ class TurnChainUtil { Logger.log('打开${provider} webUrl, url = ${webUrl}'); RouterUtil.openWebview(webUrl, context); } else { + Fluttertoast.cancel(); Fluttertoast.showToast(msg: '购买链接不存在'); } break; } } else { + Fluttertoast.cancel(); Fluttertoast.showToast(msg: '购买链接不存在'); } } @@ -154,6 +158,7 @@ class TurnChainUtil { if (!EmptyUtil.isEmpty(result) && !EmptyUtil.isEmpty(result['open_app_url'])) { return result; } + Fluttertoast.cancel(); Fluttertoast.showToast(msg: '购买链接不存在'); return null; }