收藏功能&排行榜功能
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
tween,
|
||||
view,
|
||||
screen,
|
||||
Button,
|
||||
} from "cc";
|
||||
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
|
||||
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
||||
@@ -30,6 +31,7 @@ import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlSe
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import { SceneBgVideoLayer } from "../../../Sub/UI/SceneBgVideoLayer";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
import { GButton } from "../../../Main/Common/GButton";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -87,10 +89,15 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
ImgVidSelect: Node;
|
||||
ImgVidFakePos: Node;
|
||||
|
||||
AddFavoriteBtn: Node;
|
||||
|
||||
// 跟随控制相关属性
|
||||
private isFollowing: boolean = true; // 当前是否处于跟随状态
|
||||
private lastFakePosPosition: Vec3 = new Vec3(); // 记录上次的位置
|
||||
|
||||
// 收藏请求状态标记,防止重复点击
|
||||
private isRequestingBookmark: boolean = false;
|
||||
|
||||
protected onEnable(): void {
|
||||
this.refresh();
|
||||
}
|
||||
@@ -101,6 +108,7 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
|
||||
this.ImgVidSelect = this._nodeTab.ImgVidSelect;
|
||||
this.ImgVidFakePos = this._nodeTab.ImgVidFakePos;
|
||||
this.AddFavoriteBtn = this._nodeTab.AddFavoriteBtn;
|
||||
|
||||
// 初始化位置跟随
|
||||
if (this.ImgVidFakePos) {
|
||||
@@ -111,18 +119,15 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
|
||||
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
||||
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
||||
let desc = "";
|
||||
const tags = LanguageUtils.getText(this.tagKey);
|
||||
// for (let i = 0; i < tags.length; i++) {
|
||||
// if (i != 0) desc += "\n";
|
||||
// desc += tags[i];
|
||||
// }
|
||||
this.tags.string = tags;
|
||||
this.desc.string = LanguageUtils.getText(this.descKey);
|
||||
});
|
||||
|
||||
this.imgToggle.callback = this.bindImgToggle.bind(this);
|
||||
this.videoToggle.callback = this.bindVideoToggle.bind(this);
|
||||
|
||||
GButton.BandClick(this.AddFavoriteBtn, this.OnClickAddFavoriteBtn, this);
|
||||
}
|
||||
|
||||
setVideEnable(enable: boolean) {
|
||||
@@ -263,9 +268,44 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
this.id,
|
||||
resIds
|
||||
);
|
||||
|
||||
// 刷新收藏按钮状态
|
||||
this.refreshAddFavoriteBtn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新收藏按钮状态
|
||||
*/
|
||||
refreshAddFavoriteBtn() {
|
||||
if (!this.AddFavoriteBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const isBookmarked = girlData.isBookmarkGirl(
|
||||
this.category.toString(),
|
||||
this.id
|
||||
);
|
||||
|
||||
// 查找收藏按钮的状态节点(通常命名为 "selected" 或 "checked")
|
||||
// 如果有这样的子节点,根据收藏状态显示/隐藏
|
||||
const selectedNode = this.AddFavoriteBtn.getChildByName("selected");
|
||||
if (selectedNode) {
|
||||
selectedNode.active = isBookmarked;
|
||||
}
|
||||
|
||||
// 如果有未选中状态的节点
|
||||
const unselectedNode = this.AddFavoriteBtn.getChildByName("unselected");
|
||||
if (unselectedNode) {
|
||||
unselectedNode.active = !isBookmarked;
|
||||
}
|
||||
|
||||
logger.log(
|
||||
`[GirlDetailPanel] 收藏按钮状态已刷新: girlId=${this.id}, isBookmarked=${isBookmarked}`
|
||||
);
|
||||
}
|
||||
|
||||
bindImgToggle() {
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
let resIds = girlData.getAllDisplayGrilPhotoId(
|
||||
@@ -348,6 +388,78 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击收藏按钮
|
||||
*/
|
||||
async OnClickAddFavoriteBtn() {
|
||||
// 防止重复点击
|
||||
if (this.isRequestingBookmark) {
|
||||
logger.warn("[GirlDetailPanel] 收藏请求进行中,请稍候");
|
||||
return;
|
||||
}
|
||||
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const isBookmarked = girlData.isBookmarkGirl(
|
||||
this.category.toString(),
|
||||
this.id
|
||||
);
|
||||
|
||||
logger.log(
|
||||
`[GirlDetailPanel] 点击收藏按钮: girlId=${this.id}, 当前状态=${
|
||||
isBookmarked ? "已收藏" : "未收藏"
|
||||
}`
|
||||
);
|
||||
|
||||
try {
|
||||
this.isRequestingBookmark = true;
|
||||
|
||||
// 调用收藏接口
|
||||
const reqData = {
|
||||
girlId: this.id,
|
||||
cancel: isBookmarked, // true=取消收藏, false=添加收藏
|
||||
};
|
||||
const res = await GirlService.I.reqBookmarkGirl(reqData);
|
||||
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
// 更新本地收藏时间
|
||||
if (isBookmarked) {
|
||||
// 取消收藏:设置为0
|
||||
girlData.setBookmarkTime(this.category.toString(), this.id, 0);
|
||||
logger.log(`[GirlDetailPanel] 取消收藏成功: girlId=${this.id}`);
|
||||
} else {
|
||||
// 添加收藏:设置为当前时间戳(秒)
|
||||
const currentTimestamp = Math.floor(Date.now() / 1000);
|
||||
girlData.setBookmarkTime(
|
||||
this.category.toString(),
|
||||
this.id,
|
||||
currentTimestamp
|
||||
);
|
||||
logger.log(
|
||||
`[GirlDetailPanel] 添加收藏成功: girlId=${this.id}, timestamp=${currentTimestamp}`
|
||||
);
|
||||
}
|
||||
|
||||
// 刷新按钮状态
|
||||
this.refreshAddFavoriteBtn();
|
||||
|
||||
// TODO: 可以在这里添加UI提示,比如显示Toast
|
||||
// Utils.showToast(isBookmarked ? "已取消收藏" : "收藏成功");
|
||||
} else {
|
||||
logger.warn(
|
||||
`[GirlDetailPanel] 收藏操作失败: girlId=${this.id}, code=${res?.code}`
|
||||
);
|
||||
// TODO: 显示错误提示
|
||||
// Utils.showToast("操作失败,请稍后重试");
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`[GirlDetailPanel] 收藏操作异常: girlId=${this.id}`, error);
|
||||
// TODO: 显示错误提示
|
||||
// Utils.showToast("网络错误,请稍后重试");
|
||||
} finally {
|
||||
this.isRequestingBookmark = false;
|
||||
}
|
||||
}
|
||||
|
||||
returnBtn() {
|
||||
// GirlDetailPanel现在是subpanel,关闭自己即可
|
||||
NavigationManager.Instance.closeSubPanel(this);
|
||||
|
||||
Reference in New Issue
Block a user