Files
SEONexus/code/public/template/shikong/huiyuan/js/class/cctv.js
2025-04-21 17:49:17 +08:00

131 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import EncAndDec from '../public/enc.js'
import {Equipment,clickEvent} from '../public/commonFun.js';
/**
* 广告
*/
class Cctvs {
constructor() {
// 初始化数据
this.arrCctvs = this.getAll();
this.currentEquipmentData = this.getCurrentEquipmentData();
}
/**
* 绑定点击事件
* 所有广告点击
* class="j-cctv-click" data-href="${data.href}" data-id="${data.id}" data-onsite-or-offsite="${data.onsite_or_offsite}"
*/
addEvent() {
$(document).on("click", ".j-cctv-click", function(event) {
event.stopPropagation(); // 阻止事件冒泡
event.preventDefault(); // 阻止默认行为
let strHref = $(this).attr('data-href') ?? '';
let intId = $(this).attr('data-id') ?? '';
let strOnsiteOrOffsite = $(this).attr('data-onsite-or-offsite') ?? '';
console.log(strHref)
clickEvent(strHref, intId, 5, strOnsiteOrOffsite)
})
$(document).on("click", ".j-cctv-click-dp", function(event) {
let strHref = $(this).attr('data-href') ?? '';
let intId = $(this).attr('data-id') ?? '';
let strOnsiteOrOffsite = $(this).attr('data-onsite-or-offsite') ?? '';
clickEvent(strHref, intId, 5, strOnsiteOrOffsite)
})
$(".j-close-float-pupous").on("click", () => {
$("#coupletLeft").addClass("yc")
$("#coupletRight").addClass("yc")
})
}
/**
* 读取所有广告数据
* @returns array
*/
getAll() {
return
let strCtvEncoded = EncAndDec.decryptData(cctvEncodedData, configDecData.MIAO_API_ENCRYPT_KEY);
let CtvEncoded = JSON.parse(strCtvEncoded)
return CtvEncoded.data;
}
/**
* 获取当前设备的数据
* @returns array
*/
getCurrentEquipmentData() {
let currentEquipmentData = []
return
this.arrCctvs.forEach(function (item) {
if (item.status == 1) { // 启用
if (Equipment().isAndroid) {
// 所有设备 + H5(安卓+IOS) + 安卓+ PC+安卓)
if (item.equipment == 400 || item.equipment == 402 || item.equipment == 403 || item.equipment == 405) {
currentEquipmentData.push(item)
}
} else if (Equipment().isPhone) {
// 所有设备 + H5(安卓+IOS) + IOS+ PC+IOS
if (item.equipment == 400 || item.equipment == 402 || item.equipment == 404 || item.equipment == 406) {
currentEquipmentData.push(item)
}
} else {
// 所有设备 + PC + PC+安卓) + PC+ios
if (item.equipment == 400 || item.equipment == 401 || item.equipment == 405 || item.equipment == 406) {
currentEquipmentData.push(item)
}
}
}
})
return currentEquipmentData;
}
/**
* 根据条件读取广告数据
* @param {int} intType
* @param {int} intLocation
* @param {array} arrPageId
* @returns array
*/
getDataByWhere(intType, intLocation, arrPageId) {
return
let arrCctv = []
this.currentEquipmentData.forEach(Cctv => {
if (Cctv.type == intType && Cctv.location == intLocation) {
arrPageId.forEach(intPageId => {
if(Cctv.page_id == intPageId){
arrCctv.push(Cctv)
}
})
}
});
return arrCctv;
}
/**
* 创建横幅 dom
* @param {array} arrCctv
* @param {string} strTip
*/
createBananerDom(arrCctv, strTip = null) {
let DomCctv = ''
arrCctv.forEach((item, index) => {
if (item) {
DomCctv += this.CreateCctvBannerTopDom(item, index, strTip);
}
})
return DomCctv;
}
}
export default Cctvs