修改:协议和配置表
This commit is contained in:
@@ -4,10 +4,8 @@ import type { IAuthService } from "./IAuthService";
|
||||
|
||||
export class MockAuthService implements IAuthService {
|
||||
private delay(ms = 180) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||
|
||||
// 项目里 ApiResponse 结构若固定(code/message 等),把 ok()/err() 调整为你的真实结构即可
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ ok: true, data } as unknown) as ApiResponse<T>;
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
// private err<T = unknown>(message = "mock login error"): ApiResponse<T> {
|
||||
// return ({ ok: false, error: { message } } as unknown) as ApiResponse<T>;
|
||||
@@ -15,18 +13,29 @@ export class MockAuthService implements IAuthService {
|
||||
|
||||
// 登录
|
||||
async login(req: proto.cs.ICSLoginReq): Promise<ApiResponse<proto.cs.ICSLoginRes>> {
|
||||
// 延时
|
||||
await this.delay(150);
|
||||
|
||||
const name = req?.platType === "guest" ? `guest_${(req?.userId ?? "uid").toString().slice(-6)}` : "tester";
|
||||
// 注意:protobufjs 会把 int64 表达为 number/Long。这里用「秒」级时间戳更常见
|
||||
const isGuest = req?.platType === "guest";
|
||||
const userId = req?.userId ?? "uid";
|
||||
const name = isGuest ? `guest_${userId.toString().slice(-6)}` : "tester";
|
||||
|
||||
// 过期时间(秒级时间戳,7天后过期)
|
||||
const expireSeconds = Math.floor(Date.now() / 1000) + 7 * 24 * 3600;
|
||||
|
||||
// 你的生成器通常会把 refresh_token 转成 refreshToken(camelCase)
|
||||
// 模拟用户ID
|
||||
const accId = Math.floor(Math.random() * 1000000);
|
||||
|
||||
// 模拟 CDN 前缀
|
||||
const cdn = "https://cdn.mockserver.com/";
|
||||
|
||||
const res: proto.cs.ICSLoginRes = {
|
||||
name,
|
||||
token: `mock_token_${Date.now()}`,
|
||||
refreshToken: `mock_refresh_${Date.now()}`,
|
||||
expire: expireSeconds,
|
||||
accId,
|
||||
cdn,
|
||||
};
|
||||
|
||||
return this.ok(res);
|
||||
|
||||
@@ -15,50 +15,66 @@ export class MockGirlService implements IGirlService {
|
||||
return ({ code: 100, error: { message } } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
|
||||
private genBrief(id: number, name: string, age: number, tagKey: string, priceType: number, price: number, avatar: string, star: number, category: number, listAvatarPath: string): proto.cs.IGirlBrief {
|
||||
private genBrief(id: number, nameKey: string, age: string, category: number, tagKey: string, priceType: number, price: number, vipUnlock: number, avatarPath: string, listAvatarPath: string): proto.cs.IGirls {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
nameKey,
|
||||
age,
|
||||
category,
|
||||
tagKey,
|
||||
priceType,
|
||||
price,
|
||||
avatar,
|
||||
star,
|
||||
category,
|
||||
vipUnlock,
|
||||
avatarPath,
|
||||
listAvatarPath,
|
||||
};
|
||||
}
|
||||
|
||||
private genPhoto(imageType: number, imagePrice: number, path: string, isRelease: boolean, ): proto.cs.IPurchaseCommercialImage {
|
||||
private genPhoto(id: number, imageType: number, unlockCounts: number, imagePrice: number, path: string): proto.cs.IPurchaseCommercialImage {
|
||||
return {
|
||||
id,
|
||||
imageType,
|
||||
unlockCounts,
|
||||
imagePrice,
|
||||
path,
|
||||
isRelease,
|
||||
};
|
||||
}
|
||||
|
||||
private genVideo(path: string, emotion: number, videoPrice: number, isRelease: boolean): proto.cs.IPurchaseCommercialVideo {
|
||||
return {
|
||||
private genVideo(id: number, path: string, emotion: number, videoPrice: number): proto.cs.IPurchaseCommercialVideo {
|
||||
return {
|
||||
id,
|
||||
path,
|
||||
emotion,
|
||||
videoPrice,
|
||||
isRelease,
|
||||
};
|
||||
}
|
||||
|
||||
private genDetail(brief: proto.cs.IGirlBrief, desc: string, images: proto.cs.IPurchaseCommercialImage[], videos: proto.cs.IPurchaseCommercialVideo[], isRelease: boolean, chatCount: number): proto.cs.IGirlDetail {
|
||||
private genDetail(id: number, detailDesc: string, commercialImages: proto.cs.IPurchaseCommercialImage[], commercialVideos: proto.cs.IPurchaseCommercialVideo[]): proto.cs.IGirlsDetail {
|
||||
return {
|
||||
brief,
|
||||
desc,
|
||||
images,
|
||||
videos,
|
||||
isRelease,
|
||||
chatCount,
|
||||
id,
|
||||
detailDesc,
|
||||
commercialImages,
|
||||
commercialVideos,
|
||||
};
|
||||
}
|
||||
|
||||
private genGirlData(
|
||||
id: number, girl: proto.cs.IGirls, isRelease: boolean, star: number,
|
||||
detail: proto.cs.IGirlsDetail, images: proto.cs.IResourceUnlock[], videos: proto.cs.IResourceUnlock[],
|
||||
chatTotalCount: number, chatRemainCount: number): proto.cs.IGirlData {
|
||||
return {
|
||||
id,
|
||||
girl,
|
||||
isRelease,
|
||||
star,
|
||||
detail,
|
||||
images,
|
||||
videos,
|
||||
chatTotalCount,
|
||||
chatRemainCount,
|
||||
};
|
||||
}
|
||||
|
||||
// 每日推荐
|
||||
async reqDailyRecommend(_req: proto.cs.ICSDailyRecommendReq): Promise<ApiResponse<proto.cs.ICSDailyRecommendRes>> {
|
||||
// 延时
|
||||
@@ -67,19 +83,19 @@ export class MockGirlService implements IGirlService {
|
||||
const configData = ConfigManager.I.getDataById<GirlConfig>(ConfigId.Girl);
|
||||
const allId = configData.getAllId();
|
||||
const recId = allId[0];
|
||||
let name = configData.getNameById(recId);
|
||||
let age = Number(configData.getAgeById(recId));
|
||||
let nameKey = configData.getNameById(recId);
|
||||
let age = configData.getAgeById(recId);
|
||||
let tagKey = configData.getTagKeyById(recId);
|
||||
let priceType = configData.getPriceTypeById(recId);
|
||||
let price = 9.9;
|
||||
let avatar = configData.getAvatarPathById(recId);
|
||||
let star = 3;
|
||||
let price = configData.getPriceById(recId);
|
||||
let vipUnlock = configData.getVipUnlockById(recId);
|
||||
let avatarPath = configData.getAvatarPathById(recId);
|
||||
let category = configData.getCategoryById(recId);
|
||||
let listAvatarPath = configData.getListAvatarPathPathById(recId);
|
||||
let oneData = this.genBrief(recId, name, age, tagKey, priceType, price, avatar, star, category, listAvatarPath);
|
||||
let oneData = this.genBrief(recId, nameKey, age, category, tagKey, priceType, price, vipUnlock, avatarPath, listAvatarPath);
|
||||
// 返回数据
|
||||
const girls = [oneData];
|
||||
return this.ok({ girls });
|
||||
const res: proto.cs.ICSDailyRecommendRes = {girl: oneData};
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 获取技师列表
|
||||
@@ -105,29 +121,35 @@ export class MockGirlService implements IGirlService {
|
||||
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 girls: proto.cs.IGirlData[] = pageIds.map((id: number) => {
|
||||
// 简要数据
|
||||
const nameKey = configData.getNameById(id);
|
||||
const age = 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;
|
||||
|
||||
const priceType = configData.getPriceTypeById(id);
|
||||
const price = configData.getPriceById(id);
|
||||
const vipUnlock = configData.getVipUnlockById(id);
|
||||
const avatarPath = configData.getAvatarPathById(id);
|
||||
const category = configData.getCategoryById(id);
|
||||
const listAvatarPath = configData.getListAvatarPathPathById(id);
|
||||
|
||||
return this.genBrief(id, name, age, tagKey, priceType, price, avatar, star, category, listAvatarPath);
|
||||
const listAvatarPath = configData.getListAvatarPathPathById(id);
|
||||
const briefData = this.genBrief(id, nameKey, age, category, tagKey, priceType, price, vipUnlock, avatarPath, listAvatarPath);
|
||||
|
||||
const isRelease = true;
|
||||
const star = 3;
|
||||
// 详细数据
|
||||
const detail = null;
|
||||
const images = [];
|
||||
const videos = [];
|
||||
const chatTotalCount = 0;
|
||||
const chatRemainCount = 0;
|
||||
const girlData = this.genGirlData(id, briefData, isRelease, star, detail, images, videos, chatTotalCount, chatRemainCount);
|
||||
|
||||
return girlData;
|
||||
});
|
||||
// 返回数据
|
||||
return this.ok({ girls });
|
||||
const res: proto.cs.ICSGetGirlListRes = {girls};
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 获取技师详细信息
|
||||
@@ -140,45 +162,76 @@ export class MockGirlService implements IGirlService {
|
||||
// id
|
||||
const girlId = req.id;
|
||||
// 简要数据
|
||||
let name = girlConfig.getNameById(girlId);
|
||||
let age = Number(girlConfig.getAgeById(girlId));
|
||||
let nameKey = girlConfig.getNameById(girlId);
|
||||
let age = 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 price = girlConfig.getPriceById(girlId);
|
||||
let vipUnlock = girlConfig.getVipUnlockById(girlId);
|
||||
let avatarPath = girlConfig.getAvatarPathById(girlId);
|
||||
let category = girlConfig.getCategoryById(girlId);
|
||||
let listAvatarPath = girlConfig.getListAvatarPathPathById(girlId);
|
||||
let briefData = this.genBrief(girlId, name, age, tagKey, priceType, price, avatar, star, category, listAvatarPath);
|
||||
let briefData = this.genBrief(girlId, nameKey, age, category, tagKey, priceType, price, vipUnlock, avatarPath, listAvatarPath);
|
||||
|
||||
let desc = girlDetailConfig.getDetailDescById(girlId);
|
||||
let isRelease = Math.random() < 0.4;
|
||||
let chatCount = 10;
|
||||
let detailDesc = girlDetailConfig.getDetailDescById(girlId);
|
||||
// 图片
|
||||
let photoData = [];
|
||||
let photoCount = girlDetailConfig.getCommercialImagesCount(girlId);
|
||||
for (let i = 0; i < photoCount; i++) {
|
||||
let imageType = girlDetailConfig.getImageTypeById(girlId, i);
|
||||
let imagePath = girlDetailConfig.getImagePathById(girlId, i);
|
||||
let isRelease = Math.random() < 0.4;
|
||||
let imagePrice = girlDetailConfig.getImagePriceById(girlId, i);
|
||||
let oneData = this.genPhoto(imageType, imagePrice, imagePath, isRelease);
|
||||
let photoIds = girlDetailConfig.getCommercialImagesIds(girlId);
|
||||
for (let id of photoIds) {
|
||||
let imageType = girlDetailConfig.getImageTypeById(girlId, id);
|
||||
let unlockCounts = girlDetailConfig.getImageUnlockCountsById(girlId, id);
|
||||
let imagePrice = girlDetailConfig.getImagePriceById(girlId, id);
|
||||
let imagePath = girlDetailConfig.getImagePathById(girlId, id);
|
||||
let oneData = this.genPhoto(id, imageType, unlockCounts, imagePrice, imagePath);
|
||||
photoData.push(oneData);
|
||||
}
|
||||
// 视频
|
||||
let videoData = [];
|
||||
let videoCount = girlDetailConfig.getCommercialVideosCount(girlId);
|
||||
for (let i = 0; i < videoCount; i++) {
|
||||
let videoPath = girlDetailConfig.getVideoPathById(girlId, i);
|
||||
let videoEmotion = girlDetailConfig.getVideoEmotionById(girlId, i);
|
||||
let videoPrice = girlDetailConfig.getVideoPriceById(girlId, i);
|
||||
let isRelease = Math.random() < 0.4;
|
||||
let oneData = this.genVideo(videoPath, videoEmotion, videoPrice, isRelease);
|
||||
let videoIds = girlDetailConfig.getCommercialVideosIds(girlId);
|
||||
for (let id of videoIds) {
|
||||
let videoPath = girlDetailConfig.getVideoPathById(girlId, id);
|
||||
let videoEmotion = girlDetailConfig.getVideoEmotionById(girlId, id);
|
||||
let videoPrice = girlDetailConfig.getVideoPriceById(girlId, id);
|
||||
let oneData = this.genVideo(id, videoPath, videoEmotion, videoPrice);
|
||||
videoData.push(oneData);
|
||||
}
|
||||
// 详细数据
|
||||
let detail = this.genDetail(briefData, desc, photoData, videoData, isRelease, chatCount);
|
||||
let detail = this.genDetail(girlId, detailDesc, photoData, videoData);
|
||||
// 图片解锁数据
|
||||
let unlockImageData: proto.cs.IResourceUnlock[] = [];
|
||||
for (let id of photoIds) {
|
||||
// 偶数才解锁
|
||||
let isUnlock = (id % 2 === 0);
|
||||
if (isUnlock) {
|
||||
let oneData = {
|
||||
girlId: girlId,
|
||||
resId: id,
|
||||
};
|
||||
unlockImageData.push(oneData);
|
||||
}
|
||||
}
|
||||
// 视频解锁数据
|
||||
let unlockVideoData: proto.cs.IResourceUnlock[] = [];
|
||||
for (let id of videoIds) {
|
||||
// 偶数才解锁
|
||||
let isUnlock = (id % 2 === 0);
|
||||
if (isUnlock) {
|
||||
let oneData = {
|
||||
girlId: girlId,
|
||||
resId: id,
|
||||
};
|
||||
unlockVideoData.push(oneData);
|
||||
}
|
||||
}
|
||||
|
||||
const star = 3;
|
||||
const chatTotalCount = 10;
|
||||
const chatRemainCount = 10;
|
||||
|
||||
const girlData = this.genGirlData(girlId, briefData, isRelease, star, detail, unlockImageData, unlockVideoData, chatTotalCount, chatRemainCount);
|
||||
// 返回数据
|
||||
return this.ok({ detail });
|
||||
const res: proto.cs.ICSGetGirlDetailRes = {girl: girlData};
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,26 +3,26 @@ import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { IPlayerDataService } from "./IPlayerDataService";
|
||||
|
||||
export class MockPlayerDataService implements IPlayerDataService {
|
||||
private delay(ms = 160) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||
private delay(ms = 160) {
|
||||
return new Promise<void>(r => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
// 按你项目的 ApiResponse 真实结构调整这里
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ ok: true, data } as unknown) as ApiResponse<T>;
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
// 如需模拟失败
|
||||
// private err<T = unknown>(message = "mock myInfo error"): ApiResponse<T> {
|
||||
// return ({ ok: false, error: { message } } as unknown) as ApiResponse<T>;
|
||||
// }
|
||||
|
||||
// 获取个人信息
|
||||
async reqMyInfo(_req: proto.cs.ICSMyInfoReq): Promise<ApiResponse<proto.cs.ICSMyInfoRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
|
||||
// 由于我们并不知道 ICSMyInfoRes 的具体字段,这里提供一个“最安全”的空对象返回;
|
||||
// 如果你有明确字段(例如 name/diamond/vipExpire 等),可在此构造并 as-cast:
|
||||
// const res = { name: "Player-001", diamond: 123, vipExpire: Math.floor(Date.now()/1000) } as unknown as proto.cs.ICSMyInfoRes;
|
||||
const nowSeconds = Math.floor(Date.now() / 1000);
|
||||
|
||||
const res = ({} as unknown) as proto.cs.ICSMyInfoRes;
|
||||
const res: proto.cs.ICSMyInfoRes = {
|
||||
balance: Math.floor(Math.random() * 100000), // 随机余额
|
||||
vipExpire: nowSeconds + 30 * 24 * 3600, // vip 30天后过期
|
||||
};
|
||||
// 返回数据
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class MockThemeService implements IThemeService {
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
|
||||
private makeTheme(id: number, key: string, name: string, category: number, isRelease: boolean, path: string): proto.cs.IHallTheme {
|
||||
private makeTheme(id: number, key: string, name: string, category: number, isRelease: boolean, path: string): proto.cs.IThemes {
|
||||
return {
|
||||
id,
|
||||
key,
|
||||
@@ -28,7 +28,7 @@ export class MockThemeService implements IThemeService {
|
||||
|
||||
const configData = ConfigManager.I.getDataById<ThemeConfig>(ConfigId.Theme);
|
||||
const allId = configData.getAllId();
|
||||
let themes: proto.cs.IHallTheme[] = [];
|
||||
let themes: proto.cs.IThemes[] = [];
|
||||
for (let oneId of allId) {
|
||||
let key = configData.getLanKeyById(oneId);
|
||||
let name = configData.getNameById(oneId);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { HttpPlayerDataService } from "./HttpPlayerDataService";
|
||||
import { MockPlayerDataService } from "./MockPlayerDataService";
|
||||
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
const USE_MOCK = false;
|
||||
|
||||
export class PlayerDataService implements IPlayerDataService {
|
||||
private static _I: PlayerDataService | null = null;
|
||||
|
||||
Reference in New Issue
Block a user