JLChen
2020-12-09 e87985ec1dcb69beedaf9f95e8e7aba14b7c08d6
HDL_ON/UI/UI1-Login/LoginPage.cs
New file
@@ -0,0 +1,637 @@
using System;
using System.Text.RegularExpressions;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI.UI1Login
{
    public partial class LoginPage : FrameLayout
    {
        public LoginPage()
        {
            //bodyView = new FrameLayout();
            //AddChidren(bodyView);
            bodyView = this;
            pm = new HttpServerRequest();
        }
        public override void RemoveFromParent()
        {
            //如果当前界面存在正在等待数据的情况,先将该动作关掉
            if (waitPage != null)
            {
                waitPage.RemoveFromParent();
                waitPage = null;
            }
            else
            {
                base.RemoveFromParent();
            }
        }
        #region 局部变量
        /// <summary>
        /// 登录类型
        /// 0:手机
        /// 1:邮箱
        /// </summary>
        int loginType = 0;
        /// <summary>
        /// 登录方式
        /// 0:密码
        /// 1:验证码
        /// </summary>
        int logintMode = 0;
        string account = "";
        string password = "";
        #endregion
        #region 控件列表
        /// <summary>
        /// 等待提示
        /// </summary>
        Loading waitPage;
        /// <summary>
        /// 当前界面
        /// </summary>
        FrameLayout bodyView;
        /// <summary>
        /// 选择手机登录按钮
        /// </summary>
        Button btnPhoneLogin;
        /// <summary>
        /// 选择邮箱登录按钮
        /// </summary>
        Button btnEmailLogin;
        /// <summary>
        /// 账号子区域
        /// </summary>
        FrameLayout accountView;
        /// <summary>
        /// 国际区号按钮
        /// </summary>
        Button btnGlobalRoaming;
        /// <summary>
        /// 账号子区域里面的分割线
        /// </summary>
        Button btnDividingLineVertical_AccountView;
        /// <summary>
        /// 账号文本框
        /// </summary>
        EditText etAccount;
        /// <summary>
        /// 账号Icon按钮
        /// </summary>
        Button btnAccountIcon;
        /// <summary>
        /// 密码子区域
        /// </summary>
        FrameLayout passwordView;
        /// <summary>
        /// 密码Icon按钮
        /// </summary>
        Button btnPasswordIcon;
        /// <summary>
        /// 密码文本框
        /// </summary>
        EditText etPassword;
        /// <summary>
        /// 密码子区域里面的分割线1
        /// </summary>
        Button btnDividingLineVertical_PasswordView1;
        /// <summary>
        /// 密码子区域里面的分割线2
        /// </summary>
        Button btnDividingLineVertical_PasswordView2;
        /// <summary>
        /// 忘记密码按钮
        /// </summary>
        Button btnForgetPassword;
        /// <summary>
        /// 获取手机验证码按钮
        /// </summary>
        Button btnGetVerificationCode;
        /// <summary>
        /// 密码是否可见按钮
        /// </summary>
        Button btnVisiblePassword;
        /// <summary>
        /// 账号子区域底部横线
        /// </summary>
        Button btnAccountViewBottomLine;
        /// <summary>
        /// 密码子区域底部横线
        /// </summary>
        Button btnPasswordViewBottomLine;
        /// <summary>
        /// 注册按钮
        /// </summary>
        Button btnRegister;
        /// <summary>
        /// 验证码登录按钮
        /// </summary>
        Button btnSwitchLoginMode;
        /// <summary>
        /// 登录按钮
        /// </summary>
        Button btnLogin;
        /// <summary>
        /// 服务器请求对象
        /// </summary>
        HttpServerRequest pm;
        #endregion
        string verAccount = "";
        /// <summary>
        ///
        /// </summary>
        string registerPhone;
        string registerEmail;
        /// <summary>
        /// 手机区号
        /// </summary>
        string phoneZoneCode = "86";
        /// <summary>
        /// 加载视图
        /// </summary>
        public void LoadView(UserInfo userInfo = null)
        {
            Language.CurrentLanguage = "Chinese";
            var btnIcon = new Button()
            {
                X = Application.GetRealWidth(28),
                Y = Application.GetRealHeight(73),
                Width = Application.GetMinRealAverage(62),
                Height = Application.GetMinRealAverage(62),
                UnSelectedImagePath = "Public/Logo.png",
            };
            bodyView.AddChidren(btnIcon);
            var btnIcon_bg = new Button()
            {
                X = Application.GetRealWidth(171),
                Y = Application.GetRealHeight(69),
                Width = Application.GetMinRealAverage(254),
                Height = Application.GetMinRealAverage(156),
                UnSelectedImagePath = "Public/Logo-bg.png"
            };
            bodyView.AddChidren(btnIcon_bg);
            btnIcon.MouseUpEventHandler += (sender, e) =>
            {
#if DEBUG
                etAccount.Text = "13375012446";// "18824864143";//"464027401@qq.com"; //"2791308028@qq.com";//
                etPassword.Text = "123456";
                //etPassword.Text = "qqqqqq";
                btnLogin.IsSelected = true;
#endif
            };
            #region 登录方式选择
            btnPhoneLogin = new Button()
            {
                X = Application.GetRealWidth(28),
                Y = Application.GetRealHeight(177),
                Width = Application.GetRealWidth(120),
                Height = Application.GetRealHeight(40),
                TextID = StringId.LoginByPhone,
                TextColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.EmphasisFontSize_Secondary,
            };
            bodyView.AddChidren(btnPhoneLogin);
            btnEmailLogin = new Button()
            {
                X = btnPhoneLogin.Right + Application.GetRealWidth(20),
                Y = Application.GetRealHeight(177),
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(40),
                TextID = StringId.LoginByEmail,
                TextColor = CSS_Color.PromptingColor1,
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.TextFontSize,
            };
            bodyView.AddChidren(btnEmailLogin);
            #endregion
            #region 账号填写
            accountView = new FrameLayout()
            {
                X = Application.GetRealWidth(28),
                Y = Application.GetRealHeight(232),
                Width = Application.GetRealWidth(319),
                Height = Application.GetRealHeight(44),
            };
            bodyView.AddChidren(accountView);
            btnGlobalRoaming = new Button()
            {
                Width = Application.GetRealWidth(65),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Text = "+" + phoneZoneCode,
                TextSize = CSS_FontSize.TextFontSize,
                Enable = true,
            };
            //跳转国家区号选择界面
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                JLCountrycode.CountryCodeView.Current.Show((countryName, code) =>
                {
                    if (!string.IsNullOrEmpty(code))
                    {
                        phoneZoneCode = code;
                        btnGlobalRoaming.Text = "+" + phoneZoneCode;
                    }
                });
            };
            btnGlobalRoaming.MouseUpEventHandler += eHandler;
            if (loginType == 0)
            {
                accountView.AddChidren(btnGlobalRoaming);
            }
            btnDividingLineVertical_AccountView = new Button()
            {
                X = Application.GetRealWidth(65),
                Gravity = Gravity.CenterVertical,
                Width = 1,
                Height = Application.GetRealHeight(20),
                BackgroundColor = CSS_Color.DividingLineColor,
            };
            accountView.AddChidren(btnDividingLineVertical_AccountView);
            etAccount = new EditText()
            {
                X = Application.GetRealWidth(78),
                Width = Application.GetRealWidth(319 - 78),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                PlaceholderTextColor = CSS_Color.PromptingColor1,
                PlaceholderText = Language.StringByID(StringId.PlsEntryPhoneNumber),
                TextAlignment = TextAlignment.CenterLeft,
            };
            accountView.AddChidren(etAccount);
            if (userInfo != null)
            {
                registerEmail = userInfo.userEmailInfo;
                etAccount.Text = registerPhone = userInfo.userMobileInfo;
            }
            btnAccountViewBottomLine = new Button()
            {
                Y = Application.GetRealHeight(42),
                BackgroundColor = CSS_Color.DividingLineColor,
                Height = Application.GetRealHeight(1),
            };
            accountView.AddChidren(btnAccountViewBottomLine);
            btnAccountIcon = new Button()
            {
                X = Application.GetRealWidth(21),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(20),
                Height = Application.GetMinRealAverage(20),
                UnSelectedImagePath = "LoginIcon/AccountIcon.png",
            };
            if (loginType == 1)
            {
                accountView.AddChidren(btnAccountIcon);
            }
            #endregion
            #region 密码填写
            passwordView = new FrameLayout()
            {
                X = Application.GetRealWidth(28),
                Y = Application.GetRealHeight(288),
                Width = Application.GetRealWidth(319),
                Height = Application.GetRealHeight(44),
            };
            bodyView.AddChidren(passwordView);
            btnPasswordIcon = new Button()
            {
                X = Application.GetRealWidth(21),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(20),
                Height = Application.GetMinRealAverage(20),
                UnSelectedImagePath = "LoginIcon/PasswordIcon.png",
                SelectedImagePath = "LoginIcon/VerificationCodeIcon.png",
            };
            passwordView.AddChidren(btnPasswordIcon);
            btnDividingLineVertical_PasswordView1 = new Button()
            {
                X = Application.GetRealWidth(65),
                Gravity = Gravity.CenterVertical,
                Width = 1,
                Height = Application.GetRealHeight(20),
                BackgroundColor = CSS_Color.DividingLineColor,
            };
            passwordView.AddChidren(btnDividingLineVertical_PasswordView1);
            etPassword = new EditText()
            {
                X = Application.GetRealWidth(78),
                Width = Application.GetRealWidth(61 + 84),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                PlaceholderTextColor = CSS_Color.PromptingColor1,
                PlaceholderText = Language.StringByID(StringId.PlsEntryPassword),
                SecureTextEntry = true,
                TextAlignment = TextAlignment.CenterLeft,
            };
            passwordView.AddChidren(etPassword);
            #region 密码登录-控件加载
            btnVisiblePassword = new Button()
            {
                X = Application.GetRealWidth(223),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(20),
                Height = Application.GetMinRealAverage(20),
                UnSelectedImagePath = "LoginIcon/HidePasswordIcon.png",
                SelectedImagePath = "LoginIcon/ShowPasswordIcon.png",
            };
            passwordView.AddChidren(btnVisiblePassword);
            btnDividingLineVertical_PasswordView2 = new Button()
            {
                X = Application.GetRealWidth(253),
                Gravity = Gravity.CenterVertical,
                Width = 1,
                Height = Application.GetRealHeight(20),
                BackgroundColor = CSS_Color.DividingLineColor,
            };
            passwordView.AddChidren(btnDividingLineVertical_PasswordView2);
            btnForgetPassword = new Button()
            {
                X = Application.GetRealWidth(263),
                Width = Application.GetRealWidth(56),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = StringId.ForgetPassword,
                TextSize = 12,
            };
            passwordView.AddChidren(btnForgetPassword);
            #endregion
            #region 验证码登录-控件加载
            btnGetVerificationCode = new Button()
            {
                X = Application.GetRealWidth(219),
                Width = Application.GetRealWidth(100),
                TextID = StringId.GetVerificationCode,
                SelectedTextColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.CenterRight,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor = CSS_Color.PromptingColor1,
                Visible = false,
                IsSelected = false,
            };
            passwordView.AddChidren(btnGetVerificationCode);
            #endregion
            btnPasswordViewBottomLine = new Button()
            {
                Y = Application.GetRealHeight(42),
                BackgroundColor = CSS_Color.DividingLineColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                Height = Application.GetRealHeight(1),
            };
            passwordView.AddChidren(btnPasswordViewBottomLine);
            #endregion
            #region 注册与快捷登录
            btnRegister = new Button()
            {
                X = Application.GetRealWidth(28),
                Y = passwordView.Bottom,
                Width = Application.GetRealWidth(60),
                Height = Application.GetRealHeight(17 + 12 + 12),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.SingUp,
                TextAlignment = TextAlignment.CenterLeft,
            };
            bodyView.AddChidren(btnRegister);
            btnSwitchLoginMode = new Button()
            {
                X = Application.GetRealWidth(223 + 28),
                Y = passwordView.Bottom,
                Width = Application.GetRealWidth(96),
                Height = Application.GetRealHeight(51),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.VerificationCodeLogin,
                TextAlignment = TextAlignment.CenterRight,
            };
            bodyView.AddChidren(btnSwitchLoginMode);
            #endregion
            btnLogin = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(403),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                Radius = (uint)Application.GetRealWidth(22),
                SelectedBackgroundColor = CSS_Color.MainColor,
                BackgroundColor = CSS_Color.PromptingColor1,
                TextID = StringId.Login,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.MainBackgroundColor,
                TextAlignment = TextAlignment.Center,
            };
            bodyView.AddChidren(btnLogin);
            LoadEventList();
            account = etAccount.Text.Trim();
#if DEBUG1211
            //本地模式
            Button btnLocalMode = new Button()
            {
                Y = Application.GetRealHeight(600),
                Height = Application.GetRealHeight(67),
                Text = "Local Mode",
                TextAlignment = TextAlignment.Center,
                BackgroundColor  = CSS_Color.MainColor,
                TextColor = CSS_Color.TextualColor,
            };
            bodyView.AddChidren(btnLocalMode);
            btnLocalMode.MouseUpEventHandler = (sender, e) =>
            {
                MainPage.LocalMode = true;
                 UserInfo.Current = new UserInfo();
                MainPage.GoUserPage();
            };
            MainPage.Log("etAccount.TextAlignment : " + etAccount.TextAlignment.ToString());
#endif
            #region 隐私政策
            AddServiceAgreementControl(bodyView);
            #endregion
        }
        #region ■ 服务协议___________________________
        bool isAgreePrivacyPolicy = false;
        /// <summary>
        /// 添加服务协议控件
        /// </summary>
        /// <param name="frameBack"></param>
        private void AddServiceAgreementControl(FrameLayout frameLayout)
        {
            isAgreePrivacyPolicy = UserInfo.Current.isAgreePrivacyPolicy;
            var frameRow = new FrameLayout()
            {
                Height = Application.GetRealHeight(28),
                Y = Application.GetRealHeight(628),
            };
            frameLayout.AddChidren(frameRow);
            //同意按钮背景
            var agreeView = new FrameLayout()
            {
                Height = Application.GetRealHeight(28),
                Width = Application.GetRealWidth(28),
                X = Application.GetRealWidth(82),
            };
            frameRow.AddChidren(agreeView);
            //同意图标按钮
            var agreeBtn = new Button()
            {
                Width = Application.GetMinRealAverage(28),
                Height = Application.GetMinRealAverage(28),
                UnSelectedImagePath = "Public/ChooseIcon.png",
                SelectedImagePath = "Public/ChooseOnIcon.png",
                IsSelected = isAgreePrivacyPolicy,
                Gravity = Gravity.Center
            };
            agreeView.AddChidren(agreeBtn);
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                isAgreePrivacyPolicy = !isAgreePrivacyPolicy;
                agreeBtn.IsSelected = isAgreePrivacyPolicy;
                UserInfo.Current.isAgreePrivacyPolicy = isAgreePrivacyPolicy;
                UserInfo.Current.SaveUserInfo();
            };
            agreeBtn.MouseUpEventHandler = eventHandler;
            agreeView.MouseUpEventHandler = eventHandler;
            //int btnWidth = 0;
            //同意文本
            var agreeTextBtn = new TextButton()
            {
                X = agreeView.Right,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealHeight(28),
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.Agree
            };
            frameRow.AddChidren(agreeTextBtn);
            agreeTextBtn.Width = Utlis.GetRealWidthByTextButton(agreeTextBtn);
            //用户协议按钮
            var userAgreementBtn = new TextButton()
            {
                X = agreeTextBtn.Right,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealHeight(28),
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                Text = "《" + Language.StringByID(StringId.UserAgreement) + "》"
            };
            frameRow.AddChidren(userAgreementBtn);
            userAgreementBtn.Width = Utlis.GetRealWidthByTextButton(userAgreementBtn);
            //和文本
            var andTextBtn = new TextButton()
            {
                X = userAgreementBtn.Right,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealHeight(28),
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.And
            };
            frameRow.AddChidren(andTextBtn);
            andTextBtn.Width = Utlis.GetRealWidthByTextButton(andTextBtn);
            //隐私政策按钮
            var privacyPolicyBtn = new TextButton()
            {
                X = andTextBtn.Right,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealHeight(28),
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                Text = "《" + Language.StringByID(StringId.PrivacyPolicy) + "》"
            };
            frameRow.AddChidren(privacyPolicyBtn);
            privacyPolicyBtn.Width = Utlis.GetRealWidthByTextButton(privacyPolicyBtn);
            //打开用户协议
            userAgreementBtn.MouseUpEventHandler = (sender, e) =>
            {
                OpenWebViewPage(false);
            };
            //打开隐私政策
            privacyPolicyBtn.MouseUpEventHandler = (sender, e) =>
            {
                OpenWebViewPage(true);
            };
        }
        /// <summary>
        /// OpenWebViewPage
        /// </summary>
        /// <param name="isOpenPrivacyPolicy">是否隐私政策</param>
        private void OpenWebViewPage(bool isOpenPrivacyPolicy)
        {
            string url = isOpenPrivacyPolicy ? Constant.URL_PRIVACYPOLICY : Constant.URL_USERAGREEMENT;
            string titleStr = isOpenPrivacyPolicy ? Language.StringByID(StringId.PrivacyPolicy) : Language.StringByID(StringId.UserAgreement);
            new WebViewDialog().LoadPage(titleStr, url);
        }
        /// <summary>
        /// 检测隐私协议
        /// </summary>
        /// <returns></returns>
        private bool CheckPrivacyPolicy()
        {
            if (isAgreePrivacyPolicy == false)
            {
                //请同意《用户协议》和《隐私政策》
                Utlis.ShowTip(Language.StringByID(StringId.PleaseReadAndAgreePrivacyPolicyMsg));
                return false;
            }
            return true;
        }
        #endregion
    }
}