模拟数据:技师的详细数据

This commit is contained in:
chen wei bo
2025-09-03 17:35:41 +08:00
parent 7ad2261867
commit cd05c4d3a8
5 changed files with 271 additions and 142 deletions
+147 -29
View File
@@ -88,14 +88,16 @@ export class GirlData extends BaseData {
private parseOneGirlBrief(data: proto.cs.IGirlBrief): proto.cs.IGirlBrief | null {
if (!data) return null;
const oneData: proto.cs.IGirlBrief = {
id: data.id, // id
name: data.name, // 名字
age: data.age, // 年龄
tagKey: data.tagKey, // 标签
priceType: data.priceType, // 付费类型
price: data.price, // 价格
avatar: data.avatar, // 头像
star: data.star, // 星级
id: data.id, // id
name: data.name, // 名字
age: data.age, // 年龄
tagKey: data.tagKey, // 标签
priceType: data.priceType, // 付费类型
price: data.price, // 价格
avatar: data.avatar, // 头像
star: data.star, // 星级
category: data.category, // 主题枚举
listAvatarPath: data.listAvatarPath, // list头像路径
};
return oneData;
}
@@ -174,25 +176,40 @@ export class GirlData extends BaseData {
return oneData.star;
}
/** 获取主题枚举 */
public getGrilCategory(categoryId: string, girlId: number): number {
let oneData = this.getGrilBrief(categoryId, girlId);
if (!oneData) return 0;
return oneData.category;
}
/** 获取list头像路径 */
public getGrilListAvatar(categoryId: string, girlId: number): string {
let oneData = this.getGrilBrief(categoryId, girlId);
if (!oneData) return "";
return oneData.listAvatarPath;
}
/** --------------------------------------------------------- 技师的详细数据 --------------------------------------------------------- */
// 解析技师图片数据,一个
private parseOneGirlPhoto(data: proto.cs.IGirlPhoto): proto.cs.IGirlPhoto | null {
private parseOneGirlPhoto(data: proto.cs.IPurchaseCommercialImage): proto.cs.IPurchaseCommercialImage | null {
if (!data) return null;
const oneData: proto.cs.IGirlPhoto = {
pic: data.pic, // 图片路径
const oneData: proto.cs.IPurchaseCommercialImage = {
imageType: data.imageType, // 图片类型
imagePrice: data.imagePrice, // 图片价格
path: data.path, // 图片资源路径
isRelease: data.isRelease, // 是否解锁
price: data.price, // 价格
};
return oneData;
}
// 解析技师图片数据,多个
private parseAllGirlPhoto(data: proto.cs.IGirlPhoto[]): proto.cs.IGirlPhoto[] | null {
private parseAllGirlPhoto(data: proto.cs.IPurchaseCommercialImage[]): proto.cs.IPurchaseCommercialImage[] | null {
if (!data) return null;
let allData = [];
for (const value of data) {
const oneData: proto.cs.IGirlPhoto = this.parseOneGirlPhoto(value);
const oneData: proto.cs.IPurchaseCommercialImage = this.parseOneGirlPhoto(value);
if (oneData) {
allData.push(oneData);
}
@@ -200,17 +217,44 @@ export class GirlData extends BaseData {
return allData;
}
// 解析技师视频数据,一个
private parseOneGirlVideo(data: proto.cs.IPurchaseCommercialVideo): proto.cs.IPurchaseCommercialVideo | null {
if (!data) return null;
const oneData: proto.cs.IPurchaseCommercialVideo = {
path: data.path, // 视频资源路径
emotion: data.emotion, // 关联情绪
videoPrice: data.videoPrice, // 价格
isRelease: data.isRelease, // 是否解锁
};
return oneData;
}
// 解析技师视频数据,多个
private parseAllGirlVideo(data: proto.cs.IPurchaseCommercialVideo[]): proto.cs.IPurchaseCommercialVideo[] | null {
if (!data) return null;
let allData = [];
for (const value of data) {
const oneData: proto.cs.IPurchaseCommercialVideo = this.parseOneGirlVideo(value);
if (oneData) {
allData.push(oneData);
}
}
return allData;
}
// 解析技师详细数据,一个
private parseOneGirlDetail(data: proto.cs.IGirlDetail): proto.cs.IGirlDetail | null {
if (!data) return null;
const photoData = this.parseAllGirlPhoto(data.photos);
const photoData = this.parseAllGirlPhoto(data.images);
const videoData = this.parseAllGirlVideo(data.videos);
const briefData = this.parseOneGirlBrief(data.brief);
const oneData: proto.cs.IGirlDetail = {
brief: briefData, // 技师简要数据
desc: data.desc, // 技师描述
photos: photoData, // 技师图片列表
desc: data.desc, // 技师描述
isRelease: data.isRelease, // 技师是否解锁
chatCount: data.chatCount, // 剩余聊天次数
images: photoData, // 技师图片列表
videos: videoData, // 技师视频列表
};
return oneData;
}
@@ -271,21 +315,49 @@ export class GirlData extends BaseData {
return oneData.chatCount;
}
/** 获取技师图片数据,通过 index */
public getGrilPhotoData(categoryId: string, girlId: number, index: number): proto.cs.IGirlPhoto | null {
/** 获取所有技师图片数据 */
private getAllGrilPhotoData(categoryId: string, girlId: number): proto.cs.IPurchaseCommercialImage[] | null {
let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData || !oneData.photos) return null;
// 下标越界保护
if (index < 0 || index >= oneData.photos.length) return null;
return oneData.photos[index] ?? null;
if (!oneData || !oneData.images) return null;
return oneData.images;
}
/** 获取所有技师图片数据的数量 */
public getAllGrilPhotoDataCount(categoryId: string, girlId: number): number {
let allData = this.getAllGrilPhotoData(categoryId, girlId);
if (!allData) return 0;
return allData.length;
}
/** 获取技师图片数据,通过 index */
private getGrilPhotoData(categoryId: string, girlId: number, index: number): proto.cs.IPurchaseCommercialImage | null {
let allData = this.getAllGrilPhotoData(categoryId, girlId);
if (!allData) return null;
// 下标越界保护
if (index < 0 || index >= allData.length) return null;
return allData[index] ?? null;
}
/** 获取技师图片的类型 */
public getGrilPhotoType(categoryId: string, girlId: number, index: number): number {
let oneData = this.getGrilPhotoData(categoryId, girlId, index);
if (!oneData) return 0;
return oneData.imageType;
}
/** 获取技师图片的价格 */
public getGrilPhotoPrice(categoryId: string, girlId: number, index: number): number {
let oneData = this.getGrilPhotoData(categoryId, girlId, index);
if (!oneData) return 0;
return oneData.imagePrice;
}
/** 获取技师图片的路径 */
public getGrilPhotoPic(categoryId: string, girlId: number, index: number): string {
let oneData = this.getGrilPhotoData(categoryId, girlId, index);
if (!oneData) return "";
return oneData.pic;
return oneData.path;
}
/** 获取技师图片是否解锁 */
@@ -295,11 +367,57 @@ export class GirlData extends BaseData {
return oneData.isRelease;
}
/** 获取技师图片的价格 */
public getGrilPhotoPrice(categoryId: string, girlId: number, index: number): number {
let oneData = this.getGrilPhotoData(categoryId, girlId, index);
/** 获取所有技师视频数据 */
private getAllGrilVideoData(categoryId: string, girlId: number): proto.cs.IPurchaseCommercialVideo[] | null {
let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData || !oneData.videos) return null;
return oneData.videos ?? null;
}
/** 获取所有技师视频数据的数量 */
public getAllGrilVideoDataCount(categoryId: string, girlId: number): number {
let allData = this.getAllGrilVideoData(categoryId, girlId);
if (!allData) return 0;
return allData.length;
}
/** 获取技师视频数据,通过 index */
private getGrilVideoData(categoryId: string, girlId: number, index: number): proto.cs.IPurchaseCommercialVideo | null {
let allData = this.getAllGrilVideoData(categoryId, girlId);
if (!allData) return null;
// 下标越界保护
if (index < 0 || index >= allData.length) return null;
return allData[index] ?? null;
}
/** 获取技师视频的路径 */
public getGrilVideoPath(categoryId: string, girlId: number, index: number): string {
let oneData = this.getGrilVideoData(categoryId, girlId, index);
if (!oneData) return "";
return oneData.path;
}
/** 获取技师视频的关联情绪 */
public getGrilVideoEmotion(categoryId: string, girlId: number, index: number): number {
let oneData = this.getGrilVideoData(categoryId, girlId, index);
if (!oneData) return 0;
return oneData.price;
return oneData.emotion;
}
/** 获取技师视频的价格 */
public getGrilVideoPrice(categoryId: string, girlId: number, index: number): number {
let oneData = this.getGrilVideoData(categoryId, girlId, index);
if (!oneData) return 0;
return oneData.videoPrice;
}
/** 获取技师视频是否解锁 */
public getGrilVideoIsRelease(categoryId: string, girlId: number, index: number): boolean {
let oneData = this.getGrilVideoData(categoryId, girlId, index);
if (!oneData) return false;
return oneData.isRelease;
}
/** --------------------------------------------------------- 每日推荐 --------------------------------------------------------- */
@@ -15,7 +15,7 @@ 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): proto.cs.IGirlBrief {
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 {
return {
id,
name,
@@ -25,22 +25,35 @@ export class MockGirlService implements IGirlService {
price,
avatar,
star,
category,
listAvatarPath,
};
}
private genPhoto(pic: string, isRelease: boolean, price: number): proto.cs.IGirlPhoto {
private genPhoto(imageType: number, imagePrice: number, path: string, isRelease: boolean, ): proto.cs.IPurchaseCommercialImage {
return {
pic,
imageType,
imagePrice,
path,
isRelease,
price,
};
}
private genDetail(brief: proto.cs.IGirlBrief, desc: string, photos: proto.cs.IGirlPhoto[], isRelease: boolean, chatCount: number): proto.cs.IGirlDetail {
private genVideo(path: string, emotion: number, videoPrice: number, isRelease: boolean): proto.cs.IPurchaseCommercialVideo {
return {
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 {
return {
brief,
desc,
photos,
images,
videos,
isRelease,
chatCount,
};
@@ -61,7 +74,9 @@ export class MockGirlService implements IGirlService {
let price = 9.9;
let avatar = configData.getAvatarPathById(recId);
let star = 3;
let oneData = this.genBrief(recId, name, age, tagKey, priceType, price, avatar, star);
let category = configData.getCategoryById(recId);
let listAvatarPath = configData.getListAvatarPathPathById(recId);
let oneData = this.genBrief(recId, name, age, tagKey, priceType, price, avatar, star, category, listAvatarPath);
// 返回数据
const girls = [oneData];
return this.ok({ girls });
@@ -106,7 +121,10 @@ export class MockGirlService implements IGirlService {
// 星级兜底:1~5
const star = (id % 5) + 1;
return this.genBrief(id, name, age, tagKey, priceType, price, avatar, star);
const category = configData.getCategoryById(id);
const listAvatarPath = configData.getListAvatarPathPathById(id);
return this.genBrief(id, name, age, tagKey, priceType, price, avatar, star, category, listAvatarPath);
});
// 返回数据
return this.ok({ girls });
@@ -121,7 +139,7 @@ export class MockGirlService implements IGirlService {
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);
@@ -129,24 +147,37 @@ export class MockGirlService implements IGirlService {
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 category = girlConfig.getCategoryById(girlId);
let listAvatarPath = girlConfig.getListAvatarPathPathById(girlId);
let briefData = this.genBrief(girlId, name, age, tagKey, priceType, price, avatar, star, category, listAvatarPath);
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 imageType = girlDetailConfig.getImageTypeById(girlId, 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 isRelease = Math.random() < 0.4;
let imagePrice = girlDetailConfig.getImagePriceById(girlId, i);
let oneData = this.genPhoto(imageType, imagePrice, imagePath, isRelease);
photoData.push(oneData);
}
let detail = this.genDetail(briefData, desc, photoData, isRelease, chatCount);
// 视频
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);
videoData.push(oneData);
}
// 详细数据
let detail = this.genDetail(briefData, desc, photoData, videoData, isRelease, chatCount);
// 返回数据
return this.ok({ detail });
}
@@ -135,7 +135,7 @@ export class GirlDetailPanel extends li_BaseView {
}
nameKey: string;
tagKey: string;
category;
category: number;
async refresh(index: number) {
// TODO,暂时这样获取,修改后从GirlData获取
const girlConfig = ConfigManager.tables.TbGirls.get(this.id);
@@ -144,109 +144,71 @@ export class GirlDetailPanel extends li_BaseView {
const reqData = {
id: this.id,
};
// let res = await GirlService.I.reqGetGirlDetail(reqData);
// console.log("看看响应数据:", res);
// if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
// // 保存数据
// const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// girlData.setGirlDetails(this.category.toString(), res.data);
// // 根据数据,刷新界面
// this.nameKey = girlData.getGrilName(this.category, this.id);
// this.girlName.string = LanguageUtils.getText(this.nameKey);
// this.desc.string = girlData.getGrilDesc(this.category, this.id);
let res = await GirlService.I.reqGetGirlDetail(reqData);
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
// 保存数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
girlData.setGirlDetails(this.category.toString(), res.data);
// 根据数据,刷新界面
this.nameKey = girlData.getGrilName(this.category.toString(), this.id);
this.girlName.string = LanguageUtils.getText(this.nameKey);
this.desc.string = girlData.getGrilDesc(this.category.toString(), this.id);
// let desc = "";
// this.tagKey = girlData.getGrilTagKey(this.category, this.id);
// 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;
// for (let i = 0; i < 5; i++) {
// this.starParent.children[i].active = i < 5;
// }
// let age = girlData.getGrilAge(this.category, this.id);
// this.descAge.string =
// LanguageUtils.getText("girldetailpanel.age") + age.toString();
let desc = "";
this.tagKey = girlData.getGrilTagKey(this.category.toString(), this.id);
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;
for (let i = 0; i < 5; i++) {
this.starParent.children[i].active = i < 5;
}
let age = girlData.getGrilAge(this.category.toString(), this.id);
this.descAge.string =
LanguageUtils.getText("girldetailpanel.age") + age.toString();
// // TODO
// const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
const firstPath = girlData.getGrilVideoPath(this.category.toString(), this.id, 0);
ResManager.I.changeBundleVideo(
this.avatarVideo,
firstPath,
"Chat18x"
);
// ResManager.I.changeBundleVideo(
// this.avatarVideo,
// dataDetail.commercialVideos[0].path,
// "Chat18x"
// );
// // 也立即尝试调整(以防已经加载完成)
// this.adjustVideoScale();
// this.vids = dataDetail.commercialVideos.slice(0);
// this.refreshImgs(dataDetail.commercialImages);
// }
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
console.log(dataDetail);
const data = ConfigManager.tables.TbGirls.get(this.id);
this.nameKey = data.nameKey;
this.girlName.string = LanguageUtils.getText(data.nameKey);
this.desc.string = dataDetail.detailDesc;
let desc = "";
this.tagKey = data.tagKey;
const tags = LanguageUtils.getText(data.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "|";
desc += tags[i];
}
this.tags.string = desc;
for (let i = 0; i < 5; i++) {
this.starParent.children[i].active = i < 5;
}
this.descAge.string =
LanguageUtils.getText("girldetailpanel.age") + data.age.toString();
this.desc.string = dataDetail.detailDesc;
ResManager.I.changeBundleVideo(
this.avatarVideo,
dataDetail.commercialVideos[0].path,
"Chat18x"
);
// 也立即尝试调整(以防已经加载完成)
this.adjustVideoScale();
this.vids = dataDetail.commercialVideos.slice(0);
this.refreshImgs(dataDetail.commercialImages);
let allPhotoDataCount = girlData.getAllGrilPhotoDataCount(this.category.toString(), this.id);
// 也立即尝试调整(以防已经加载完成)
this.adjustVideoScale();
this.refreshImgs(1, this.category, this.id, allPhotoDataCount);
}
}
vids: purchase.CommercialVideo[];
bindImgToggle() {
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
const images = dataDetail.commercialImages;
this.refreshImgs(images);
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
let allPhotoDataCount = girlData.getAllGrilPhotoDataCount(this.category.toString(), this.id);
this.refreshImgs(1, this.category, this.id, allPhotoDataCount);
}
bindVideoToggle() {
this.refreshImgs(this.vids);
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
let allVideoDataCount = girlData.getAllGrilVideoDataCount(this.category.toString(), this.id);
this.refreshImgs(2, this.category, this.id, allVideoDataCount);
}
refreshImgs(
resouces: purchase.CommercialImage[] | purchase.CommercialVideo[]
type: number,
category: number,
id: number,
count: number
) {
for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) {
this.imgsLayout.children[i].destroy();
}
for (let i = 1; i < resouces.length; i++) {
const resource = resouces[i];
for (let i = 0; i < count; i++) {
let newNode = instantiate(this.imgItemInst.node);
let item = newNode.getComponent(DetailImageItem);
item.refresh(resource, this);
item.refresh(this, type, category, id, i);
newNode.active = true;
this.imgsLayout.addChild(newNode);
}
@@ -5,6 +5,9 @@ import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
import { GirlDetailPanel } from "../ui/panels/GirlDetailPanel";
import { purchase } from "../../schema/schema";
import proto from 'db://assets/Scripts/proto/proto.pb.js';
import { DataManager, DataId } from "../data/DataManager";
import { GirlData } from "../data/GirlData";
const { ccclass, property } = _decorator;
@@ -22,6 +25,10 @@ export class DetailImageItem extends Component {
url: string;
isImage: boolean;
uitransform: UITransform;
category: number;
id: number;
index: number;
type : number;
onLoad() {
GButton.BandClick(this.node, this.onClickThis, this);
@@ -82,21 +89,33 @@ export class DetailImageItem extends Component {
}
}
refresh(
resource: purchase.CommercialImage | purchase.CommercialVideo,
base: GirlDetailPanel
base: GirlDetailPanel,
type: number,
category: number,
id: number,
index: number
) {
this.base = base;
this.type = type;
this.category = category;
this.id = id;
this.index = index;
this.lock.active = false;
this.question.active = true; // 显示问号,表示加载中
this.url = resource.path;
let imgPath = this.url;
if (resource instanceof purchase.CommercialImage) {
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
let imgPath = "";
if (type === 1) {
// 图片
this.url = girlData.getGrilPhotoPic(this.category.toString(), this.id, this.index);
imgPath = this.url;
this.isImage = true;
} else {
} else if (type === 2) {
// 视频
this.isImage = false;
if (resource.videoPrice > 0) {
this.url = girlData.getGrilVideoPath(this.category.toString(), this.id, this.index);
let videoPrice = girlData.getGrilVideoPrice(this.category.toString(), this.id, this.index);
if (videoPrice > 0) {
imgPath = this.url + "_thumbnail_blur";
} else {
imgPath = this.url + "_thumbnail";
@@ -87,8 +87,7 @@ export class GirlListItem extends Component {
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);
let listAvatarPath = girlData.getGrilListAvatar(this.category.toString(), this.id);
ResManager.I.changeBundleSpriteFrame(
this.avatar,
listAvatarPath,