给更多的广告展示机会

This commit is contained in:
xu_yanfeng 2025-01-18 22:21:12 +08:00
parent 43fb857060
commit 033fa1da1f

View File

@ -56,6 +56,15 @@ export class AdData {
* 广 * 广
*/ */
scrollDuration: number = 3; scrollDuration: number = 3;
/**
*
*/
randomIndex: boolean = false;
/**
* 广-1
*/
showCount: number = -1;
data: Array<AdItem> = []; data: Array<AdItem> = [];
parse(data: AdData) { parse(data: AdData) {
this.desc = data.desc; this.desc = data.desc;
@ -63,8 +72,17 @@ export class AdData {
this.valid = !!data.valid; this.valid = !!data.valid;
this.showDuration = data.showDuration || 10; this.showDuration = data.showDuration || 10;
this.scrollDuration = data.scrollDuration || 3; this.scrollDuration = data.scrollDuration || 3;
this.randomIndex = !!data.randomIndex;
this.showCount = data.showCount || -1;
if (data.data) { if (data.data) {
if (this.randomIndex) {
data.data.sort(() => Math.random() - 0.5);
}
data.data.forEach((el) => { data.data.forEach((el) => {
if (this.showCount !== -1 && this.data.length >= this.showCount) {
return;
}
const item = new AdItem().parse(el); const item = new AdItem().parse(el);
if (!item.duration) { if (!item.duration) {
console.warn(`add failed, ad.duration is ${item.duration}, ${JSON.stringify(item)}`); console.warn(`add failed, ad.duration is ${item.duration}, ${JSON.stringify(item)}`);