using System;
|
using System.Threading;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI.UI1Login
|
{
|
public partial class LoginPage
|
{
|
|
/// <summary>
|
/// 加载事件
|
/// </summary>
|
void LoadEventList()
|
{
|
LoadPage_SwitchLoginType();
|
LoadMethod_VisiblePassword();
|
LoadPage_SwitchLoginMode();
|
LoadMethod_LoginMethod();
|
LoadPage_SelectionEditText();
|
LoadPage_RegisterPage();
|
GetVerificationCode();
|
|
}
|
|
/// <summary>
|
/// 点击按钮获取验证码
|
/// </summary>
|
void GetVerificationCode()
|
{
|
btnGetVerificationCode.MouseUpEventHandler += (sender, e) =>
|
{
|
#if DEBUG
|
etAccount.Text = "17576024298";
|
#endif
|
string phoneNumber = etAccount.Text.Trim();
|
btnGetVerificationCode.Enable = false;
|
btnGetVerificationCode.TextColor = CSS_Color.PromptingColor1;
|
int time = 60;
|
new Thread(() =>
|
{
|
while (time != 0)
|
{
|
time--;
|
Application.RunOnMainThread(() =>
|
{
|
btnGetVerificationCode.Text = time.ToString() + "s";
|
});
|
Thread.Sleep(1000);
|
}
|
})
|
{ IsBackground = true }.Start();
|
//检查手机是否已经被注册
|
var checkPhoneResult = pm.IsExistingAccount(etAccount.Text.Trim());
|
//手机已经被注册
|
if (checkPhoneResult.StateCode == HttpRequesResult.SUCCESS.ToString())
|
{
|
//获取验证码
|
pm.GetPhoneVerificationCode(phoneNumber,MainPage.Company);
|
}
|
};
|
}
|
|
/// <summary>
|
/// 切换登录类型
|
/// </summary>
|
void LoadPage_SwitchLoginType()
|
{
|
//选择手机登录
|
btnPhoneLogin.MouseUpEventHandler += (sender, e) =>
|
{
|
#region 切换选中按钮
|
btnEmailLogin.TextColor = CSS_Color.PromptingColor1;
|
btnEmailLogin.TextSize = CSS_FontSize.TextFontSize;
|
btnPhoneLogin.TextColor = CSS_Color.MainColor;
|
btnPhoneLogin.TextSize = CSS_FontSize.EmphasisFontSize_Secondary;
|
etAccount.PlaceholderText = Language.StringByID(R.InternationalizationString.PlsEntryCorrectMobilNeumber);
|
#endregion
|
|
#region 切换登录方式及图标
|
logintType = 0;
|
if (btnAccountIcon.Parent != null)
|
{
|
btnAccountIcon.RemoveFromParent();
|
}
|
accountView.AddChidren(btnGlobalRoaming);
|
//显示验证码登录方式,手机登录有验证码登录
|
btnSwitchLoginMode.Visible = true;
|
#endregion
|
};
|
|
//选择邮箱登录
|
btnEmailLogin.MouseUpEventHandler += (sender, e) =>
|
{
|
#region 切换选中按钮
|
btnPhoneLogin.TextColor = CSS_Color.PromptingColor1;
|
btnPhoneLogin.TextSize = CSS_FontSize.TextFontSize;
|
btnEmailLogin.TextColor = CSS_Color.MainColor;
|
btnEmailLogin.TextSize = CSS_FontSize.EmphasisFontSize_Secondary;
|
etAccount.PlaceholderText = Language.StringByID(R.InternationalizationString.PlsEntryEmailAddress);
|
#endregion
|
|
#region 切换登录类型及图标
|
logintType = 1;
|
if (btnGlobalRoaming.Parent != null)
|
{
|
btnGlobalRoaming.RemoveFromParent();
|
}
|
accountView.AddChidren(btnAccountIcon);
|
#endregion
|
|
//邮箱只有密码登录模式
|
logintMode = 0;
|
//密码登录
|
btnSwitchLoginMode.TextID = R.InternationalizationString.VerificationCodeLogin;
|
passwordView.AddChidren(btnVisiblePassword);
|
passwordView.AddChidren(btnDividingLineVertical_PasswordView2);
|
passwordView.AddChidren(btnForgetPassword);
|
btnPasswordIcon.IsSelected = false;
|
|
if (btnGetVerificationCode.Parent != null)
|
{
|
btnGetVerificationCode.RemoveFromParent();
|
}
|
//隐藏密码
|
etPassword.SecureTextEntry = true;
|
//隐藏验证码登录方式,邮箱登录没有验证码登录
|
btnSwitchLoginMode.Visible = false;
|
};
|
}
|
|
/// <summary>
|
/// 切换登录方式
|
/// 验证码/密码
|
/// </summary>
|
void LoadPage_SwitchLoginMode()
|
{
|
btnSwitchLoginMode.MouseUpEventHandler += (sender, e) =>
|
{
|
logintMode = logintMode == 0 ? 1 : 0;
|
//清除密码框文本数据
|
etPassword.Text = "";
|
//密码登录
|
if (logintMode == 0)
|
{
|
btnSwitchLoginMode.TextID = R.InternationalizationString.VerificationCodeLogin;
|
passwordView.AddChidren(btnVisiblePassword);
|
passwordView.AddChidren(btnDividingLineVertical_PasswordView2);
|
passwordView.AddChidren(btnForgetPassword);
|
btnPasswordIcon.IsSelected = false;
|
if (btnGetVerificationCode.Parent != null)
|
{
|
btnGetVerificationCode.RemoveFromParent();
|
}
|
//隐藏密码
|
etPassword.SecureTextEntry = true;
|
}
|
//验证码登录
|
else if (logintMode == 1)
|
{
|
btnSwitchLoginMode.TextID = R.InternationalizationString.PasswordLogin;
|
passwordView.AddChidren(btnGetVerificationCode);
|
btnPasswordIcon.IsSelected = true;
|
if (btnVisiblePassword.Parent != null)
|
{
|
btnVisiblePassword.RemoveFromParent();
|
}
|
if (btnDividingLineVertical_PasswordView2.Parent != null)
|
{
|
btnDividingLineVertical_PasswordView2.RemoveFromParent();
|
}
|
if (btnForgetPassword.Parent != null)
|
{
|
btnForgetPassword.RemoveFromParent();
|
}
|
//验证码不需要隐藏
|
etPassword.SecureTextEntry = false;
|
}
|
};
|
}
|
|
/// <summary>
|
/// 文本框选中事件
|
/// </summary>
|
void LoadPage_SelectionEditText()
|
{
|
//当焦点在账号文本框时,文本框底线点亮
|
etAccount.FoucsChanged += (sender, e) =>
|
{
|
if (etAccount.Foucs)
|
{
|
btnAccountViewBottomLine.BackgroundColor = CSS_Color.MainColor;
|
btnAccountViewBottomLine.Height = Application.GetRealHeight(2);
|
}
|
else
|
{
|
btnAccountViewBottomLine.BackgroundColor = CSS_Color.DividingLineColor;
|
btnAccountViewBottomLine.Height = Application.GetRealHeight(1);
|
}
|
};
|
//当焦点在密码文本框时,文本框底线点亮
|
etPassword.FoucsChanged += (sender, e) =>
|
{
|
if (etPassword.Foucs)
|
{
|
btnPasswordViewBottomLine.BackgroundColor = CSS_Color.MainColor;
|
btnPasswordViewBottomLine.Height = Application.GetRealHeight(2);
|
}
|
else
|
{
|
btnPasswordViewBottomLine.BackgroundColor = CSS_Color.DividingLineColor;
|
btnPasswordViewBottomLine.Height = Application.GetRealHeight(1);
|
}
|
};
|
|
//当焦点在账号文本框时,点击键盘回撤按键,触发的事件
|
etAccount.EditorEnterAction += (obj) =>
|
{
|
etPassword.Foucs = true;
|
};
|
//当焦点在密码文本框时,点击键盘回撤按键,触发的事件
|
etPassword.EditorEnterAction += (obj) =>
|
{
|
etPassword.Foucs = false;
|
};
|
}
|
|
/// <summary>
|
/// 隐藏/显示密码
|
/// </summary>
|
void LoadMethod_VisiblePassword()
|
{
|
btnVisiblePassword.MouseUpEventHandler += (sender, e) =>
|
{
|
btnVisiblePassword.IsSelected = !btnVisiblePassword.IsSelected;
|
if (btnVisiblePassword.IsSelected)
|
{
|
etPassword.SecureTextEntry = false;
|
}
|
else
|
{
|
etPassword.SecureTextEntry = true;
|
}
|
};
|
}
|
|
/// <summary>
|
/// 登录按钮点击事件
|
/// </summary>
|
void LoadMethod_LoginMethod()
|
{
|
btnLogin.MouseUpEventHandler += (sender, e) =>
|
{
|
if (btnLogin.IsSelected)
|
{
|
account = etAccount.Text.Trim();
|
password = etPassword.Text.Trim();
|
//创建登录线程
|
var loginThread = LoadMethod_LoginThread();
|
LoadPage_WaitPage(loginThread);
|
}
|
};
|
#region 当账号密码都输入时,才能点击登录按钮
|
etAccount.TextChangeEventHandler += (sender, e) =>
|
{
|
if (etAccount.Text.Trim().Length > 0 && etPassword.Text.Trim().Length > 0)
|
{
|
btnLogin.IsSelected = true;
|
}
|
else
|
{
|
btnLogin.IsSelected = false;
|
}
|
};
|
etPassword.TextChangeEventHandler += (sender, e) =>
|
{
|
if (etAccount.Text.Trim().Length > 0 && etPassword.Text.Trim().Length > 0)
|
{
|
btnLogin.IsSelected = true;
|
}
|
else
|
{
|
btnLogin.IsSelected = false;
|
}
|
};
|
#endregion
|
}
|
|
/// <summary>
|
/// 加载等待界面
|
/// </summary>
|
void LoadPage_WaitPage(Thread thread)
|
{
|
waitPage = new Loading();
|
bodyView.AddChidren(waitPage);
|
waitPage.Start(Language.StringByID(R.InternationalizationString.PleaseWait));
|
var showedTime = DateTime.Now;
|
//如果等待事件过长,可以允许用户取消当前操作
|
waitPage.MouseUpEventHandler += (sender, e) =>
|
{
|
if (showedTime.AddSeconds(30) > DateTime.Now)
|
{
|
waitPage.RemoveFromParent();
|
waitPage = null;
|
thread.Abort();
|
}
|
};
|
thread.Start();
|
}
|
|
/// <summary>
|
/// 加载登录线程
|
/// </summary>
|
Thread LoadMethod_LoginThread()
|
{
|
var loginThread = new Thread(() =>
|
{
|
try
|
{
|
var loginResult = pm.LoginByPassword(account,password,MainPage.Company);
|
Application.RunOnMainThread(() =>
|
{
|
waitPage.RemoveFromParent();
|
waitPage = null;
|
});
|
//登录成功
|
if (loginResult.StateCode == HttpRequesResult.SUCCESS.ToString())
|
{
|
var loginResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes>(loginResult.ResponseData.ToString());
|
//记录用户数据
|
MainPage.LoginUser = new UserInfo
|
{
|
ID = loginResponseData.UserId,
|
MasterID = loginResponseData.MainUserId,
|
AccountType = loginResponseData.UserType,
|
AccountString = account,
|
Password = password,
|
LastTime = DateTime.Now,
|
SIP_Account = loginResponseData.AllVisionRegisterDevUserNameGuid,
|
};
|
MainPage.LoginUser.SaveUserInfo();
|
MainPage.Log("登录成功。");
|
|
/*
|
* Wait : 推送注册
|
*/
|
}
|
//登录失败
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
//提示原因
|
var tip = new Tip()
|
{
|
Text = loginResult.ErrorInfo,
|
CloseTime = 3,
|
Direction = AMPopTipDirection.None
|
};
|
tip.Show(bodyView);
|
//if (loginResult.StateCode == HttpRequesResult.LoginFailed_AccountErorr.ToString())
|
{
|
btnAccountViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
|
btnAccountViewBottomLine.Height = Application.GetRealHeight(2);
|
//}
|
//else if (loginResult.StateCode == HttpRequesResult.LoginFailed_PasswordErorr.ToString())
|
//{
|
btnPasswordViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
|
btnPasswordViewBottomLine.Height = Application.GetRealHeight(2);
|
}
|
});
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"LoginPage : {ex.Message}");
|
}
|
})
|
{ IsBackground = true };
|
return loginThread;
|
}
|
|
/// <summary>
|
/// 加载注册界面
|
/// </summary>
|
void LoadPage_RegisterPage()
|
{
|
btnRegister.MouseUpEventHandler += (sender, e) => {
|
//回调事件
|
Action<string> callBackAction = (callBackPar_Action) =>
|
{
|
try
|
{
|
etAccount.Text = callBackPar_Action;
|
}
|
catch (Exception ex) {
|
MainPage.Log($"login callBackAction : {ex.Message}");
|
}
|
};
|
|
var registerPage = new RegisterPage(callBackAction);
|
registerPage.Show();
|
registerPage.ShowDialog();
|
};
|
}
|
}
|
}
|