LoginManager.cs 6.7 KB

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