From 29554bb0c86ab7a192413acc6ac97aea21cc00d6 Mon Sep 17 00:00:00 2001 From: chen wei bo <1025839511@qq.com> Date: Tue, 2 Sep 2025 16:38:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E6=95=B0=E6=8D=AE=EF=BC=9A?= =?UTF-8?q?=E6=8A=80=E5=B8=88=E7=9A=84=E7=AE=80=E8=A6=81=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network/services/MockGirlService.ts | 42 +++++++++++++++++-- .../chat18x/ui/panels/GirlListPanel.ts | 39 ++++++++++++----- .../Scripts/chat18x/ui/panels/ThemePanel.ts | 4 +- .../Scripts/chat18x/uiitems/GirlListItem.ts | 30 ++++++++----- 4 files changed, 88 insertions(+), 27 deletions(-) diff --git a/assets/Scripts/chat18x/network/services/MockGirlService.ts b/assets/Scripts/chat18x/network/services/MockGirlService.ts index 97ea9b67..fd57a6cf 100644 --- a/assets/Scripts/chat18x/network/services/MockGirlService.ts +++ b/assets/Scripts/chat18x/network/services/MockGirlService.ts @@ -61,10 +61,46 @@ export class MockGirlService implements IGirlService { // 获取技师列表 async reqGetGirlList(req: proto.cs.ICSGetGirlListReq): Promise> { + // 延时 await this.delay(200); - const base = (req?.category ?? 0) * 1000 + (req?.page ?? 1) * 100; - const limit = Math.max(1, Math.min(req?.limit ?? 10, 50)); - const girls = Array.from({ length: limit }, (_, i) => this.genBrief(base + i, "", 1, "", 2, 3, "", 4)); + + const configData = ConfigManager.I.getDataById(ConfigId.Girl); + const allId = configData.getAllId(); + + // 按 category 精确匹配 + const category = Number(req?.category ?? -1); + const filteredIds = category >= 0 + ? allId.filter((id: number) => { + const cat = Number(configData.getCategoryById(id) ?? -1); + return cat === category; + }) + : allId; + + // 分页 + const page = Math.max(1, Number(req?.page ?? 1)); + const limit = Math.max(1, Math.min(Number(req?.limit ?? 10), 50)); + const start = (page - 1) * limit; + const pageIds = filteredIds.slice(start, start + limit); + + // 映射为 IGirlBrief + const girls: proto.cs.IGirlBrief[] = pageIds.map((id: number) => { + const name = configData.getNameById(id); + const age = Number(configData.getAgeById(id)); + const tagKey = configData.getTagKeyById(id); + const priceType = Number(configData.getPriceTypeById(id)); + const avatar = configData.getAvatarPathById(id); + + // 如果有价格配置,就用配置里的,否则给个兜底值 + const price = typeof (configData as any).getPriceById === "function" + ? Number((configData as any).getPriceById(id) ?? 9.9) + : 9.9; + + // 星级兜底:1~5 + const star = (id % 5) + 1; + + return this.genBrief(id, name, age, tagKey, priceType, price, avatar, star); + }); + return this.ok({ girls }); } diff --git a/assets/Scripts/chat18x/ui/panels/GirlListPanel.ts b/assets/Scripts/chat18x/ui/panels/GirlListPanel.ts index 6cf9653c..7cf8909b 100644 --- a/assets/Scripts/chat18x/ui/panels/GirlListPanel.ts +++ b/assets/Scripts/chat18x/ui/panels/GirlListPanel.ts @@ -4,6 +4,11 @@ import Utils from "db://assets/Scripts/Main/Common/Utils"; import { GButton } from "db://assets/Scripts/Main/Common/GButton"; import { GirlListItem } from "../../uiitems/GirlListItem"; import { ConfigManager } from "../../manager/ConfigManager"; +import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService"; +import { DataManager, DataId } from "../../data/DataManager"; +import { GirlData } from "../../data/GirlData"; +import proto from 'db://assets/Scripts/proto/proto.pb.js'; + const { ccclass, property } = _decorator; @ccclass("GirlListPanel") @@ -28,22 +33,34 @@ export class GirlListPanel extends li_BaseView { this.refresh(this.category); } - refresh(category: number) { + async refresh(category: number) { if (this.cache) { for (let i = this.cache.length - 1; i >= 0; i--) { this.cache[i].node.destroy(); } } - const GirlsData = ConfigManager.tables.TbGirls.getDataList(); - const config = GirlsData.filter((value) => value.category == category); - for (let i = 0; i < config.length; i++) { - const cfg = config[i]; - let newNode = instantiate(this.itemInst.node); - let item = newNode.getComponent(GirlListItem); - item.refreshData(cfg, this.node); - newNode.active = true; - this.cache.push(item); - this.content.addChild(newNode); + + // 请求列表 + const reqData = { + category, + page: 1, + limit: 10, + }; + let res = await GirlService.I.reqGetGirlList(reqData); + if (res && res.code === proto.cs.EnmRetCode.SUCCESS) { + // 保存数据 + const girlData = DataManager.I.getDataById(DataId.Girl); + girlData.setGirlBriefs(category.toString(), res.data); + // 根据数据,刷新界面 + const allId = girlData.getGirlIds(category.toString()); + for (let id of allId) { + let newNode = instantiate(this.itemInst.node); + let item = newNode.getComponent(GirlListItem); + item.refreshData(category, id, this.node); + newNode.active = true; + this.cache.push(item); + this.content.addChild(newNode); + } } } diff --git a/assets/Scripts/chat18x/ui/panels/ThemePanel.ts b/assets/Scripts/chat18x/ui/panels/ThemePanel.ts index 8ca261b9..3573c4e5 100644 --- a/assets/Scripts/chat18x/ui/panels/ThemePanel.ts +++ b/assets/Scripts/chat18x/ui/panels/ThemePanel.ts @@ -74,7 +74,7 @@ export class ThemePanel extends li_BaseView { // 保存数据 const themeData = DataManager.I.getDataById(DataId.Theme); themeData.themes = res.data; - // 根据数据,构建界面显示 + // 根据数据,刷新界面 const themeIds = themeData.themeIds; for (let id of themeIds) { let newNode = instantiate(this.itemInst.node); @@ -94,7 +94,7 @@ export class ThemePanel extends li_BaseView { if (res2 && res2.code === proto.cs.EnmRetCode.SUCCESS) { const girlData = DataManager.I.getDataById(DataId.Girl); girlData.setDailyRecommend(res2.data); - // 根据数据,构建界面显示 + // 根据数据,刷新界面 this.recId = girlData.getRecommendGrilId(0); this.rectNameKey = girlData.getRecommendGrilName(0); let avatarPath = girlData.getRecommendGrilAvatar(0); diff --git a/assets/Scripts/chat18x/uiitems/GirlListItem.ts b/assets/Scripts/chat18x/uiitems/GirlListItem.ts index 04941950..24b024b9 100644 --- a/assets/Scripts/chat18x/uiitems/GirlListItem.ts +++ b/assets/Scripts/chat18x/uiitems/GirlListItem.ts @@ -7,6 +7,8 @@ import { NavigationManager } from "../manager/NavigationManager"; import { Girl, PriceType } from "../../schema/schema"; import LanguageUtils from "../../Main/Common/LanguageUtils"; import { InnerMsgCode } from "../../Main/Config/InnerMsgCode"; +import { DataManager, DataId } from "../data/DataManager"; +import { GirlData } from "../data/GirlData"; const { ccclass, property } = _decorator; @@ -33,6 +35,7 @@ export class GirlListItem extends Component { nameKey: string; tagKey: string; + category: number; private onLanguageChangeCallback = () => { if (!this.girlName || !this.tags) return; @@ -64,26 +67,31 @@ export class GirlListItem extends Component { } baseNode: Node; - refreshData(data: Girl, baseNode: Node) { + refreshData(category: number, girlId: number, baseNode: Node) { + this.category = category; this.baseNode = baseNode; - this.id = data.id; - this.nameKey = data.nameKey; - this.girlName.string = LanguageUtils.getText(data.nameKey); - this.tagKey = data.tagKey; + this.id = girlId; + // 数据 + const girlData = DataManager.I.getDataById(DataId.Girl); + this.nameKey = girlData.getGrilName(this.category.toString(), this.id); + this.girlName.string = LanguageUtils.getText(this.nameKey); + this.tagKey = girlData.getGrilTagKey(this.category.toString(), this.id); let desc = ""; - const tags = LanguageUtils.getText(data.tagKey).split("|"); + const tags = LanguageUtils.getText(this.tagKey).split("|"); for (let i = 0; i < tags.length; i++) { if (i != 0) desc += "|"; desc += tags[i]; } this.tags.string = desc; - this.price.node.active = data.priceType == PriceType.pay; - this.freeNode.active = data.priceType == PriceType.free; - this.tryNode.active = data.priceType == PriceType.first_time_free; - + let priceType = girlData.getGrilPriceType(this.category.toString(), this.id); + this.price.node.active = priceType == PriceType.pay; + this.freeNode.active = priceType == PriceType.free; + this.tryNode.active = priceType == PriceType.first_time_free; + // TODO,先用 AvatarPath 代替着 listAvatarPath + let listAvatarPath = girlData.getGrilAvatar(this.category.toString(), this.id); ResManager.I.changeBundleSpriteFrame( this.avatar, - data.listAvatarPath, + listAvatarPath, "Chat18x", () => { let sizeTran = this.avatar.node.parent.getComponent(UITransform);