public BindingWechatViewModel(RegisterByOpenIdPara registerByOpenIdPara) { Avatar = registerByOpenIdPara.headimgurl; NickName = registerByOpenIdPara.nikename; BindingWechatCommand = new Command(async() => { try { string result = await Application.Current.MainPage.DisplayPromptAsync("已注册手机号", "请输入11位手机号", "确定绑定", "取消", "请输入11位手机号", 11, null); if (result == null) { CrossToastPopUp.Current.ShowToastWarning("已取消", ToastLength.Long); } else if (string.IsNullOrWhiteSpace(result)) { CrossToastPopUp.Current.ShowToastWarning("手机号不能为空,请输入!", ToastLength.Long); } else if (!Tools.IsPhoneNumber(result)) { CrossToastPopUp.Current.ShowToastWarning("手机号格式不标准,请检查。", ToastLength.Long); } else { registerByOpenIdPara.tel = result; AuthCodePage authCodePage = new AuthCodePage(registerByOpenIdPara); await Application.Current.MainPage.Navigation.PushAsync(authCodePage); } } catch (Exception) { throw; } }, () => { return(true); }); ToRegisterCommand = new Command(async() => { RegisterPage registerPage = new RegisterPage(registerByOpenIdPara); await Application.Current.MainPage.Navigation.PushAsync(registerPage); }, () => { return(true); }); LoginCommand = new Command(() => { Login(registerByOpenIdPara); }, () => { return(true); }); }
public LoginViewModel() { IsPassword = true; EyeSource = "Resource/drawable/closed_eye.png"; AuthLoginButtonColor = "#83d7f9"; AuthVisible = true; PasswordVisible = false; ToRegisterPageCommand = new Command(() => { Application.Current.MainPage.Navigation.PushAsync(new RegisterPage()); }, () => { return(true); }); LoginCommand = new Command(() => { if (CheckInput()) { OnLogin(); } }, () => { return(true); }); FindPwdCommand = new Command(() => { Application.Current.MainPage.Navigation.PushAsync(new ResetPwdPage()); }, () => { return(true); }); OpenEyeCommand = new Command(() => { if (IsPassword) { IsPassword = false; EyeSource = "Resource/drawable/open_eye.png"; } else { IsPassword = true; EyeSource = "Resource/drawable/closed_eye.png"; } }, () => { return(true); }); ToAuthPageCommand = new Command(() => { if (Tools.IsPhoneNumber(Tel)) { AuthCodePage authCodePage = new AuthCodePage(Tel); Application.Current.MainPage.Navigation.PushAsync(authCodePage); } else { CrossToastPopUp.Current.ShowToastWarning("手机号格式不标准,请检查。", ToastLength.Long); } }, () => { return(true); }); PasswordLoginPartCommand = new Command(() => { AuthVisible = false; PasswordVisible = true; }, () => { return(true); }); AuthLoginPartCommand = new Command(() => { AuthVisible = true; PasswordVisible = false; }, () => { return(true); }); WechatLoginCommand = new Command(() => { MessagingCenter.Send(new object(), "Register");//首先进行注册,然后订阅注册的结果。 MessagingCenter.Send(new object(), "Login"); MessagingCenter.Subscribe <object, string>(this, "LoginSuccess", async(sender, result) => { try { JObject jObject = JObject.Parse(result); RegisterByOpenIdPara registerByOpenIdPara = new RegisterByOpenIdPara { openId = jObject["openid"].ToString(), nikename = jObject["nickname"].ToString(), headimgurl = jObject["headimgurl"].ToString(), }; BindingWechatPage bindingWechatPage = new BindingWechatPage(registerByOpenIdPara); await Application.Current.MainPage.Navigation.PushAsync(bindingWechatPage); MessagingCenter.Unsubscribe <object, string>(this, "LoginSuccess"); MessagingCenter.Unsubscribe <object, string>(this, "Login"); } catch (Exception ex) { Console.WriteLine("错误:" + ex); } }); }, () => { return(true); }); }
public LoginViewModel() { IsPassword = true; EyeSource = "Resource/drawable/closed_eye.png"; AuthLoginButtonColor = "#83d7f9"; AuthVisible = true; PasswordVisible = false; ToRegisterPageCommand = new Command(() => { Application.Current.MainPage.Navigation.PushModalAsync(new RegisterPage()); }, () => { return(true); }); LoginCommand = new Command(() => { if (CheckInput()) { OnLogin(); } }, () => { return(true); }); FindPwdCommand = new Command(() => { Application.Current.MainPage.Navigation.PushModalAsync(new ResetPwdPage()); }, () => { return(true); }); OpenEyeCommand = new Command(() => { if (IsPassword) { IsPassword = false; EyeSource = "Resource/drawable/open_eye.png"; } else { IsPassword = true; EyeSource = "Resource/drawable/closed_eye.png"; } }, () => { return(true); }); ToAuthPageCommand = new Command(() => { if (Tools.IsPhoneNumber(Tel)) { AuthCodePage authCodePage = new AuthCodePage(Tel); Application.Current.MainPage.Navigation.PushModalAsync(authCodePage); } else { CrossToastPopUp.Current.ShowToastWarning("手机号格式不标准,请检查。", ToastLength.Long); } }, () => { return(true); }); PasswordLoginPartCommand = new Command(() => { AuthVisible = false; PasswordVisible = true; }, () => { return(true); }); AuthLoginPartCommand = new Command(() => { AuthVisible = true; PasswordVisible = false; }, () => { return(true); }); WechatLoginCommand = new Command(() => { MessagingCenter.Send(new object(), "Register");//首先进行注册,然后订阅注册的结果。 MessagingCenter.Send(new object(), "Login"); }, () => { return(true); }); }