模拟数据:技师的简要数据
This commit is contained in:
@@ -61,10 +61,46 @@ export class MockGirlService implements IGirlService {
|
||||
|
||||
// 获取技师列表
|
||||
async reqGetGirlList(req: proto.cs.ICSGetGirlListReq): Promise<ApiResponse<proto.cs.ICSGetGirlListRes>> {
|
||||
// 延时
|
||||
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<GirlConfig>(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 });
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GirlData>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ export class ThemePanel extends li_BaseView {
|
||||
// 保存数据
|
||||
const themeData = DataManager.I.getDataById<ThemeData>(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<GirlData>(DataId.Girl);
|
||||
girlData.setDailyRecommend(res2.data);
|
||||
// 根据数据,构建界面显示
|
||||
// 根据数据,刷新界面
|
||||
this.recId = girlData.getRecommendGrilId(0);
|
||||
this.rectNameKey = girlData.getRecommendGrilName(0);
|
||||
let avatarPath = girlData.getRecommendGrilAvatar(0);
|
||||
|
||||
@@ -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<GirlData>(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);
|
||||
|
||||
Reference in New Issue
Block a user