LoginUI.ts 7.2 KB

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