liyongli hace 3 meses
padre
commit
b5b8222ae1
Se han modificado 3 ficheros con 30 adiciones y 18 borrados
  1. 28 15
      sdk/adList.js
  2. 0 0
      sdk/adList.min.js
  3. 2 3
      sdk/index.html

+ 28 - 15
sdk/adList.js

@@ -25,13 +25,20 @@ document.addEventListener('DOMContentLoaded', function () {
     const dateTime = D.getTime()
     for (let i = 0; i < slots.length; i++) {
       const v = slots[i]
-      if (!v.creativesList || !v.creativesList.length) continue
       // 获取对应广告位置
       const ad_pos = document.querySelector('#sxtv-ad-' + v.slotId)
       if (!ad_pos) {
         console.error('广告位置不存在:#sxtv-ad-' + v.slotId)
         continue
       }
+      ad_pos.style.width = (v.width || 0) + 'px'
+      ad_pos.style.height = (v.height || 0) + 'px'
+      ad_pos.style.overflow = 'hidden'
+      ad_pos.style.position = 'relative'
+      if (!v.creativesList || !v.creativesList.length) {
+        if (v.baseMaterial) ad_pos.appendChild(generateDefaultAd(v))
+        continue
+      }
       const gg = document.createElement('div')
       gg.innerHTML =
         '<svg t="1734493782806" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9775" width="32" height="32"><path d="M560.88 658.8h69.68v15.44h-69.68z" p-id="9776" fill="#515151"></path><path d="M698.24 451.44V200h-46.56v251.44H372.32V200h-46.56v251.44H186V824h651.92V451.44zM505.12 600H396.16v90.72L352 700.08v-33.92l8-2.4V575.2h54.24l-1.84-8.8h45.84l1.68 8.8h44.88z m162.72 96.48H524.4v-60h143.44z m5.36-64.48H518.88v-23.36h61.12v-11.28h-22.16l-2.88 8.48H520V582.4h8.72l5.52-13.76H568l-2.32 6.64h14.32v-8h38.64v8h49.04v22h-49.04v11.36h54.56z" p-id="9777" fill="#515151"></path></svg>'
@@ -47,25 +54,36 @@ document.addEventListener('DOMContentLoaded', function () {
         const start = new Date(item.startDate + ' 00:00:00').getTime()
         const end = new Date(item.endDate + ' 23:59:59').getTime()
         // 判断变量是否数组
-        if (dateTime < start || dateTime > end || !Array.isArray(item.stuffsList)) continue
+        if (dateTime < start || dateTime > end || !Array.isArray(item.stuffsList)) {
+          if (v.baseMaterial) ad_pos.appendChild(generateDefaultAd(v))
+          continue
+        }
         // 获取广告类型 1 轮播 2 交替 3 单项
         const showType = item.showType
         let e =
           showType === 1
             ? generateCarouselAd(item, D, v.slotId, v.width || 0, v.height || 0)
             : generateAlternateAd(item, D, v.slotId, v.width || 0, v.height || 0)
-        if (e == -1) continue
+        if (e == -1 && !v.baseMaterial) continue
+        // 使用打底素材
+        if (e == -1) e = generateDefaultAd(v)
         show = true
         ad_pos.appendChild(e)
       }
-      ad_pos.style.width = (v.width || 0) + 'px'
-      ad_pos.style.height = (v.height || 0) + 'px'
-      ad_pos.style.overflow = 'hidden'
-      ad_pos.style.position = 'relative'
       ad_pos.style.display = show ? 'block' : 'none'
     }
   }
 
+  // 投放打底素材
+  function generateDefaultAd(v) {
+    console.log('投放打底素材', v)
+    const son_ele = document.createElement('img')
+    son_ele.src = 'https://www.baidu.com/img/flexible/logo/pc/result.png'
+    son_ele.style.width = '100%'
+    son_ele.style.height = '100%'
+    return son_ele
+  }
+
   // 生成轮播广告
   const generateCarouselAd = function (generateCarousel = {}, D, slotId, width, height) {
     const week = D.getDay() === 0 ? 6 : D.getDay() - 1
@@ -121,7 +139,7 @@ document.addEventListener('DOMContentLoaded', function () {
     const son_ele = document.createElement('video')
     son_ele.setAttribute('loop', 'loop')
     son_ele.setAttribute('autoplay', 'autoplay')
-    son_ele.setAttribute('muted', 'muted')
+    son_ele.muted = true
     son_ele.src = stuff.addr
     son_ele.style.width = '100%'
     son_ele.style.height = '100%'
@@ -129,19 +147,14 @@ document.addEventListener('DOMContentLoaded', function () {
     son_ele.oncanplay = () => {
       son_ele.play()
       const uuid = localStorage.getItem('ad_id')
-      fetch(`${base}ad/show?uuid=${uuid}&stuffId=${stuff.stuffId}&slotId=${slotId}`).then((res) =>
-        res.text(),
-      )
+      fetch(`${base}ad/show?uuid=${uuid}&stuffId=${stuff.stuffId}&slotId=${slotId}`)
     }
     son_ele.addEventListener('click', () => {
       if (!stuff.landingPage) return
       const uuid = localStorage.getItem('ad_id')
+      window.open(stuff.landingPage)
       // 点击广告
       fetch(`${base}ad/click?uuid=${uuid}&stuffId=${stuff.stuffId}&slotId=${slotId}`)
-        .then((res) => res.text())
-        .then(() => {
-          window.open(stuff.landingPage)
-        })
     })
     // 对body添加一次性点击事件
     const play = () => {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
sdk/adList.min.js


+ 2 - 3
sdk/index.html

@@ -5,12 +5,11 @@
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Document</title>
-    <!-- <script id="sxtv-ad-id" src="./adList.js?a=009" ad_id="001"></script> -->
-    <script src="./adList.js" ad_id="1016" id="sxtv-ad-id"></script>
+    <script src="./adList.js" ad_id="1022" id="sxtv-ad-id"></script>
 </head>
 
 <body>
-    <div id="sxtv-ad-119"></div>
+    <div id="sxtv-ad-124"></div>
 </body>
 
 </html>

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio