LoginManager.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using LitJson;
  2. using Newtonsoft.Json.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class LoginManager : MonoSingleton<LoginManager>
  7. {
  8. //账号列表
  9. [HideInInspector]
  10. public GameObject bigLoginItem;
  11. [HideInInspector]
  12. public GameObject smallLoginItem;
  13. public GameObject itemRoot;
  14. [HideInInspector]
  15. public List<GameObject> biglistItem = new List<GameObject>();
  16. [HideInInspector]
  17. public List<GameObject> smalllistItem = new List<GameObject>();
  18. //常驻列表
  19. [HideInInspector]
  20. public GameObject bigOftenUseLoginItem;
  21. [HideInInspector]
  22. public List<GameObject> OftenUsesmalllistItem = new List<GameObject>();
  23. [HideInInspector]
  24. public List<GameObject> OftenUsebiglistItem = new List<GameObject>();
  25. public GameObject OftenUseitemRoot;
  26. private void Start()
  27. {
  28. bigLoginItem = WindowsManager.Instance.GetPrefab(WindowConfig.windowType.Login,"bigLoginItem");
  29. smallLoginItem = WindowsManager.Instance.GetPrefab(WindowConfig.windowType.Login, "smallLoginItem");
  30. bigOftenUseLoginItem = WindowsManager.Instance.GetPrefab(WindowConfig.windowType.Login, "bigOftenUseLoginItem");
  31. Instance.removeAll();
  32. Instance.InitPlayer();
  33. Instance.initOftenUse();
  34. }
  35. public void ExitUser()
  36. {
  37. removeAll();
  38. InitPlayer();
  39. initOftenUse();
  40. }
  41. public void GotoLogin()
  42. {
  43. if(isTongxun)
  44. {
  45. return;
  46. }
  47. if (UserManager.Instance.NowChoose != null)
  48. {
  49. if (LoginPassWordManager.Instance.tmpField.text.Length > 4)
  50. {
  51. JsonData data = new JsonData();
  52. data["account"] = "13910723157";
  53. data["password"] = "1";
  54. HttpTool.Instance.PostLogin("/cmcc-endustry/v1/user/login", data.ToJson(), LoginCallBack);
  55. isTongxun = true;
  56. ShowInfoTipManager.Instance.showTip("正在登录,请稍后");
  57. }
  58. else
  59. {
  60. LoginPassWordManager.Instance.toError();
  61. }
  62. }
  63. else
  64. {
  65. WindowsManager.Instance.show(WindowConfig.windowType.Tip2, false, "请选择账号");
  66. }
  67. }
  68. public void initOftenUse()
  69. {
  70. LoginDataManager.Instance.GetOftenUseLoginData((List<AccountData> adata) => {
  71. GameObject smallitem;
  72. GameObject bigitem;
  73. //创建bigLoginItem
  74. bigitem = GameObject.Instantiate(bigOftenUseLoginItem, OftenUseitemRoot.transform);
  75. OftenUsebiglistItem.Add(bigitem);
  76. //创建smallLoginItem
  77. for (int j = 3; j >=0; j--)
  78. {
  79. if(adata.Count>j)
  80. {
  81. smallitem = GameObject.Instantiate(smallLoginItem, bigitem.transform);
  82. SmallLoginItem slitem = smallitem.GetComponent<SmallLoginItem>();
  83. slitem.setData(adata[j],false);
  84. OftenUsebiglistItem.Add(smallitem);
  85. }
  86. else
  87. {
  88. break;
  89. }
  90. }
  91. });
  92. }
  93. public void InitPlayer()
  94. {
  95. LoginDataManager.Instance.GetLoginData((List<AccountData> adata) => {
  96. GameObject smallitem;
  97. GameObject bigitem;
  98. //创建bigLoginItem
  99. for (int i = 0; i < (adata.Count / 10 + 1); i++)
  100. {
  101. bigitem = GameObject.Instantiate(bigLoginItem, itemRoot.transform);
  102. biglistItem.Add(bigitem);
  103. //创建smallLoginItem
  104. for (int j = i; j < i + 10; j++)
  105. {
  106. if (adata.Count > j)
  107. {
  108. smallitem = GameObject.Instantiate(smallLoginItem, bigitem.transform);
  109. SmallLoginItem slitem = smallitem.GetComponent<SmallLoginItem>();
  110. slitem.setData(adata[j],true);
  111. smalllistItem.Add(smallitem);
  112. }
  113. else
  114. {
  115. break;
  116. }
  117. }
  118. }
  119. });
  120. }
  121. bool isTongxun;
  122. public void LoginCallBack(string msg)
  123. {
  124. isTongxun = false;
  125. ShowInfoTipManager.Instance.closeTip();
  126. Debug.Log(msg);
  127. JObject obj = JObject.Parse(msg);
  128. if (obj["code"].ToString() == "200")
  129. {
  130. string token = obj["data"]["token"].ToString();
  131. login.UserInfo.Instance.Token = token;
  132. WindowsManager.Instance.show(WindowConfig.windowType.ProjectMain);
  133. WindowsManager.Instance.show(WindowConfig.windowType.Top, false);
  134. }
  135. else
  136. {
  137. WindowsManager.Instance.show(WindowConfig.windowType.Tip2, false, obj["code"].ToString());
  138. }
  139. }
  140. public void removeAll()
  141. {
  142. /*
  143. for (int i = 0; i < smalllistItem.Count; i++)
  144. {
  145. }*/
  146. for (int i = 0; i < biglistItem.Count; i++)
  147. {
  148. Destroy(biglistItem[i]);
  149. }
  150. for (int i = 0; i < OftenUsebiglistItem.Count; i++)
  151. {
  152. Destroy(OftenUsebiglistItem[i]);
  153. }
  154. smalllistItem.Clear();
  155. biglistItem.Clear();
  156. OftenUsebiglistItem.Clear();
  157. OftenUsesmalllistItem.Clear();
  158. }
  159. }