Files
18xchat/assets/Scripts/chat18x/ui/panels/PersonalPanel.ts
T
2025-10-13 16:20:37 +08:00

168 lines
4.7 KiB
TypeScript

import { _decorator, isCCObject, Label, Node, Sprite } from "cc";
import Utils from "../../../Main/Common/Utils";
import li_BaseView from "../../../Main/Common/li_BaseView";
import { GButton } from "../../../Main/Common/GButton";
import { DataManager, DataId } from "../../data/DataManager";
import { PlayerData } from "../../data/PlayerData";
import { AccountData } from "../../data/AccountData";
import { WalletData } from "../../data/WalletData";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import {
NavigationManager,
PageTransitionType,
} from "../../manager/NavigationManager";
import { PlayerDataService } from "../../network/services/PlayerDataService";
import proto from "db://assets/Scripts/proto/proto.pb.js";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
import { TipsPanel } from "./TipsPanel";
const { ccclass, property } = _decorator;
@ccclass("PersonalPanel")
export class PersonalPanel extends li_BaseView {
private _nodeTab: any = {};
@property(Label)
private userNameLabel: Label = null;
@property(Label)
private userIdLabel: Label = null;
@property(Label)
private balanceLabel: Label = null;
@property(Label)
private vipStatusLabel: Label = null;
@property(Sprite)
private avatarSprite: Sprite = null;
@property([Node])
private vipStuff: Node[] = [];
@property([Node])
private notVipStuff: Node[] = [];
private playerData: PlayerData = null;
private accountData: AccountData = null;
private walletData: WalletData = null;
protected start(): void {
Utils.parseNode(this.node, this._nodeTab);
this.initUI();
this.registerListener();
this.refresh();
}
onEnable() {
this.initData();
this.refresh();
}
private initData(): void {
this.playerData = DataManager.I.getDataById<PlayerData>(DataId.Player);
this.accountData = DataManager.I.getDataById<AccountData>(DataId.Account);
this.walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
}
private initUI(): void {}
private registerListener(): void {
// 注册关闭按钮
if (this._nodeTab.closeBtn) {
GButton.BandClick(this._nodeTab.closeBtn, this.close, this);
}
if (this._nodeTab.WalletBtn) {
GButton.BandClick(this._nodeTab.WalletBtn, this.openPurchase, this);
}
// 注册设置按钮
if (this._nodeTab.settingBtn) {
GButton.BandClick(this._nodeTab.settingBtn, this.openSettings, this);
}
//
if (this._nodeTab.favoritesBtn) {
GButton.BandClick(this._nodeTab.favoritesBtn, this.openFavorites, this);
}
}
private async refresh() {
const reqData = {};
let res = await PlayerDataService.I.reqMyInfo(reqData);
logger.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);
}
this.updateUserInfo();
this.updateBalance();
this.updateVipStatus();
}
private updateUserInfo() {
// 更新用户名
if (this.userNameLabel && this.playerData) {
const userName = this.playerData.name || "未设置";
this.userNameLabel.string = userName;
}
// 更新用户ID
if (this.userIdLabel && this.accountData) {
const userId = this.accountData.accId || "游客";
this.userIdLabel.string = `uid: ${userId}`;
}
// 头像暂时留空,等待资源配置
if (this.avatarSprite) {
// TODO: 设置默认头像或从数据中获取头像
}
}
private updateBalance(): void {
if (this.balanceLabel && this.walletData) {
const balance = this.walletData.getOriginalBalance();
this.balanceLabel.string = `${balance}`;
}
}
private updateVipStatus(): void {
let isVip = false;
if (this.vipStatusLabel && this.walletData) {
const vipExpire = this.walletData.vipExpire;
if (vipExpire && this.walletData.isVip) {
const leftTime = Utils.formatVipLeftTime(vipExpire);
this.vipStatusLabel.string = leftTime;
isVip = true;
} else {
// this.vipStatusLabel.string = LanguageUtils.getText(
// "purchasepanel.notvip"
// );
}
}
this.vipStuff.forEach((n) => (n.active = isVip));
this.notVipStuff.forEach((n) => (n.active = !isVip));
}
private openSettings(): void {
// TODO: 打开设置面板
NavigationManager.Instance.openPopupPanel("SettingPanel", this.node);
}
private openPurchase() {
NavigationManager.Instance.openPopupPanel("PurchasePanel");
}
private openFavorites() {
TipsPanel.show(LanguageUtils.getText("rankpanel.comingsoon"));
}
}