123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- import { sys, tween, Tween, _decorator, Label, EditBox,Node } from 'cc';
- import { UIHelper } from '../../../framework/common/UIHelper';
- import { AudioID } from '../../../framework/config/AudioConf';
- import { FrameworkConf } from '../../../framework/config/FrameworkConf';
- import { ViewID } from '../../../framework/config/LayerConf';
- import { Framework } from '../../../framework/Framework';
- import { BaseView } from '../../../framework/layer/BaseView';
- import { AsyncQueue, NextFunction } from '../../../framework/queue/AsyncQueue';
- import { BulletlPool, DecoratePool, FloatTextPool, GoodsPool, IconPool, MaterialPool, PopPool, RewardPool, RolePool, TipsPool } from '../../common/Pool';
- import { UserData } from '../../data/UserData';
- import { LoginMgr } from '../../common/LoginManager';
- const { ccclass, property } = _decorator;
- export function getParameterByName(name) {
- let url = window.location.href;
- name = name.replace(/[\[\]]/g, "\\$&");
- const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
- const results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
-
- return decodeURIComponent(results[2].replace(/\+/g, ' '));
- //return results[2].replace(/\+/g, ' ')
- }
- @ccclass('LoginUI')
- export class LoginUI extends BaseView {
- @property(Node)
- loginRoot: Node = null;
- @property({type:Label,tooltip:"版本"})
- version: Label = null;
- @property({type:Label,tooltip:"ServerName"})
- serverName: Label = null;
- @property({type:Label,tooltip:"服务器状态"})
- serverState:Label = null;
- @property({type:EditBox,tooltip:"账号"})
- userName: EditBox = null;
- private scene_back = null;
- //登录数据
- private loginData:any = null
- serverData: any;
- server_list: any;
- protected onLoad() {
- super.onLoad();
- this._initPool();
- LoginMgr.init();
- this.version.string = "版本:1.0.0";
- Framework.event.addEvent(FrameworkConf.Event.NET_ERROR, () => {
- // if (this.node.active && this._touchLogin) {
- // if (UserData.player.uuid != "") {
- // this._enterGame(0);
- // } else {
- // UIHelper.buttonEnable(this.Button.btn_login, true);
- // this._touchLogin = false;
- // }
- // }
- }, this);
- Framework.event.addEvent(FrameworkConf.Event.NET_CLOSE, () => {
- // if (this.node.active && this._touchLogin) {
- // if (UserData.player.uuid != "") {
- // this._enterGame(0);
- // } else {
- // UIHelper.buttonEnable(this.Button.btn_login, true);
- // this._touchLogin = false;
- // }
- // }
- }, this);
- Framework.audio.playMusic(AudioID.Game);
-
- let uid = UserData.save_locally('UserID')
- let choose_server = UserData.save_locally('choose_server', null, {})
- this.loginData = {
- url:getParameterByName("url") ||"http://118.178.135.110/sdk/debug/login.php",
- uid:getParameterByName("uid") || uid ||"ttq3",
- token:getParameterByName("token"),
- }
-
- // this.server_list.push(choose_server)
-
- this.userName.string = this.loginData.uid
- // this.serverName.string = "997"
- this.getServerList()
- }
- protected onDestroy() {
- super.onDestroy();
- Framework.event.removeEvent(this);
- this.scene_back()
- }
- //UI开打时会调用,如果有初始化代码应该放到此函数
- onOpen(SceneBack) {
- this.scene_back = SceneBack
- // console.log(window["App_Clue"]);
- // GuideConf
- //this.EditBox.box.string = UserData.save_locally('UserID', null, '');
- }
- //UI关闭时会调用,该函数在onDestroy前调用
- onClose() {
- // Tween.stopAllByTarget(this.Node.sign);
- }
- //框架管理UI层级时会调用,可根据UI情况修改
- onShow() {
- super.onShow();
- }
- //框架管理UI层级时会调用,可根据UI情况修改
- onHide() {
- super.onHide();
- }
- EditTex(text) {
- let reg = new RegExp("^[A-Za-z0-9]+$");
- let str = "";
- for (let i = 0; i < text.length; i++) {
- if (reg.test(text.charAt(i))) {
- str += text.charAt(i);
- }
- }
- this.userName.string = str;
- // this.EditBox.box.focus();
- }
- onLogin() {
- Framework.audio.playEffect(AudioID.Click);
- this.loginData.uid = this.userName.string
- UserData.save_locally('UserID', this.loginData.uid)
- let _gateway_data = {
- openid: this.serverData.openid, //上面获取到的openid
- openkey: this.serverData.openkey, //上面获取到的openkey
- sid: this.server_list.id, // 选择的服务器列表信息中的id
- }
- LoginMgr.getGateway(_gateway_data, this.server_list.host, () => {
- if (UserData['mark'].first_login && UserData['mark'].first_login == 1) {
- Framework.layer.open(ViewID.MainUI, () => {
- Framework.layer.close(ViewID.LoginUI);
- Framework.layer.close(ViewID.SelectServer);
- });
- } else {
- Framework.layer.open(ViewID.MainUI, () => {
- Framework.layer.close(ViewID.LoginUI);
- Framework.layer.close(ViewID.SelectServer);
- });
- }
- })
-
- //
- //登录游戏
- // Framework.layer.close(this);
- // if (this.EditBox.box.string.length > 0) {
- // const match = SensitiveWordFilter.getInstance().containsSensitiveWord(this.EditBox.box.string);
- // if (match) {
- // Framework.tips.setTips(`${match}是敏感词`);
- // return;
- // }
-
- // } else {
- // Framework.tips.setTips('账号只能输入英文和数字并且不可为空!');
- // }
- }
- //UI事件处理
- private onTouchButton(event: Event) {
- let target: any = event.target;
- // LoginMgr.getServerList(1, (data) => {
- // // Framework.layer.close(this);
- // Framework.layer.open(ViewID.ServerList,null,data)
- // })
- return;
- }
- private _enterGame(state: number) {
- // if (UserData.player.uuid == "") {
- // UIHelper.buttonEnable(this.Button.btn_login, true);
- // this._touchLogin = false;
- // Framework.tips.setTips("网络错误,请查看网络是否正常!");
- // this.Button.btn_loginex.node.active = true;
- // return;
- // }
- // if (UserData.player.area == GameConf.AreaType.error) {
- // Framework.layer.open(ViewID.HometownUI, () => {
- // Framework.layer.close(this);
- // });
- // } else {
- //载入界面
- // }
- }
- private _loginEx() {
- //开始登陆
- // if (sys.platform == sys.Platform.WECHAT_GAME) {
- // //微信
- // // @ts-ignore
- // wx.login({
- // success: (result) => {
- // //console.log(result);
- // LoginMgr.check(result.code, (token: string | null) => {
- // if (token) {
- // // LoginMgr.login(1, token, this._enterGame.bind(this));
- // } else {
- // //登录失败
- // this.Button.btn_loginex.node.active = true;
- // Framework.tips.setTips("登录失败");
- // }
- // });
- // },
- // fail: (result) => {
- // console.log(result);
- // this.Button.btn_loginex.node.active = true;
- // }
- // });
- // } else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- // //字节
- // // @ts-ignore
- // tt.login({
- // force: false,
- // success: (result) => {
- // console.log(`login 调用成功${result.code} ------ ${result.anonymousCode}`);
- // LoginMgr.check(result.code, (token: string | null) => {
- // if (token) {
- // // LoginMgr.login(2, token, this._enterGame.bind(this));
- // } else {
- // //登录失败
- // this.Button.btn_loginex.node.active = true;
- // Framework.tips.setTips("登录失败");
- // }
- // });
- // },
- // fail: (result) => {
- // console.log(`login 调用失败`);
- // this.Button.btn_loginex.node.active = true;
- // Framework.tips.setTips("登录失败");
- // },
- // });
- // } else {
- // this.Button.btn_loginex.node.active = true;
- // }
- }
- private _initPool() {
- //初始化池
- // let queue = new AsyncQueue();
- // queue.pushMulti("InitPool", async (next: NextFunction, params: any, args: any) => {
- // //加载道具池
- // MaterialPool.init("package", "prefab/pool/MaterialItem", 15, 120, () => {
- // next && next();
- // console.log("道具池加载成功!");
- // });
- // }, async (next: NextFunction, params: any, args: any) => {
- // Framework.tips.setTipsNode("package", "prefab/other/TipsNode", "Label", () => {
- // next && next();
- // });
- // }, async (next: NextFunction, params: any, args: any) => {
- // RewardPool.init("package", "prefab/other/RewardEffect", 3, 120, () => {
- // next && next();
- // });
- // }, async (next: NextFunction, params: any, args: any) => {
- // BulletlPool.init("package", "prefab/other/Bullet", 6, 120, () => {
- // next && next();
- // });
- // }, async (next: NextFunction, params: any, args: any) => {
- // FloatTextPool.init("package", "prefab/other/FloatText", 10, 120, () => {
- // next && next();
- // });
- // });
- // queue.complete = () => {
- // };
-
- // queue.play();
- this._loginEx();
- }
- //获取服务器列表
- private getServerList() {
- LoginMgr.getServerList((data) => {
- if (data) {
- this.serverData = data;
- let num = 0;
- let idx = 1;
- this.server_list = data.server_list[998]
- this.loginRoot.active = true
-
- // if (Object.keys(this.server_list[0]).length < 1) {
- // let idx = this.server_list.length - 1
- // let choosePic = this.Node.serverTab.getChildByName(this.tabulation).getComponent(Sprite).spriteFrame;
- // this.Node.serverTab.getChildByName(this.tabulation).getComponent(Sprite).spriteFrame = this.Node.serverTab.getChildByName(String(idx * 10)).getComponent(Sprite).spriteFrame;
- // this.Node.serverTab.getChildByName(String(idx * 10)).getComponent(Sprite).spriteFrame = choosePic;
- // this.tabulation = String(idx * 10);
- // this.List.server.numItems = this.server_list[idx].length
- // } else {
- // this.List.server.numItems = 0;
- // }
- }
- }, this.loginData)
- }
- }
|