黄学彪
2020-04-02 9904031f5291daaf56985146bb671f25e18ebbdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
using System;
using Shared.Common;
using Shared.Phone.UserView;
using Shared.Phone.Device.CommonForm;
 
namespace Shared.Phone.Login
{
    /// <summary>
    /// 登录界面
    /// </summary>
    public class AccountLogin : FrameLayout
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// 背景视图
        /// </summary>
        private FrameLayout midFrameLayout;
        /// <summary>
        /// 手机邮箱
        /// </summary>
        private PhoneEmailForm phoneEmailForm;
        /// <summary>
        /// phoneRowForm
        /// </summary>
        private PhoneLoginRowForm phoneRow;
        /// <summary>
        /// emailRow
        /// </summary>
        private EmailLoginRowForm emailRow;
        /// <summary>
        /// phonePwdRow
        /// </summary>
        private PwdLoginRowForm phonePwdRow;
        /// <summary>
        /// emailPwdRow
        /// </summary>
        private PwdLoginRowForm emailPwdRow;
 
        /// <summary>
        /// 账号密码fl
        /// </summary>
        private FrameLayout accountPwdFL;
        /// <summary>
        /// 登录错误提示按钮
        /// </summary>
        private Button loginErrorBtn;
        /// <summary>
        /// 忘记密码按钮
        /// </summary>
        private Button forgotPasswordBtn;
        /// <summary>
        /// 登录按钮
        /// </summary>
        private Button loginBtn;
        /// <summary>
        /// 验证码登录按钮
        /// </summary>
        private Button loginByCodeBtn;
        /// <summary>
        /// 注册按钮
        /// </summary>
        private Button registerBtn;
        /// <summary>
        /// wechat
        /// </summary>
        private Button wechatBtn;
        /// <summary>
        /// qq
        /// </summary>
        private Button qqBtn;
        /// <summary>
        /// 输入的登陆账号(重新登陆时使用)
        /// </summary>
        private string oldInputAccount = string.Empty;
 
        #endregion
 
        #region ◆ 构造方法_________________________
 
        /// <summary>
        /// 构造方法
        /// </summary>
        public AccountLogin()
        {
            CommonPage.Instance.IsDrawerLockMode = true;
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            Tag = "Login";
        }
 
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
        }
 
        #endregion
 
        #region ◆ 显示界面_________________________
 
        /// <summary>
        /// 显示界面
        /// </summary>
        /// <param name="account">Account.</param>
        /// <param name="password">Password.</param>
        public void Show(string account = "", string password = "")
        {
            if (Config.Instance.IsLogin)
            {
 
            }
            else
            {
                LoginViewShow(account);
            }
        }
 
        /// <summary>
        /// Logins the view show.
        /// </summary>
        /// <param name="account">Account.</param>
        public void LoginViewShow(string account = "")
        {
            //设置一下初始值
            if (account.Contains("@") == true) { this.oldInputAccount = account; }
            else { this.oldInputAccount = account; }
 
            #region midFrameLayout
            midFrameLayout = new FrameLayout()
            {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight(CommonPage.AppRealHeight),
                BackgroundColor =ZigbeeColor.Current.GXCBackgroundColor
            };
            AddChidren(midFrameLayout);
            #endregion
 
            #region 布局账户,密码,忘记密码,注册  手机验证码登录
 
            var logoBG = new Button()
            {
                Height = Application.GetRealHeight(619),
                UnSelectedImagePath = "Account/Logo_loginBG.png"
            };
            midFrameLayout.AddChidren(logoBG);
 
            var phoneEmailBGFL = new FrameLayout()
            {
                Y = logoBG.Bottom,
                Height = Application.GetRealHeight(1921),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
            };
            midFrameLayout.AddChidren(phoneEmailBGFL);
 
            var logo = new Button()
            {
                Width = Application.GetMinRealAverage(184),
                Height = Application.GetMinRealAverage(184),
                Y = Application.GetRealHeight(230),
                UnSelectedImagePath = "Account/Logo_White.png",
                Gravity = Gravity.CenterHorizontal
            };
            midFrameLayout.AddChidren(logo);
 
            var logoName = new Button()
            {
                Y = logo.Bottom,
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(300),
                Gravity = Gravity.CenterHorizontal,
                TextID = R.MyInternationalizationString.AppName,
                TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                TextSize=16
            };
            midFrameLayout.AddChidren(logoName);
 
            phoneEmailForm = new PhoneEmailForm();
            phoneEmailForm.Init(midFrameLayout);
 
 
            //错误提示Btn
            loginErrorBtn = new Button()
            {
                X = Application.GetRealWidth(242),
                Y = Application.GetRealHeight(740),
                Width = Application.GetRealWidth(700),
                Height = Application.GetRealHeight(58),
                TextColor = ZigbeeColor.Current.GXCTextRed,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize=CommonFormResouce.TextSize,
                IsBold=true
            };
            midFrameLayout.AddChidren(loginErrorBtn);
 
            accountPwdFL = new FrameLayout()
            {
                Y = Application.GetRealHeight(801),
                Height = Application.GetRealHeight(553),
                Width = Application.GetRealWidth(942),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                Radius = (uint)Application.GetRealHeight(17)
            };
            midFrameLayout.AddChidren(accountPwdFL);
 
            AddPhoneOrEmailFL(accountPwdFL, "Phone");
 
            forgotPasswordBtn = new Button()
            {
                X = Application.GetRealWidth(CommonPage.AppRealWidth - 115 - 250),
                Y = Application.GetRealHeight(1198),
                Width = Application.GetRealWidth(250),
                Height = Application.GetRealHeight(58),
                TextID = R.MyInternationalizationString.ForgotPWD_1,
                TextSize = CommonFormResouce.loginTextSize,
                TextColor = Shared.Common.ZigbeeColor.Current.GXCTextGrayColor,
                TextAlignment = TextAlignment.CenterRight
            };
            midFrameLayout.AddChidren(forgotPasswordBtn);
 
            loginBtn = new Button()
            {
                Y = Application.GetRealHeight(1293),
                Width = Application.GetRealWidth(688),
                Height = Application.GetRealHeight(127),
                Gravity = Gravity.CenterHorizontal,
                TextID = R.MyInternationalizationString.Login,
                TextSize = 16,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonBlackSelectedColor,
                BackgroundColor = ZigbeeColor.Current.GXCButtonUnSelectedColor,
                Radius = (uint)Application.GetRealHeight(127 / 2),
                Enable = false,
                IsBold=true
            };
            midFrameLayout.AddChidren(loginBtn);
 
            loginByCodeBtn = new Button()
            {
                X=Application.GetRealWidth(98),
                Y = Application.GetRealHeight(1466),
                Width = Application.GetRealWidth(300),
                Height = Application.GetRealHeight(49),
                TextID = R.MyInternationalizationString.LoginByCode,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CommonFormResouce.loginTextSize
            };
            midFrameLayout.AddChidren(loginByCodeBtn);
 
            registerBtn = new Button()
            {
                X = Application.GetRealWidth(738),
                Y = Application.GetRealHeight(1466),
                Width = Application.GetRealWidth(244),
                Height = Application.GetRealHeight(49),
                TextID = R.MyInternationalizationString.Register,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextAlignment = TextAlignment.CenterRight,
                TextSize = CommonFormResouce.loginTextSize
            };
            midFrameLayout.AddChidren(registerBtn);
 
            wechatBtn = new Button
            {
                X = Application.GetRealWidth(395),
                Y = Application.GetRealHeight(1737),
                Width = Application.GetMinRealAverage(115),
                Height = Application.GetMinRealAverage(115),
                UnSelectedImagePath = "Account/Wechat.png",
                Gravity=Gravity.CenterHorizontal
            };
            midFrameLayout.AddChidren(wechatBtn);
 
            qqBtn = new Button
            {
                X = Application.GetRealWidth(567),
                Y = Application.GetRealHeight(1737),
                Width = Application.GetMinRealAverage(115),
                Height = Application.GetMinRealAverage(115),
                UnSelectedImagePath = "Account/QQ.png"
            };
            //midFrameLayout.AddChidren(qqBtn);
 
            #endregion
 
            BindEvent();
 
            if (account.Contains("@") == true)
            {
                SelectPhoneOrEmail_MouseUpEvent(phoneEmailForm.SelectedEmail, null);
            }
        }
 
        #endregion
 
        #region ◆ 绑定事件_________________________
 
        /// <summary>
        /// 绑定按钮事件
        /// </summary>
        private void BindEvent()
        {
            //选择手机邮箱
            phoneEmailForm.SelectedPhone.MouseUpEventHandler += SelectPhoneOrEmail_MouseUpEvent;
            phoneEmailForm.SelectedEmail.MouseUpEventHandler += SelectPhoneOrEmail_MouseUpEvent;
            //登录事件
            loginBtn.MouseUpEventHandler += LoginBtnEvent;
            //短信登录
            loginByCodeBtn.MouseUpEventHandler += LoginByCode;
            //注册事件
            registerBtn.MouseUpEventHandler += Register;
            //忘记密码
            forgotPasswordBtn.MouseUpEventHandler += ForgetPWD_MouseUpEvent;
            //wechat
            wechatBtn.MouseUpEventHandler += LoginByWechat;
            //qq
            qqBtn.MouseUpEventHandler += LoginByQQ;
        }
 
        #endregion
 
        #region ◆ 登录____________________________
 
        /// <summary>
        /// 登录事件
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void LoginBtnEvent(object sender,MouseEventArgs mouseEventArgs)
        {
            if (phoneEmailForm.SelectedPhone.IsSelected)
            {
                Login(phoneRow.AccountET.Text.Trim(), phonePwdRow.PasswrodET.Text.Trim());
            }
            else
            {
                Login(emailRow.AccountET.Text.Trim(), emailPwdRow.PasswrodET.Text.Trim());
            }
 
        }
 
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="accountStr">Account.</param>
        /// <param name="passwordStr">Password.</param>
        private void Login(string accountStr, string passwordStr)
        {
            //Application.RunOnMainThread( () =>
            //{
            Action action = async () =>
            {
                try
                {
                    if(CheckAccount(accountStr)==false)
                    {
                        return;
                    }
 
                    CommonPage.Loading.Start(Language.StringByID(R.MyInternationalizationString.Logining));
 
                    var requestObj = new SendDataToServer.LoginObj
                    {
                        Account = accountStr,
                        Password = passwordStr,
                        Source = CommonPage.Source,
                        Company = CommonPage.Company
                    };
                    var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
                    var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/Login", System.Text.Encoding.UTF8.GetBytes(requestJson));
                    if (revertObj == null)
                    {
                        CommonPage.Instance.FailureToServer();
                        CommonPage.Loading.Hide();
                        return;
                    }
                    var stateCodeStr = revertObj.StateCode.ToUpper();
                    //Error 不能直接从服务器取,只能根据状态码逐一判断
                    if (stateCodeStr == "SUCCESS")
                    {
                        if (revertObj.ResponseData == null)
                        {
                            return;
                        }
 
                        HomePage.Instance.ShowLoginLoadView();
 
                        new System.Threading.Thread(async () =>
                        {
                            //存储数据
                            var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.UserLoginRes>(revertObj.ResponseData.ToString());
                            var revertData = responseDataObj;
                            Config.ReFresh();
                            //标记上一次是不是同一个账号登陆
                            UserCenter.UserCenterResourse.ResidenceOption.TheSameLoginAccount = Config.Instance.Guid == revertData.Guid;
                            Config.Instance.Account = revertData.Account;
                            Config.Instance.Password = passwordStr;
                            Config.Instance.MD5PWD = revertData.MD5PWD;
                            Config.Instance.Guid = revertData.Guid;
                            Config.Instance.LoginDateTime = DateTime.Now;
                            Config.Instance.LoginToken = revertData.Token;
                            if (Config.Instance.AccountList.Find((obj) => obj == revertData.Account) == null)
                            {
                                Config.Instance.AccountList.Add(revertData.Account);
                            }
                            Config.Instance.Save();
 
                            var resultRegID = await Shared.Common.CommonPage.Instance.PushRegID();
                            var homes = await House.GetHomeLists();
                            //刷新个人中心的内存及线程
                            await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
                            //启动ZigBee
                            ZigBee.Common.Application.Init();
 
                            UserCenter.HdlRoomLogic.Current.InitAllRoom();
                            Application.RunOnMainThread(() =>
                            {
                                CommonPage.Loading.Hide();
                                this.RemoveFromParent();
                                CommonPage.Instance.RemoveViewByTag("Login");
                                UserPage.Instance.Fresh();
                            });
                        })
                        { IsBackground = true }.Start();
                    }
                    else if (stateCodeStr == "NOTVERIFY")
                    {
                        CommonPage.Loading.Hide();
                        //未激活
                        loginErrorBtn.TextID = R.MyInternationalizationString.NOTVERIFY;
                    }
                    else if (stateCodeStr == "NOTENABLE")
                    {
                        CommonPage.Loading.Hide();
                        //该用户属于调试账号,并未启用
                        loginErrorBtn.TextID = R.MyInternationalizationString.NOTENABLE;
                    }
                    else if (stateCodeStr == "USERNAMEORPWDERROR")
                    {
                        CommonPage.Loading.Hide();
                        //账号或密码错误
                        loginErrorBtn.TextID = R.MyInternationalizationString.USERNAMEORPWDERROR;
                    }
                    else if (stateCodeStr == "ACCOUNTNOEXISTS")
                    {
                        CommonPage.Loading.Hide();
                        //账号不存在
                        loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS;
                    }
                    else if (stateCodeStr == "YOUDATANOISLOCALREGION")
                    {
                        CommonPage.Loading.Hide();
                        //不在本区域,需要重定向区域后再次请求登录
                        if (revertObj.ResponseData == null)
                        {
                            return;
                        }
                        var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.UserLoginLocalRegionRes>(revertObj.ResponseData.ToString());
                        CommonPage.RequestHttpsHost = responseDataObj.RegionServer;
                        //再次登录
                        Login(accountStr, passwordStr);
                    }
                    else
                    {
                        loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"登录失败--{ex.Message}");
                    CommonPage.Loading.Hide();
                    CommonPage.Instance.FailureToServer();
                }
                finally
                {
                    //CommonPage.Loading.Hide();
                }
                //});
            };
            action();
        }
 
        /// <summary>
        /// CheckAccount
        /// </summary>
        /// <param name="accountStr"></param>
        /// <returns></returns>
        private bool CheckAccount(string accountStr)
        {
            if (phoneEmailForm.SelectedEmail.IsSelected)
            {
                if (AccountLogic.Instance.CheckEmail(accountStr) == false)
                {
                    loginErrorBtn.TextID = R.MyInternationalizationString.TheEmailError;
                    return false;
                }
            }
            else
            {
                if (AccountLogic.Instance.CheckPhone(accountStr) == false)
                {
                    loginErrorBtn.TextID = R.MyInternationalizationString.ThePhoneError;
                    return false;
                }
            }
            return true;
        }
 
        /// <summary>
        /// 通过验证码登录
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void LoginByCode(object sender,MouseEventArgs mouseEventArgs)
        {
            //this.RemoveFromParent();
            var loginByCodePage = new AccountLoginByCode();
            CommonPage.Instance.AddChidren(loginByCodePage);
            loginByCodePage.Show();
        }
 
        /// <summary>
        /// wechat登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void LoginByWechat(object sender, MouseEventArgs mouseEventArgs)
        {
#if Android
            //var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP),
            //    Language.StringByID(R.MyInternationalizationString.LoginByWechat),
            //    Language.StringByID(R.MyInternationalizationString.Cancel),
            //    Language.StringByID(R.MyInternationalizationString.Confrim));
            //alert.Show();
            //alert.ResultEventHandler += (send, e) =>
            //{
                //if (e)
                //{
                    com.hdl.home.Application.WXLogin();
                    com.hdl.home.WXEntryActivity.RespAction = (authStr) =>
                    {
                        if (authStr == null)
                        {
 
                        }
                        else
                        {
                            new System.Threading.Thread(async () =>
                            {
                                var re = await isBindAuthAsync(authStr);
                                if (re)
                                {
                                    Application.RunOnMainThread(() =>
                                    {
                                        //直接登录
                                        HomePage.Instance.ShowLoginLoadView();
                                    });
                                    var resultRegID = await Shared.Common.CommonPage.Instance.PushRegID();
                                    var homes = await House.GetHomeLists();
                                    //刷新个人中心的内存及线程
                                    await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
                                    //启动ZigBee
                                    ZigBee.Common.Application.Init();
                                    UserCenter.HdlRoomLogic.Current.InitAllRoom();
                                    Application.RunOnMainThread(() =>
                                    {
                                        this.RemoveFromParent();
                                        CommonPage.Instance.RemoveViewByTag("Login");
                                        UserPage.Instance.Fresh();
                                    });
                                }
                                else
                                {
                                    var authRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.AuthUserRes>(authStr);
                                    Application.RunOnMainThread(() =>
                                    {
                                        var registerPage = new AccountRegister();
                                        Shared.Common.CommonPage.Instance.AddChidren(registerPage);
                                        registerPage.OpenID = authRes.openid;
                                        registerPage.Show();
                                    });
                                }
                            })
                            { IsBackground = true }.Start();
                        }
                    };
                //}
            //};
#endif
 
#if iOS
            Home.IOS.AppDelegate.WXLogin();
            Home.IOS.AppDelegate.RespAction = (authStr) =>
            {
                if (authStr == null)
                {
 
                }
                else
                {
                    new System.Threading.Thread(async () =>
                    {
 
                        var re = await isBindAuthAsync(authStr);
                        if (re)
                        {
                            //直接登录
                            //this.RemoveFromParent();
 
                            //UserPage.Instance.Fresh();
                            var resultRegID = await Shared.Common.CommonPage.Instance.PushRegID();
                            var homes = await House.GetHomeLists();
                            //启动ZigBee
                            ZigBee.Common.Application.Init();
                            //刷新个人中心的内存及线程
                            await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
                            UserCenter.HdlRoomLogic.Current.InitAllRoom();
                            Application.RunOnMainThread(() =>
                            {
                                this.RemoveFromParent();
                                UserPage.Instance.Fresh();
                            });
                        }
                        else
                        {
                            var authRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.AuthUserRes>(authStr);
                            Application.RunOnMainThread(() =>
                            {
                                var registerPage = new AccountRegister();
                                Shared.Common.CommonPage.Instance.AddChidren(registerPage);
                                registerPage.OpenID = authRes.openid;
                                registerPage.Show();
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                }
            };
#endif
 
 
 
        }
 
        /// <summary>
        /// qq登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void LoginByQQ(object sender, MouseEventArgs mouseEventArgs)
        {
 
        }
 
        /// <summary>
        /// 是否已绑定
        /// </summary>
        /// <param name="authStr"></param>
        /// <returns></returns>
        private async System.Threading.Tasks.Task<bool> isBindAuthAsync(string authStr)
        {
            var authRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.AuthUserRes>(authStr);
            var auth = new SendDataToServer.AuthUser()
            {
                AccessToken = authRes.access_token,
                RefreshToken = authRes.refresh_token,
                OpenID = authRes.openid
            };
            //获取微信昵称
            var strUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + authRes.access_token;
            strUrl += "&openid=" + authRes.openid;
            var byteData = await Common.CommonPage.Instance.DoRequestZigbeeHttpsInterface(strUrl, null, null, "GET");
            if (byteData == null)
            {
                return false;
            }
            var receipData = System.Text.Encoding.UTF8.GetString(byteData);
            var nickData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserCenter.NicknameInfo>(receipData);
            auth.UserName = nickData.nickname;
 
            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(auth);
            var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/InsertOrUpdateAuthUser", System.Text.Encoding.UTF8.GetBytes(requestJson));
            if (revertObj == null)
            {
                return false;
            }
            var stateCodeStr = revertObj.StateCode.ToUpper();
            if (stateCodeStr == "SUCCESS")
            {
                var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.UserLoginRes>(revertObj.ResponseData.ToString());
                var revertData = responseDataObj;
                //标记上一次是不是同一个账号登陆
                UserCenter.UserCenterResourse.ResidenceOption.TheSameLoginAccount = Config.Instance.Guid == revertData.Guid;
                Config.Instance.Account = revertData.Account;
                Config.Instance.MD5PWD = revertData.MD5PWD;
                Config.Instance.Guid = revertData.Guid;
                Config.Instance.LoginDateTime = DateTime.Now;
                if (Config.Instance.AccountList.Find((obj) => obj == revertData.Account) == null)
                {
                    Config.Instance.AccountList.Add(revertData.Account);
                }
                Config.Instance.Save();
                return true;
            }
            else
            {
                return false;
            }
        }
 
        /// <summary>
        /// phone/email 选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void SelectPhoneOrEmail_MouseUpEvent(object sender, MouseEventArgs mouseEventArgs)
        {
            phoneEmailForm.SelectedPhone.IsSelected = phoneEmailForm.SelectedEmail.IsSelected = false;
            phoneEmailForm.SelectedPhone.IsBold = phoneEmailForm.SelectedEmail.IsBold = false;
            loginBtn.Enable = loginBtn.IsSelected = false;
            loginErrorBtn.Text = string.Empty;
            (sender as Button).IsSelected = (sender as Button).IsBold = true;
            if((sender as Button).Tag.ToString()=="Phone")
            {
                AddPhoneOrEmailFL(accountPwdFL, "Phone");
            }
            else
            {
                AddPhoneOrEmailFL(accountPwdFL, "Email");
            }
        }
        /// <summary>
        /// AddPhoneOrEmailFL
        /// </summary>
        /// <param name="accountPwdFrameLayout"></param>
        /// <param name="phoneOrEmail"></param>
        private void AddPhoneOrEmailFL(FrameLayout accountPwdFrameLayout,string phoneOrEmail)
        {
            if (phoneOrEmail == "Phone")
            {
                if (phoneRow != null) 
                {
                    phoneRow.Visible = true;
                    phonePwdRow.Visible = true;
                    if (emailRow != null)
                    { 
                        emailRow.Visible = false;
                        emailPwdRow.Visible = false;
                    }
                    this.Pwd_TextChange(phonePwdRow);
                    return;
                }
                phoneRow = new PhoneLoginRowForm();
                phoneRow.Init(accountPwdFrameLayout, this, this.oldInputAccount, 29, 29);
                phoneRow.AccountET.TextChangeEventHandler += Account_TextChange;
 
                phonePwdRow = new PwdLoginRowForm();
                phonePwdRow.Init(accountPwdFrameLayout, 29, 225);
                phonePwdRow.PasswrodET.TextChangeEventHandler += (sender, e) =>
                {
                    this.Pwd_TextChange(phonePwdRow);
                };
            }
            else
            {
                if (emailRow != null)
                {
                    emailRow.Visible = true;
                    emailPwdRow.Visible = true;
                    if (phoneRow != null) 
                    { 
                        phoneRow.Visible = false;
                        phonePwdRow.Visible = false;
                    }
                    this.Pwd_TextChange(emailPwdRow);
                    return;
                }
                emailRow = new EmailLoginRowForm();
                emailRow.Init(accountPwdFrameLayout, this.oldInputAccount, 29, 29);
                emailRow.AccountET.TextChangeEventHandler += Account_TextChange;
 
                emailPwdRow = new PwdLoginRowForm();
                emailPwdRow.Init(accountPwdFrameLayout, 29, 225);
                emailPwdRow.PasswrodET.TextChangeEventHandler += (sender, e) =>
                {
                    this.Pwd_TextChange(emailPwdRow);
                };
            }
        }
        #endregion
 
 
        #region ◆ 忘记密码________________________
        /// <summary>
        /// 忘记密码
        /// </summary>
        private void ForgetPWD_MouseUpEvent(object sender, MouseEventArgs mouseEventArgs)
        {
            var forgot = new AccountForgetPWD();
            CommonPage.Instance.AddChidren(forgot);
            forgot.Show();
        }
 
        #endregion
 
        #region ◆ 注册_____________________________
 
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void Register(object sender,MouseEventArgs mouseEventArgs)
        {
            var registerPage = new AccountRegister();
            CommonPage.Instance.AddChidren(registerPage);
            registerPage.Show();
        }
 
        #endregion
 
        #region ◆ 账号密码监听______________________
        /// <summary>
        /// 账号监听
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void Account_TextChange(object sender,string mouseEventArgs)
        {
            loginErrorBtn.Text = string.Empty;
        }
 
        /// <summary>
        /// 密码监听事件
        /// </summary>
        /// <param name="pwdRow">Sender.</param>
        private void Pwd_TextChange(PwdLoginRowForm pwdRow)
        {
            loginErrorBtn.Text = string.Empty;
            string pswText = pwdRow.PasswrodET.Text.Trim();
            if (1 <= pswText.Length && pswText.Length <= 16 && (phoneRow.AccountET.Text.Trim().Length > 0 || emailRow?.AccountET.Text.Trim().Length>0))
            {
                loginBtn.Enable = loginBtn.IsSelected = true;
            }
            else if (pswText.Length > 16)
            {
                pwdRow.PasswrodET.Text = pswText.Substring(0, 16);
                if (phoneRow.AccountET.Text.Trim().Length > 0 || emailRow?.AccountET.Text.Trim().Length > 0)
                {
                    loginBtn.Enable = loginBtn.IsSelected = true;
                }
            }
            else
            {
                loginBtn.Enable = loginBtn.IsSelected = false;
            }
        }
 
 
        #endregion
 
    }
}