LoginUI.ts 9.5 KB

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