模拟数据:技师的详细数据
This commit is contained in:
@@ -48,6 +48,13 @@ export class GirlDetailConfig extends BaseConfig {
|
||||
return oneData.commercialImages;
|
||||
}
|
||||
|
||||
/** 根据 id 获取 commercialImages数量 */
|
||||
public getCommercialImagesCount(id: number): any | null {
|
||||
let oneData = this.getCommercialImagesById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.commercialImages.size;
|
||||
}
|
||||
|
||||
/** 根据 id 和 index 获取图片类型 */
|
||||
public getImageTypeById(id: number, index: number): number | null {
|
||||
let oneData = this.getCommercialImagesById(id);
|
||||
@@ -79,6 +86,13 @@ export class GirlDetailConfig extends BaseConfig {
|
||||
return oneData.commercialVideos;
|
||||
}
|
||||
|
||||
/** 根据 id 获取 commercialVideos数量 */
|
||||
public getCommercialVideosCount(id: number): any | null {
|
||||
let oneData = this.getCommercialVideosById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.commercialVideos.size;
|
||||
}
|
||||
|
||||
/** 根据 id 和 index 获取视频路径 */
|
||||
public getVideoPathById(id: number, index: number): string | null {
|
||||
let oneData = this.getCommercialVideosById(id);
|
||||
|
||||
@@ -3,11 +3,10 @@ import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { IGirlService } from "./IGirlService";
|
||||
import { ConfigManager, ConfigId } from "../../manager/ConfigManager";
|
||||
import { GirlConfig } from "../../config/GirlConfig";
|
||||
|
||||
import { GirlDetailConfig } from "../../config/GirlDetailConfig";
|
||||
export class MockGirlService implements IGirlService {
|
||||
private delay(ms = 180) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||
private randInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; }
|
||||
private pick<T>(arr: T[]) { return arr[this.randInt(0, arr.length - 1)]; }
|
||||
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
@@ -29,20 +28,29 @@ export class MockGirlService implements IGirlService {
|
||||
};
|
||||
}
|
||||
|
||||
private genPhoto(idx: number): proto.cs.IGirlPhoto {
|
||||
return { pic: `https://dummy.local/photo/${idx}.jpg`, isRelease: Math.random() < 0.5, price: 20 + (idx % 5) * 5 };
|
||||
private genPhoto(pic: string, isRelease: boolean, price: number): proto.cs.IGirlPhoto {
|
||||
return {
|
||||
pic,
|
||||
isRelease,
|
||||
price,
|
||||
};
|
||||
}
|
||||
|
||||
private genDetail(id: number): proto.cs.IGirlDetail {
|
||||
const photos = Array.from({ length: 4 }, (_, i) => this.genPhoto(id * 10 + i));
|
||||
return { brief: this.genBrief(id, "", 1, "", 2, 3, "", 4), desc: `Mock detail for ${id}`, photos, isRelease: Math.random() < 0.4, chatCount: this.randInt(0, 5) };
|
||||
private genDetail(brief: proto.cs.IGirlBrief, desc: string, photos: proto.cs.IGirlPhoto[], isRelease: boolean, chatCount: number): proto.cs.IGirlDetail {
|
||||
return {
|
||||
brief,
|
||||
desc,
|
||||
photos,
|
||||
isRelease,
|
||||
chatCount,
|
||||
};
|
||||
}
|
||||
|
||||
// 每日推荐
|
||||
async reqDailyRecommend(_req: proto.cs.ICSDailyRecommendReq): Promise<ApiResponse<proto.cs.ICSDailyRecommendRes>> {
|
||||
// 延时
|
||||
await this.delay(180);
|
||||
|
||||
// 配置数据
|
||||
const configData = ConfigManager.I.getDataById<GirlConfig>(ConfigId.Girl);
|
||||
const allId = configData.getAllId();
|
||||
const recId = allId[0];
|
||||
@@ -63,7 +71,7 @@ export class MockGirlService implements IGirlService {
|
||||
async reqGetGirlList(req: proto.cs.ICSGetGirlListReq): Promise<ApiResponse<proto.cs.ICSGetGirlListRes>> {
|
||||
// 延时
|
||||
await this.delay(200);
|
||||
|
||||
// 配置数据
|
||||
const configData = ConfigManager.I.getDataById<GirlConfig>(ConfigId.Girl);
|
||||
const allId = configData.getAllId();
|
||||
|
||||
@@ -100,14 +108,45 @@ export class MockGirlService implements IGirlService {
|
||||
|
||||
return this.genBrief(id, name, age, tagKey, priceType, price, avatar, star);
|
||||
});
|
||||
|
||||
// 返回数据
|
||||
return this.ok({ girls });
|
||||
}
|
||||
|
||||
// 获取技师详细信息
|
||||
async reqGetGirlDetail(req: proto.cs.ICSGetGirlDetailReq): Promise<ApiResponse<proto.cs.ICSGetGirlDetailRes>> {
|
||||
// 延时
|
||||
await this.delay(160);
|
||||
const id = req?.id ?? this.randInt(1, 9999);
|
||||
return this.ok({ detail: this.genDetail(id) });
|
||||
// 配置数据
|
||||
const girlConfig = ConfigManager.I.getDataById<GirlConfig>(ConfigId.Girl);
|
||||
const girlDetailConfig = ConfigManager.I.getDataById<GirlDetailConfig>(ConfigId.GirlDetail);
|
||||
// id
|
||||
const girlId = req.id;
|
||||
|
||||
let name = girlConfig.getNameById(girlId);
|
||||
let age = Number(girlConfig.getAgeById(girlId));
|
||||
let tagKey = girlConfig.getTagKeyById(girlId);
|
||||
let priceType = girlConfig.getPriceTypeById(girlId);
|
||||
let price = 9.9;
|
||||
let avatar = girlConfig.getAvatarPathById(girlId);
|
||||
let star = 3;
|
||||
let briefData = this.genBrief(girlId, name, age, tagKey, priceType, price, avatar, star);
|
||||
|
||||
let desc = girlDetailConfig.getDetailDescById(girlId);
|
||||
let isRelease = Math.random() < 0.4;
|
||||
let chatCount = 10;
|
||||
|
||||
let photoData = [];
|
||||
let photoCount = girlDetailConfig.getCommercialImagesCount(girlId);
|
||||
for (let i = 0; i < photoCount; i++) {
|
||||
let imagePath = girlDetailConfig.getImagePathById(girlId, i);
|
||||
let isImageRelease = Math.random() < 0.4;
|
||||
let imagePrice = 9.9;
|
||||
let onePhotoData = this.genPhoto(imagePath, isImageRelease, imagePrice);
|
||||
photoData.push(onePhotoData);
|
||||
}
|
||||
|
||||
let detail = this.genDetail(briefData, desc, photoData, isRelease, chatCount);
|
||||
|
||||
return this.ok({ detail });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user