LoginUI.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import { sys, tween, Tween, _decorator, Label, EditBox,Node } from 'cc';
  2. import { UIHelper } from '../../../framework/common/UIHelper';
  3. import { AudioID } from '../../../framework/config/AudioConf';
  4. import { FrameworkConf } from '../../../framework/config/FrameworkConf';
  5. import { ViewID } from '../../../framework/config/LayerConf';
  6. import { Framework } from '../../../framework/Framework';
  7. import { BaseView } from '../../../framework/layer/BaseView';
  8. import { AsyncQueue, NextFunction } from '../../../framework/queue/AsyncQueue';
  9. import { BulletlPool, DecoratePool, FloatTextPool, GoodsPool, IconPool, MaterialPool, PopPool, RewardPool, RolePool, TipsPool } from '../../common/Pool';
  10. import { UserData } from '../../data/UserData';
  11. import { LoginMgr } from '../../common/LoginManager';
  12. const { ccclass, property } = _decorator;
  13. export function getParameterByName(name) {
  14. let url = window.location.href;
  15. name = name.replace(/[\[\]]/g, "\\$&");
  16. const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
  17. const results = regex.exec(url);
  18. if (!results) return null;
  19. if (!results[2]) return '';
  20. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  21. //return results[2].replace(/\+/g, ' ')
  22. }
  23. @ccclass('LoginUI')
  24. export class LoginUI extends BaseView {
  25. @property(Node)
  26. loginRoot: Node = null;
  27. @property({type:Label,tooltip:"版本"})
  28. version: Label = null;
  29. @property({type:Label,tooltip:"ServerName"})
  30. serverName: Label = null;
  31. @property({type:Label,tooltip:"服务器状态"})
  32. serverState:Label = null;
  33. @property({type:EditBox,tooltip:"账号"})
  34. userName: EditBox = null;
  35. private scene_back = null;
  36. //登录数据
  37. private loginData:any = null
  38. serverData: any;
  39. server_list: any;
  40. protected onLoad() {
  41. super.onLoad();
  42. this._initPool();
  43. LoginMgr.init();
  44. this.version.string = "版本:1.0.0";
  45. Framework.event.addEvent(FrameworkConf.Event.NET_ERROR, () => {
  46. // if (this.node.active && this._touchLogin) {
  47. // if (UserData.player.uuid != "") {
  48. // this._enterGame(0);
  49. // } else {
  50. // UIHelper.buttonEnable(this.Button.btn_login, true);
  51. // this._touchLogin = false;
  52. // }
  53. // }
  54. }, this);
  55. Framework.event.addEvent(FrameworkConf.Event.NET_CLOSE, () => {
  56. // if (this.node.active && this._touchLogin) {
  57. // if (UserData.player.uuid != "") {
  58. // this._enterGame(0);
  59. // } else {
  60. // UIHelper.buttonEnable(this.Button.btn_login, true);
  61. // this._touchLogin = false;
  62. // }
  63. // }
  64. }, this);
  65. Framework.audio.playMusic(AudioID.Game);
  66. let uid = UserData.save_locally('UserID')
  67. let choose_server = UserData.save_locally('choose_server', null, {})
  68. this.loginData = {
  69. url:getParameterByName("url") ||"http://118.178.135.110/sdk/debug/login.php",
  70. uid:getParameterByName("uid") || uid ||"ttq3",
  71. token:getParameterByName("token"),
  72. }
  73. // this.server_list.push(choose_server)
  74. this.userName.string = this.loginData.uid
  75. // this.serverName.string = "997"
  76. this.getServerList()
  77. }
  78. protected onDestroy() {
  79. super.onDestroy();
  80. Framework.event.removeEvent(this);
  81. this.scene_back()
  82. }
  83. //UI开打时会调用,如果有初始化代码应该放到此函数
  84. onOpen(SceneBack) {
  85. this.scene_back = SceneBack
  86. // console.log(window["App_Clue"]);
  87. // GuideConf
  88. //this.EditBox.box.string = UserData.save_locally('UserID', null, '');
  89. }
  90. //UI关闭时会调用,该函数在onDestroy前调用
  91. onClose() {
  92. // Tween.stopAllByTarget(this.Node.sign);
  93. }
  94. //框架管理UI层级时会调用,可根据UI情况修改
  95. onShow() {
  96. super.onShow();
  97. }
  98. //框架管理UI层级时会调用,可根据UI情况修改
  99. onHide() {
  100. super.onHide();
  101. }
  102. EditTex(text) {
  103. let reg = new RegExp("^[A-Za-z0-9]+$");
  104. let str = "";
  105. for (let i = 0; i < text.length; i++) {
  106. if (reg.test(text.charAt(i))) {
  107. str += text.charAt(i);
  108. }
  109. }
  110. this.userName.string = str;
  111. // this.EditBox.box.focus();
  112. }
  113. onLogin() {
  114. Framework.audio.playEffect(AudioID.Click);
  115. this.loginData.uid = this.userName.string
  116. UserData.save_locally('UserID', this.loginData.uid)
  117. let _gateway_data = {
  118. openid: this.serverData.openid, //上面获取到的openid
  119. openkey: this.serverData.openkey, //上面获取到的openkey
  120. sid: this.server_list.id, // 选择的服务器列表信息中的id
  121. }
  122. LoginMgr.getGateway(_gateway_data, this.server_list.host, () => {
  123. if (UserData['mark'].first_login && UserData['mark'].first_login == 1) {
  124. Framework.layer.open(ViewID.MainUI, () => {
  125. Framework.layer.close(ViewID.LoginUI);
  126. Framework.layer.close(ViewID.SelectServer);
  127. });
  128. } else {
  129. Framework.layer.open(ViewID.MainUI, () => {
  130. Framework.layer.close(ViewID.LoginUI);
  131. Framework.layer.close(ViewID.SelectServer);
  132. });
  133. }
  134. })
  135. //
  136. //登录游戏
  137. // Framework.layer.close(this);
  138. // if (this.EditBox.box.string.length > 0) {
  139. // const match = SensitiveWordFilter.getInstance().containsSensitiveWord(this.EditBox.box.string);
  140. // if (match) {
  141. // Framework.tips.setTips(`${match}是敏感词`);
  142. // return;
  143. // }
  144. // } else {
  145. // Framework.tips.setTips('账号只能输入英文和数字并且不可为空!');
  146. // }
  147. }
  148. //UI事件处理
  149. private onTouchButton(event: Event) {
  150. let target: any = event.target;
  151. // LoginMgr.getServerList(1, (data) => {
  152. // // Framework.layer.close(this);
  153. // Framework.layer.open(ViewID.ServerList,null,data)
  154. // })
  155. return;
  156. }
  157. private _enterGame(state: number) {
  158. // if (UserData.player.uuid == "") {
  159. // UIHelper.buttonEnable(this.Button.btn_login, true);
  160. // this._touchLogin = false;
  161. // Framework.tips.setTips("网络错误,请查看网络是否正常!");
  162. // this.Button.btn_loginex.node.active = true;
  163. // return;
  164. // }
  165. // if (UserData.player.area == GameConf.AreaType.error) {
  166. // Framework.layer.open(ViewID.HometownUI, () => {
  167. // Framework.layer.close(this);
  168. // });
  169. // } else {
  170. //载入界面
  171. // }
  172. }
  173. private _loginEx() {
  174. //开始登陆
  175. // if (sys.platform == sys.Platform.WECHAT_GAME) {
  176. // //微信
  177. // // @ts-ignore
  178. // wx.login({
  179. // success: (result) => {
  180. // //console.log(result);
  181. // LoginMgr.check(result.code, (token: string | null) => {
  182. // if (token) {
  183. // // LoginMgr.login(1, token, this._enterGame.bind(this));
  184. // } else {
  185. // //登录失败
  186. // this.Button.btn_loginex.node.active = true;
  187. // Framework.tips.setTips("登录失败");
  188. // }
  189. // });
  190. // },
  191. // fail: (result) => {
  192. // console.log(result);
  193. // this.Button.btn_loginex.node.active = true;
  194. // }
  195. // });
  196. // } else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
  197. // //字节
  198. // // @ts-ignore
  199. // tt.login({
  200. // force: false,
  201. // success: (result) => {
  202. // console.log(`login 调用成功${result.code} ------ ${result.anonymousCode}`);
  203. // LoginMgr.check(result.code, (token: string | null) => {
  204. // if (token) {
  205. // // LoginMgr.login(2, token, this._enterGame.bind(this));
  206. // } else {
  207. // //登录失败
  208. // this.Button.btn_loginex.node.active = true;
  209. // Framework.tips.setTips("登录失败");
  210. // }
  211. // });
  212. // },
  213. // fail: (result) => {
  214. // console.log(`login 调用失败`);
  215. // this.Button.btn_loginex.node.active = true;
  216. // Framework.tips.setTips("登录失败");
  217. // },
  218. // });
  219. // } else {
  220. // this.Button.btn_loginex.node.active = true;
  221. // }
  222. }
  223. private _initPool() {
  224. //初始化池
  225. // let queue = new AsyncQueue();
  226. // queue.pushMulti("InitPool", async (next: NextFunction, params: any, args: any) => {
  227. // //加载道具池
  228. // MaterialPool.init("package", "prefab/pool/MaterialItem", 15, 120, () => {
  229. // next && next();
  230. // console.log("道具池加载成功!");
  231. // });
  232. // }, async (next: NextFunction, params: any, args: any) => {
  233. // Framework.tips.setTipsNode("package", "prefab/other/TipsNode", "Label", () => {
  234. // next && next();
  235. // });
  236. // }, async (next: NextFunction, params: any, args: any) => {
  237. // RewardPool.init("package", "prefab/other/RewardEffect", 3, 120, () => {
  238. // next && next();
  239. // });
  240. // }, async (next: NextFunction, params: any, args: any) => {
  241. // BulletlPool.init("package", "prefab/other/Bullet", 6, 120, () => {
  242. // next && next();
  243. // });
  244. // }, async (next: NextFunction, params: any, args: any) => {
  245. // FloatTextPool.init("package", "prefab/other/FloatText", 10, 120, () => {
  246. // next && next();
  247. // });
  248. // });
  249. // queue.complete = () => {
  250. // };
  251. // queue.play();
  252. this._loginEx();
  253. }
  254. //获取服务器列表
  255. private getServerList() {
  256. LoginMgr.getServerList((data) => {
  257. if (data) {
  258. this.serverData = data;
  259. let num = 0;
  260. let idx = 1;
  261. this.server_list = data.server_list[998]
  262. this.loginRoot.active = true
  263. // if (Object.keys(this.server_list[0]).length < 1) {
  264. // let idx = this.server_list.length - 1
  265. // let choosePic = this.Node.serverTab.getChildByName(this.tabulation).getComponent(Sprite).spriteFrame;
  266. // this.Node.serverTab.getChildByName(this.tabulation).getComponent(Sprite).spriteFrame = this.Node.serverTab.getChildByName(String(idx * 10)).getComponent(Sprite).spriteFrame;
  267. // this.Node.serverTab.getChildByName(String(idx * 10)).getComponent(Sprite).spriteFrame = choosePic;
  268. // this.tabulation = String(idx * 10);
  269. // this.List.server.numItems = this.server_list[idx].length
  270. // } else {
  271. // this.List.server.numItems = 0;
  272. // }
  273. }
  274. }, this.loginData)
  275. }
  276. }