123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- 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';
- import { StringUtil } from '../../../framework/util/StringUtil';
- import { GameEvent } from '../../data/GameEvent';
- 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, ' '));
-
- }
- @ccclass('LoginUI')
- export class LoginUI extends BaseView {
- @property(Node)
- loginRoot: Node = null;
- @property({ type: Label, tooltip: "版本" })
- version: Label = null;
- @property(Node)
- selectServer: Node = 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
- accountData: any;
- serverData: any;
- protected onLoad() {
- super.onLoad();
- this._initPool();
- LoginMgr.init();
- this.version.string = "版本:1.0.0";
- Framework.event.addEvent(FrameworkConf.Event.NET_ERROR, () => {
-
-
-
-
-
-
-
-
- }, this);
- Framework.event.addEvent(FrameworkConf.Event.NET_CLOSE, () => {
-
-
-
-
-
-
-
-
- }, this);
- Framework.event.addEvent(GameEvent.SelectServer, () => {
- this.updateCurServer(true);
- }, 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.userName.string = this.loginData.uid
-
- }
- protected onDestroy() {
- super.onDestroy();
- Framework.event.removeEvent(this);
- this.scene_back()
- }
-
- onOpen(SceneBack) {
- this.scene_back = SceneBack
-
-
-
- }
-
- onClose() {
-
- }
-
- onShow() {
- super.onShow();
- }
-
- 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;
-
- }
- onLogin() {
- Framework.audio.playEffect(AudioID.Click);
- this.loginData.uid = this.userName.string
- UserData.save_locally('UserID', this.loginData.uid)
- this.getServerList()
- }
- onEnter() {
- let _gateway_data = {
- openid: this.accountData.openId,
- openkey: this.accountData.openKey,
- sid: this.serverData.sid,
- }
- LoginMgr.getGateway(_gateway_data, this.serverData.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);
- });
- }
- })
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- private onTouchButton(event: Event) {
- let target: any = event.target;
- if (target.name == 'select_server') {
- Framework.layer.open(ViewID.SelectServer)
- }
- }
- private _enterGame(state: number) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- private _loginEx() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- private _initPool() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this._loginEx();
- }
-
- private getServerList() {
- LoginMgr.getServerList((data) => {
- if (data) {
- UserData.parseLoginData(data);
- this.accountData = UserData.getAccountData()
- this.updateCurServer()
- }
- }, this.loginData)
- }
- updateCurServer(isRefresh?:boolean) {
- let sid = -1;
- if (isRefresh){
- sid = UserData.getSid();
- }
- if (sid == -1) {
- const roles = UserData.getRoleServers();
- if (roles.length === 0) {
-
- const recmds = UserData.getRecmdServers();
- for (const v of recmds) {
- if (v && v.sid) {
- sid = v.sid;
- break;
- }
- }
- } else {
-
- for (const v of roles) {
- if (v && v.sid) {
- sid = v.sid;
- break;
- }
- }
- }
- }
- let serverData = UserData.getServerBySid(sid)
- if (!serverData) {
- return;
- }
-
- this.serverData = serverData;
- UserData.setSid(serverData['sid'], false);
- this.serverName.string = serverData.name;
- if (serverData.status == 0) {
- this.serverState.string = StringUtil.getLanguageData('维护');
- }else if(serverData.status == 1){
- this.serverState.string = StringUtil.getLanguageData('爆满');
- }else if(serverData.status == 2){
- this.serverState.string = StringUtil.getLanguageData('推荐');
- }
- this.loginRoot.active = false
- this.selectServer.active = true
- }
- }
|