模拟数据:技师的简要数据

This commit is contained in:
chen wei bo
2025-09-02 16:38:38 +08:00
parent cf32944f64
commit 29554bb0c8
4 changed files with 88 additions and 27 deletions
@@ -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 });
}