日志控制

This commit is contained in:
chen wei bo
2025-09-21 20:18:30 +08:00
parent 23c038fd14
commit 8f90c1d7cf
23 changed files with 207 additions and 178 deletions
+18 -17
View File
@@ -35,6 +35,7 @@ import proto from "db://assets/Scripts/proto/proto.pb.js";
import GameRootUI from "../../../Main/Common/GameRootUI";
import { MainController } from "../../core/MainController";
import { GirlListPanel } from "./GirlListPanel";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
const { ccclass, property } = _decorator;
@@ -79,7 +80,7 @@ export class ThemePanel extends li_BaseView {
async Show(forceRefresh: boolean = false) {
// 防止重复加载
if (this.isLoading) {
console.log("[ThemePanel] 已在加载中,等待当前加载完成");
logger.log("[ThemePanel] 已在加载中,等待当前加载完成");
if (this.loadingPromise) {
await this.loadingPromise;
}
@@ -123,12 +124,12 @@ export class ThemePanel extends li_BaseView {
// 如果需要强制刷新,先刷新数据
if (forceRefresh) {
console.log("[ThemePanel] 开始强制刷新数据");
logger.log("[ThemePanel] 开始强制刷新数据");
await Promise.all([
MainController.I.refreshThemeData(),
MainController.I.refreshDailyRecommend(),
]);
console.log("[ThemePanel] 数据刷新完成");
logger.log("[ThemePanel] 数据刷新完成");
// 再次检查是否已被取消
if (signal.aborted) {
@@ -138,7 +139,7 @@ export class ThemePanel extends li_BaseView {
// 优先使用MainController中预加载的数据
const preloadStatus = MainController.I.getPreloadStatus();
console.log("[ThemePanel] 预加载状态:", preloadStatus);
logger.log("[ThemePanel] 预加载状态:", preloadStatus);
// 处理主题数据
await this.handleThemeData(preloadStatus.themeData);
@@ -161,13 +162,13 @@ export class ThemePanel extends li_BaseView {
// 处理商品列表数据
await this.handleShopListData(preloadStatus.shopList);
} catch (error) {
console.error("[ThemePanel] Show操作出错:", error);
logger.error("[ThemePanel] Show操作出错:", error);
this._nodeTab.loadingRec.active = false;
// 如果不是取消操作导致的错误,可以考虑显示错误提示
if (error.message !== "Operation was aborted") {
// 这里可以添加错误提示逻辑
console.error("[ThemePanel] 数据加载失败,请稍后重试");
logger.error("[ThemePanel] 数据加载失败,请稍后重试");
}
} finally {
this.abortController = null;
@@ -179,7 +180,7 @@ export class ThemePanel extends li_BaseView {
*/
private async handleThemeData(isPreloaded: boolean): Promise<void> {
if (isPreloaded) {
console.log("[ThemePanel] 使用预加载的主题数据");
logger.log("[ThemePanel] 使用预加载的主题数据");
// 直接使用预加载的数据渲染界面
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
if (themeData && themeData.themes) {
@@ -189,7 +190,7 @@ export class ThemePanel extends li_BaseView {
}
// 如果没有预加载数据,则请求数据
console.log("[ThemePanel] 请求主题数据");
logger.log("[ThemePanel] 请求主题数据");
const reqData = {};
let res = await ThemeService.I.reqHallTheme(reqData);
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
@@ -220,7 +221,7 @@ export class ThemePanel extends li_BaseView {
*/
private async handleDailyRecommendData(isPreloaded: boolean): Promise<void> {
if (isPreloaded) {
console.log("[ThemePanel] 使用预加载的每日推荐数据");
logger.log("[ThemePanel] 使用预加载的每日推荐数据");
// 直接使用预加载的数据渲染界面
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
if (girlData) {
@@ -230,7 +231,7 @@ export class ThemePanel extends li_BaseView {
}
// 如果没有预加载数据,则请求数据
console.log("[ThemePanel] 请求每日推荐数据");
logger.log("[ThemePanel] 请求每日推荐数据");
const reqData = {};
let res = await GirlService.I.reqDailyRecommend(reqData);
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
@@ -266,13 +267,13 @@ export class ThemePanel extends li_BaseView {
*/
private async handleShopListData(isPreloaded: boolean): Promise<void> {
if (isPreloaded) {
console.log("[ThemePanel] 商品列表数据已预加载");
logger.log("[ThemePanel] 商品列表数据已预加载");
// 数据已经在DataManager中,不需要额外处理
return;
}
// 如果没有预加载数据,则请求数据
console.log("[ThemePanel] 请求商品列表数据");
logger.log("[ThemePanel] 请求商品列表数据");
await this.reqShopList();
}
@@ -336,7 +337,7 @@ export class ThemePanel extends li_BaseView {
}
openMsgBox() {
console.log("打开信箱");
logger.log("打开信箱");
}
// 刷新余额
@@ -380,7 +381,7 @@ export class ThemePanel extends li_BaseView {
*/
private clearCache(): void {
if (this.cache && this.cache.length > 0) {
console.log(`[ThemePanel] 清理 ${this.cache.length} 个缓存节点`);
logger.log(`[ThemePanel] 清理 ${this.cache.length} 个缓存节点`);
for (let i = this.cache.length - 1; i >= 0; i--) {
if (this.cache[i] && this.cache[i].node && this.cache[i].node.isValid) {
this.cache[i].node.destroy();
@@ -394,7 +395,7 @@ export class ThemePanel extends li_BaseView {
* 页面被隐藏时调用
*/
public onHide(): void {
console.log("[ThemePanel] onHide called");
logger.log("[ThemePanel] onHide called");
this.cancelCurrentOperation();
}
@@ -403,14 +404,14 @@ export class ThemePanel extends li_BaseView {
*/
private cancelCurrentOperation(): void {
if (this.abortController) {
console.log("[ThemePanel] 取消当前操作");
logger.log("[ThemePanel] 取消当前操作");
this.abortController.abort();
this.abortController = null;
}
}
onDestroy(): void {
console.log("[ThemePanel] onDestroy called");
logger.log("[ThemePanel] onDestroy called");
// 取消当前操作
this.cancelCurrentOperation();