LoginManager.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. if (WindowsManager.Instance.isTest)
  62. {
  63. data["account"] = "dgj2";
  64. data["password"] = "00000000";
  65. }
  66. else
  67. {
  68. data["account"] = UserManager.Instance.NowChoose.number;
  69. data["password"] = LoginPassWordManager.Instance.tmpField.text;
  70. }
  71. Debug.Log("DGJ ==> Login " + data.ToJson());
  72. HttpTool.Instance.PostLogin(HttpEdustryAction.Login, data.ToJson(), LogingCallBack);
  73. }
  74. else
  75. {
  76. LoginPassWordManager.Instance.toError();
  77. }
  78. }
  79. else
  80. {
  81. WindowsManager.Instance.show(WindowConfig.windowType.Tip2, false, "请选择账号");
  82. }
  83. }
  84. public void initOftenUse()
  85. {
  86. LoginDataManager.Instance.GetOftenUseLoginData((List<AccountData> adata) => {
  87. GameObject smallitem;
  88. GameObject bigitem;
  89. //创建bigLoginItem
  90. bigitem = GameObject.Instantiate(bigOftenUseLoginItem, OftenUseitemRoot.transform);
  91. OftenUsebiglistItem.Add(bigitem);
  92. //创建smallLoginItem
  93. for (int j = 3; j >=0; j--)
  94. {
  95. if(adata.Count>j)
  96. {
  97. smallitem = GameObject.Instantiate(smallLoginItem, bigitem.transform);
  98. SmallLoginItem slitem = smallitem.GetComponent<SmallLoginItem>();
  99. slitem.setData(adata[j],false);
  100. OftenUsebiglistItem.Add(smallitem);
  101. }
  102. else
  103. {
  104. break;
  105. }
  106. }
  107. });
  108. }
  109. public void InitPlayer()
  110. {
  111. LoginDataManager.Instance.GetLoginData((List<AccountData> adata) => {
  112. GameObject smallitem;
  113. GameObject bigitem;
  114. //创建bigLoginItem
  115. for (int i = 0; i < (adata.Count / 10 + 1); i++)
  116. {
  117. bigitem = GameObject.Instantiate(bigLoginItem, itemRoot.transform);
  118. biglistItem.Add(bigitem);
  119. //创建smallLoginItem
  120. int max = i * 10;
  121. for (int j = max; j < max + 10; j++)
  122. {
  123. if (adata.Count > j)
  124. {
  125. smallitem = GameObject.Instantiate(smallLoginItem, bigitem.transform);
  126. SmallLoginItem slitem = smallitem.GetComponent<SmallLoginItem>();
  127. slitem.setData(adata[j],true);
  128. smalllistItem.Add(smallitem);
  129. }
  130. else
  131. {
  132. break;
  133. }
  134. }
  135. }
  136. });
  137. }
  138. public void testOk()
  139. {
  140. isTongxun = false;
  141. ShowInfoTipManager.Instance.closeTip();
  142. WindowsManager.Instance.show(WindowConfig.windowType.ProjectMain);
  143. WindowsManager.Instance.show(WindowConfig.windowType.Top, false);
  144. }
  145. bool isTongxun;
  146. public void LogingCallBack(string msg)
  147. {
  148. Debug.Log(msg);
  149. JObject obj = JObject.Parse(msg);
  150. if (obj["code"].ToString() == "200")
  151. {
  152. string token = obj["data"]["token"].ToString();
  153. login.UserInfo.Instance.Token = token;
  154. HttpEdustryAction.Token = token;
  155. TimerMgr.Instance.CreateTimer(() => { testOk(); }, 1f);
  156. isTongxun = true;
  157. ShowInfoTipManager.Instance.showTip("正在登录,请稍后");
  158. }
  159. else
  160. {
  161. WindowsManager.Instance.show(WindowConfig.windowType.Tip2, false, obj["code"].ToString());
  162. }
  163. }
  164. public void RTCTestLoginCallBack(string msg)
  165. {
  166. isTongxun = false;
  167. ShowInfoTipManager.Instance.closeTip();
  168. Debug.Log(msg);
  169. JObject obj = JObject.Parse(msg);
  170. if (obj["code"].ToString() == "200")
  171. {
  172. string token = obj["data"]["token"].ToString();
  173. login.UserInfo.Instance.Token = token;
  174. WindowsManager.Instance.show(WindowConfig.windowType.ProjectMain);
  175. WindowsManager.Instance.show(WindowConfig.windowType.Top, false);
  176. }
  177. else
  178. {
  179. WindowsManager.Instance.show(WindowConfig.windowType.Tip2, false, obj["code"].ToString());
  180. }
  181. }
  182. public void removeAll()
  183. {
  184. /*
  185. for (int i = 0; i < smalllistItem.Count; i++)
  186. {
  187. }*/
  188. for (int i = 0; i < biglistItem.Count; i++)
  189. {
  190. Destroy(biglistItem[i]);
  191. }
  192. for (int i = 0; i < OftenUsebiglistItem.Count; i++)
  193. {
  194. Destroy(OftenUsebiglistItem[i]);
  195. }
  196. smalllistItem.Clear();
  197. biglistItem.Clear();
  198. OftenUsebiglistItem.Clear();
  199. OftenUsesmalllistItem.Clear();
  200. }
  201. }