新增登录场景&修改登录逻辑位置
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user