Przeglądaj źródła

1、登录多次点击的优化

2、请求网络添加url参数
tags/0.0.2+6^2
PH2 4 lat temu
rodzic
commit
d418fe23d5
6 zmienionych plików z 51 dodań i 39 usunięć
  1. +4
    -4
      lib/pages/login_page/account/bloc/login_account_bloc.dart
  2. +7
    -7
      lib/pages/login_page/account/bloc/login_account_state.dart
  3. +22
    -17
      lib/pages/login_page/account/login_account_page.dart
  4. +3
    -0
      lib/pages/login_page/invite/login_invite_page.dart
  5. +10
    -11
      lib/util/net_util.dart
  6. +5
    -0
      lib/util/turn_chain/turn_chain_util.dart

+ 4
- 4
lib/pages/login_page/account/bloc/login_account_bloc.dart Wyświetl plik

@@ -58,18 +58,18 @@ class LoginAccountBloc extends Bloc<LoginAccountEvent, LoginAccountState> {
Stream<LoginAccountState> _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<LoginAccountState> _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();

}
}

+ 7
- 7
lib/pages/login_page/account/bloc/login_account_state.dart Wyświetl plik

@@ -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<Object> get props => [this.model];
}

/// 验证码登陆失败
class LoginAccountTypeVcodeLoginErrorState extends LoginAccountState {
/// 登陆失败
class LoginAccountLoginErrorState extends LoginAccountState {
final String msg;

const LoginAccountTypeVcodeLoginErrorState({this.msg});
}
const LoginAccountLoginErrorState({this.msg});
}

+ 22
- 17
lib/pages/login_page/account/login_account_page.dart Wyświetl plik

@@ -52,6 +52,8 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i
FocusNode _phoneFN;
FocusNode _passFN;
FocusNode _vcodeFN;
// 是否登录中
bool _isLogging = false;

/// 跳转到邀请码页面
void _openInvitePage() {
@@ -67,11 +69,7 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i
/// 登陆成功页面
void _openLoginSuccessPage() {
RouterUtil.hideKeyboard(context);
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)),
(Route<dynamic> route) => false,
);
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)), (Route<dynamic> route) => false,);
}

/// 返回上一页
@@ -84,14 +82,17 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i
/// 登陆
void _submitOnClick() {
print('登陆');
if (_checkParam(true)) {
if (_checkParam(true) && !_isLogging) {
setState(() {
_isLogging = true;
});
if (_useVcode) {
BlocProvider.of<LoginAccountBloc>(context)
.add(LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? ''));
BlocProvider.of<LoginAccountBloc>(context).add(LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? ''));
} else {
BlocProvider.of<LoginAccountBloc>(context)
.add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', password: _passEdController?.text?.toString()?.trim() ?? ''));
BlocProvider.of<LoginAccountBloc>(context).add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', password: _passEdController?.text?.toString()?.trim() ?? ''));
}
}else{
Logger.log('参数有误 或者 正在登录中。。。');
}
}

@@ -255,16 +256,20 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i
Widget build(BuildContext context) {
return BlocConsumer<LoginAccountBloc, LoginAccountState>(
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<UserInfoNotifier>(context, listen: false)?.setUserInfo(current.model);
if (current?.model?.registerInviteCodeEnable != '1') {
@@ -327,7 +332,7 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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'),


+ 3
- 0
lib/pages/login_page/invite/login_invite_page.dart Wyświetl plik

@@ -39,6 +39,9 @@ class _LoginInvitePageContainerState extends State<LoginInvitePageContainer> {
FocusNode _focusNode;
bool _showInviteInfo = false;

// 是否登录中
bool _isLogging = false;

/// 返回上一页
void _openPop() {
if (Navigator.canPop(context)) {


+ 10
- 11
lib/util/net_util.dart Wyświetl plik

@@ -93,7 +93,7 @@ class NetUtil {
}

/// 同步请求
static Future<dynamic> post(String path, {Map<String, dynamic> params, NetMethod method = NetMethod.POST, bool cache = false}) async {
static Future<dynamic> post(String path, {Map<String, dynamic> params, Map<String, dynamic> 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<UserInfoNotifier>(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<String, dynamic> params, OnSuccess onSuccess, OnError onError, OnCache onCache}) async {
static void request(String path, {NetMethod method = NetMethod.GET, Map<String, dynamic> params,Map<String, dynamic> 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<String> _getImei() async{
try{
static Future<String> _getImei() async {
try {
return await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: true);
}catch(e, s){
} catch (e, s) {
Logger.error(e, s);
}
return null;


+ 5
- 0
lib/util/turn_chain/turn_chain_util.dart Wyświetl plik

@@ -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;
}


Ładowanie…
Anuluj
Zapisz