2025-09-10 12:29:05 +08:00
|
|
|
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";
|
2025-09-15 11:57:21 +08:00
|
|
|
import { GlobalData } from "../../chat18x/data/GlobalData";
|
2025-09-10 12:29:05 +08:00
|
|
|
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";
|
2025-09-15 11:57:21 +08:00
|
|
|
import { CommonService } from "db://assets/Scripts/chat18x/network/services/CommonService";
|
2025-09-10 12:29:05 +08:00
|
|
|
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 = {
|
2025-09-11 16:32:16 +08:00
|
|
|
platType: "guest",
|
2025-09-10 12:29:05 +08:00
|
|
|
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();
|
2025-09-15 11:57:21 +08:00
|
|
|
this.reqGlobalData();
|
2025-09-10 12:29:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 11:57:21 +08:00
|
|
|
// 请求个人数据
|
2025-09-10 12:29:05 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 11:57:21 +08:00
|
|
|
// 请求全局数据
|
|
|
|
|
private async reqGlobalData() {
|
|
|
|
|
const reqData = {
|
|
|
|
|
resName: "TbGlobalConfig",
|
|
|
|
|
};
|
|
|
|
|
let res = await CommonService.I.reqResConfig(reqData);
|
|
|
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
|
|
|
// 保存数据
|
|
|
|
|
const globalData = DataManager.I.getDataById<GlobalData>(DataId.Global);
|
|
|
|
|
globalData.globals = res.data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 12:29:05 +08:00
|
|
|
private enterGame() {
|
|
|
|
|
ResManager.I.goMainScene();
|
|
|
|
|
}
|
|
|
|
|
}
|