新增登录场景&修改登录逻辑位置
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { _decorator, Button, Component, Node } from "cc";
|
||||
import li_BaseView from "../../Main/Common/li_BaseView";
|
||||
import Utils from "../../Main/Common/Utils";
|
||||
import { GButton } from "../../Main/Common/GButton";
|
||||
import ResManager from "../../Main/Manager/ResManager";
|
||||
import { DataManager, DataId } from "../../chat18x/data/DataManager";
|
||||
import { LoginData } from "../../chat18x/data/LoginData";
|
||||
import { PlayerData } from "../../chat18x/data/PlayerData";
|
||||
import { AccountData } from "../../chat18x/data/AccountData";
|
||||
import { WalletData } from "../../chat18x/data/WalletData";
|
||||
import { EnvData } from "../../chat18x/data/EnvData";
|
||||
import DeviceIdService from "db://assets/Scripts/chat18x/foundation/identity/DeviceIdService";
|
||||
import MachineInfoService from "db://assets/Scripts/chat18x/foundation/identity/MachineInfoService";
|
||||
import { AuthService } from "db://assets/Scripts/chat18x/network/services/AuthService";
|
||||
import { PlayerDataService } from "db://assets/Scripts/chat18x/network/services/PlayerDataService";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("LoginUI")
|
||||
export class LoginUI extends li_BaseView {
|
||||
private _nodeTab: any = {};
|
||||
private loginFinish = false;
|
||||
|
||||
loginBtn: Node;
|
||||
protected start(): void {
|
||||
Utils.parseNode(this.node, this._nodeTab);
|
||||
|
||||
this.loginBtn = this._nodeTab.btnLogin;
|
||||
|
||||
GButton.BandClick(this.loginBtn, this.onLogin, this);
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
if (this.loginFinish) {
|
||||
this.loginFinish = false;
|
||||
this.enterGame();
|
||||
}
|
||||
}
|
||||
|
||||
async onLogin() {
|
||||
const deviceId = DeviceIdService.I.id;
|
||||
const os = MachineInfoService.I.getMachineOs();
|
||||
const reqData = {
|
||||
platType: "guset",
|
||||
userId: deviceId,
|
||||
device: deviceId,
|
||||
os,
|
||||
};
|
||||
console.log("登录请求数据:", reqData);
|
||||
let res = await AuthService.I.login(reqData);
|
||||
console.log("登录响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
const loginData = DataManager.I.getDataById<LoginData>(DataId.Login);
|
||||
loginData.token = resData.token;
|
||||
loginData.refreshToken = resData.refreshToken;
|
||||
loginData.expire = Number(resData.expire);
|
||||
const playerData = DataManager.I.getDataById<PlayerData>(DataId.Player);
|
||||
playerData.name = resData.name;
|
||||
const accountData = DataManager.I.getDataById<AccountData>(
|
||||
DataId.Account
|
||||
);
|
||||
accountData.accId = resData.accId;
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
envData.cdn = resData.cdn;
|
||||
|
||||
this.loginFinish = true;
|
||||
this.reqMyInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private async reqMyInfo() {
|
||||
const reqData = {};
|
||||
let res = await PlayerDataService.I.reqMyInfo(reqData);
|
||||
console.log("个人信息响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||
walletData.balance = Number(resData.balance);
|
||||
walletData.vipExpire = Number(resData.vipExpire);
|
||||
}
|
||||
}
|
||||
|
||||
private enterGame() {
|
||||
ResManager.I.goMainScene();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0fa6dc01-de0d-4847-ae6c-624111814d80",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -25,34 +25,19 @@ import Utils from "../../Main/Common/Utils";
|
||||
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
|
||||
import { promptItem } from "../Item/promptItem";
|
||||
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
|
||||
import { DataManager, DataId } from "../../chat18x/data/DataManager";
|
||||
import { LoginData } from "../../chat18x/data/LoginData";
|
||||
import { PlayerData } from "../../chat18x/data/PlayerData";
|
||||
import { AccountData } from "../../chat18x/data/AccountData";
|
||||
import { WalletData } from "../../chat18x/data/WalletData";
|
||||
import { EnvData } from "../../chat18x/data/EnvData";
|
||||
import { DataManager } from "../../chat18x/data/DataManager";
|
||||
import { ConfigManager } from "../../chat18x/manager/ConfigManager";
|
||||
import { AppConfig } from "db://assets/Scripts/chat18x/config/env/appConfig";
|
||||
import DeviceIdService from "db://assets/Scripts/chat18x/foundation/identity/DeviceIdService";
|
||||
import MachineInfoService from "db://assets/Scripts/chat18x/foundation/identity/MachineInfoService";
|
||||
import { AuthService } from "db://assets/Scripts/chat18x/network/services/AuthService";
|
||||
import { PlayerDataService } from "db://assets/Scripts/chat18x/network/services/PlayerDataService";
|
||||
import { ApiCode } from "db://assets/Scripts/chat18x/network/client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PreloadUI")
|
||||
export class PreloadUI extends Component {
|
||||
private checkFinish = true; //检查完成
|
||||
private preloadFinish = false; //资源加载完成
|
||||
private loginFinish = false; //登录完成
|
||||
|
||||
private jinduBar: Node = null;
|
||||
private jinduFilled: Sprite = null;
|
||||
//private LabProgress: Label = null;
|
||||
private loginNode: Node = null;
|
||||
private btnLogin: Node = null; //登录按钮
|
||||
|
||||
start() {
|
||||
//Utils.addInnerEL(InnerMsgCode.UI_ShowPrompt, this, this.resiveShowPrompt)
|
||||
@@ -62,16 +47,11 @@ export class PreloadUI extends Component {
|
||||
.getChildByName("jinduFilled")
|
||||
.getComponent(Sprite);
|
||||
|
||||
this.loginNode = this.node.getChildByName("loginNode");
|
||||
this.btnLogin = this.loginNode.getChildByName("btnLogin");
|
||||
|
||||
//适配背景图
|
||||
let BG = this.node.getChildByName("BG");
|
||||
Utils.adjustBgPixelRatio(BG, 1);
|
||||
|
||||
this.jinduFilled.fillRange = 0;
|
||||
// 注册监听
|
||||
this.registerListener();
|
||||
|
||||
// 初始化配置
|
||||
ConfigManager.I.init();
|
||||
@@ -97,11 +77,9 @@ export class PreloadUI extends Component {
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
if (this.checkFinish) {
|
||||
if (this.preloadFinish && this.loginFinish) {
|
||||
this.checkFinish = false;
|
||||
this.enterGame();
|
||||
}
|
||||
if (this.preloadFinish) {
|
||||
this.preloadFinish = false;
|
||||
this.goToLoginScene();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +173,6 @@ export class PreloadUI extends Component {
|
||||
});
|
||||
} else {
|
||||
this.preloadFinish = true;
|
||||
this.enterLoginModule();
|
||||
}
|
||||
};
|
||||
preloadFunc();
|
||||
@@ -206,120 +183,11 @@ export class PreloadUI extends Component {
|
||||
this.jinduFilled.fillRange = percent;
|
||||
}
|
||||
|
||||
// 进入登录模块
|
||||
private enterLoginModule() {
|
||||
//this.LabProgress.node.active = false;
|
||||
// 跳转到登录场景
|
||||
private goToLoginScene() {
|
||||
this.jinduBar.active = false;
|
||||
this.loginNode.active = true;
|
||||
ResManager.I.goCustomScene("LoginScene");
|
||||
}
|
||||
|
||||
//登录
|
||||
async onLogin() {
|
||||
//初始化SDK信息
|
||||
// SDKManager.init(() => {
|
||||
// //检测是否有授权,有授权直接登录,没有授权就先进主界面,到主界面获取权限
|
||||
// SDKManager.checkAutoSetting("userInfo", (ishave) => {
|
||||
// if (ishave) {
|
||||
// console.log("有授权,直接登录")
|
||||
// HttpUnit.ins.login((loginData) => {
|
||||
// if (loginData == null) {
|
||||
// //登录失败,这里处理重复登录的逻辑
|
||||
// } else {
|
||||
// this.loginFinish = true
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// console.log("没有授权,等待授权后登录")
|
||||
// // this.loginFinish = true
|
||||
// this.jinduBar.active = false
|
||||
// this.LabProgress.node.active = false
|
||||
// //登录按钮
|
||||
// this.btnLogin.node.active = true
|
||||
// let loginPath = ""
|
||||
// if (SDKManager.isWenxin()) {
|
||||
// loginPath = "login1"
|
||||
// } else if (SDKManager.isByteDance()) {
|
||||
// loginPath = "login2"
|
||||
// } else if (SDKManager.isKuaishou()) {
|
||||
// loginPath = "login3"
|
||||
// }
|
||||
// ResManager.I.changeResourceSpriteFrame(this.btnLogin, loginPath)
|
||||
//
|
||||
// HttpUnit.ins.login((loginData) => {
|
||||
// if (loginData == null) {
|
||||
// //登录失败,这里处理重复登录的逻辑
|
||||
// } else {
|
||||
// this.loginFinish = true
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
|
||||
// 游客登录
|
||||
const deviceId = DeviceIdService.I.id;
|
||||
const os = MachineInfoService.I.getMachineOs();
|
||||
const reqData = {
|
||||
platType: "guset",
|
||||
userId: deviceId,
|
||||
device: deviceId,
|
||||
os,
|
||||
};
|
||||
console.log("登录请求数据:", reqData);
|
||||
let res = await AuthService.I.login(reqData);
|
||||
console.log("登录响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const loginData = DataManager.I.getDataById<LoginData>(DataId.Login);
|
||||
loginData.token = resData.token;
|
||||
loginData.refreshToken = resData.refreshToken;
|
||||
loginData.expire = Number(resData.expire);
|
||||
const playerData = DataManager.I.getDataById<PlayerData>(DataId.Player);
|
||||
playerData.name = resData.name;
|
||||
const accountData = DataManager.I.getDataById<AccountData>(
|
||||
DataId.Account
|
||||
);
|
||||
accountData.accId = resData.accId;
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
envData.cdn = resData.cdn;
|
||||
|
||||
this.loginFinish = true;
|
||||
// 请求个人信息
|
||||
this.reqMyInfo();
|
||||
}
|
||||
}
|
||||
|
||||
// 请求个人信息
|
||||
private async reqMyInfo() {
|
||||
const reqData = {};
|
||||
let res = await PlayerDataService.I.reqMyInfo(reqData);
|
||||
console.log("个人信息响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||
walletData.balance = Number(resData.balance);
|
||||
walletData.vipExpire = Number(resData.vipExpire);
|
||||
}
|
||||
}
|
||||
|
||||
enterGame() {
|
||||
//let islogin = HttpUnit.IsLogin();
|
||||
//console.log("进入游戏,登录状态:", islogin);
|
||||
this.jinduBar.active = false;
|
||||
//this.LabProgress.node.active = false;
|
||||
//this.btnLogin.node.active = false
|
||||
// if (islogin) {
|
||||
// } else {
|
||||
// //没登录成功,先进主界面,在主界面里进行登录
|
||||
// }
|
||||
|
||||
ResManager.I.goMainScene(); //进入下一个场景
|
||||
// ResManager.I.goCustomScene("Test2DScene"); //进入自定义场景
|
||||
}
|
||||
|
||||
private registerListener() {
|
||||
GButton.BandClick(this.btnLogin, this.onLogin, this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user