73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
/**
|
|
* 技师的推荐数据
|
|
*/
|
|
import { BaseData } from "./BaseData";
|
|
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
|
|
|
export class GirlRecommendData extends BaseData {
|
|
// 推荐列表,id
|
|
private idList: number[];
|
|
|
|
constructor() {
|
|
super();
|
|
this.idList = [];
|
|
}
|
|
|
|
public reset(): void {
|
|
this.idList = [];
|
|
}
|
|
|
|
public clear(): void {
|
|
this.idList = [];
|
|
}
|
|
|
|
public destroy(): void {
|
|
super.destroy();
|
|
this.idList = null;
|
|
}
|
|
|
|
/** 保存 推荐列表 */
|
|
public setRecommendList(data: proto.cs.IGirlData[]): void {
|
|
if (!data || data.length === 0) return;
|
|
|
|
// 清空现有 idList
|
|
this.idList = [];
|
|
|
|
// 使用 Set 去重并提取 id
|
|
const idSet = new Set<number>();
|
|
|
|
for (const item of data) {
|
|
if (item && item.id != null) {
|
|
idSet.add(item.id); // 添加到 Set 中去重
|
|
}
|
|
}
|
|
|
|
// 将去重后的 id 转换为数组并赋值给 idList
|
|
this.idList = Array.from(idSet);
|
|
logger.log("保存推荐列表:", this.idList);
|
|
}
|
|
|
|
/** 添加 推荐列表 */
|
|
public addRecommendList(data: proto.cs.IGirlData[]): void {
|
|
if (!data || data.length === 0) return;
|
|
|
|
// 使用 Set 来去重
|
|
const idSet = new Set(this.idList); // 创建一个基于当前 idList 的 Set
|
|
|
|
// 依次添加新的 id(保持顺序 + 去重)
|
|
for (const item of data) {
|
|
if (item && item.id != null && !idSet.has(item.id)) {
|
|
idSet.add(item.id); // 添加到 Set 中去重
|
|
this.idList.push(item.id); // 添加到 idList 中
|
|
}
|
|
}
|
|
logger.log("添加推荐列表:", this.idList);
|
|
}
|
|
|
|
/** 获取 推荐列表 id */
|
|
public getRecommendListIds(): number[] {
|
|
return this.idList;
|
|
}
|
|
}
|