Browse Source

feat: 视频列表广告逻辑修改;

qiansailong 1 year ago
parent
commit
2da57ab750
3 changed files with 68 additions and 40 deletions
  1. 58 31
      pages/video/video.js
  2. 8 8
      pages/video/video.wxml
  3. 2 1
      pages/video/video.wxss

+ 58 - 31
pages/video/video.js

@@ -17,29 +17,35 @@ const app = getApp()
 let interstitialAd = null
 
 Page({
-    data: {
-        videoList: [],
-        loading: false,
-        hasMore: true,
-        page: 1,
-        size: 10,
-        // 状态栏高度
-        statusBarHeight: 20,
-        navHeight: 64, // 导航栏高度 = 状态栏 + 44
-        navStyle: '',
-        listStyle: '',
-        // 添加防抖时间戳
-        lastLoadTime: 0,
-        ads: null,
-        globalConfig: null,
-        // 视频分类列表
-        categoryList: [],
-        // 当前选中的分类ID
-        currentCategoryId: null,
-
-        share_count: 1,
-        hasLoadAdConfig: false,
+  data: {
+    videoList: [],
+    loading: false,
+    hasMore: true,
+    page: 1,
+    size: 10,
+    // 状态栏高度
+    statusBarHeight: 20,
+    navHeight: 64, // 导航栏高度 = 状态栏 + 44
+    navStyle: '',
+    listStyle: '',
+    // 添加防抖时间戳
+    lastLoadTime: 0,
+    ads: null,
+    globalConfig: null,
+    // 视频分类列表
+    categoryList: [],
+    // 当前选中的分类ID
+    currentCategoryId: null,
+
+    share_count: 1,
+    hasLoadAdConfig: false,
+    templateAdId: '',
+    adErrorField: {
+      videoError: false,
+      bannerError: false,
+      templateError: false
     },
+  },
 
   async onLoad() {
     console.log('打开视频页面--------------------------')
@@ -50,8 +56,9 @@ Page({
     }
 
     this.setData({
+      templateAdId: apple.ads.templateAdId,
       hasLoadAdConfig: true
-    })
+  })
 
     this.interstitalLoad()
     getTemplateConfig({
@@ -256,18 +263,12 @@ Page({
           adType: "video",
           lock: false
         }))
-
         videoList = this.formatVideoAdList(videoList);
-
-        console.log(videoList, '过滤后的数组')
-
         console.log("format videoList", videoList)
-
       } catch (apiError) {
         console.error('API调用失败:', apiError)
         throw apiError
       }
-
       // 如果是第一页,直接替换数据
       if (this.data.page === 1) {
         this.setData({
@@ -401,8 +402,7 @@ Page({
   // 点击视频
   onVideoTap(e) {
     const { id, info, index } = e.currentTarget.dataset;
-    console.log(id, info, index, 111111111111111)
-    // const video = this.data.videoList.find(item => item.id === id);
+    console.log(id, info, index, '视频详情')
     if (!info) {
       wx.hideLoading();
       wx.showToast({
@@ -560,4 +560,31 @@ Page({
       wx.hideLoading()
     })
   },
+
+  // 统一小程序广告加载成功
+  appletsAdLoad(e) {
+    let _target = e.currentTarget.dataset
+    this.setData({
+      [`adErrorField.${_target.field}`]: false
+    })
+  },
+
+  // 统一小程序广告加载失败
+  appletsAdError(e) {
+    let _target = e.currentTarget.dataset
+    this.setData({
+      [`adErrorField.${_target.field}`]: true
+    })
+    console.error(_target.name, '错误', e)
+  },
+
+  // 统一小程序广告关闭
+  appletsAdClose(e) {
+    let _target = e.currentTarget.dataset
+  },
+
+  // 统一小程序广告点击
+  appletsAdClick(e) {
+    let _target = e.currentTarget.dataset
+  }
 })

+ 8 - 8
pages/video/video.wxml

@@ -31,10 +31,10 @@
     <view class="list">
       <block wx:for="{{ videoList }}" wx:key="id" wx:for-index="idx">
         <!-- 视频广告 -->
-        <view wx:if="{{itm.adType === 'videoAd' && hasLoadAdConfig}}" class="ad-custom-card">
-          <ad unit-id="{{ads.video_banner_id[0]}}" ad-type="video" ad-theme="white" data-field="videoError"
-            data-name="首页-视频1" data-adId="{{ads.video_banner_id[0]}}" bindload="appletsAdLoad"
-            binderror="appletsAdError" bindclose="appletsAdClose"></ad>
+        <view wx:if="{{item.adType === 'videoAd' && hasLoadAdConfig}}" class="ad-custom-card">
+          <ad unit-id="{{templateAdId}}" ad-type="video" ad-theme="white" data-field="videoError"
+            data-name="首页-视频1" data-adId="{{templateAdId}}" bindload="appletsAdLoad"
+            binderror="appletsAdError" bindclose="appletsAdClose" style="height: 100%;margin-bottom: 20rpx;"></ad>
         </view>
         <view wx:if="{{ item.adType === 'video' }}">
           <!-- 视频卡片 -->
@@ -69,10 +69,10 @@
           </view>
         </view>
          <!-- 卡片原生广告 -->
-         <view wx:if="{{itm.adType === 'templateAd' }}" class="ad-custom-card-1">
-            <ad-custom unit-id="adunit-80f6ec7a264f968b" data-field="templateError" data-name="首页页-卡片原生"
-              data-adId="adunit-80f6ec7a264f968b" capture-bind:tap="appletsAdClick" bindload="appletsAdLoad"
-              binderror="appletsAdError"></ad-custom>
+         <view wx:if="{{item.adType === 'templateAd' && hasLoadAdConfig }}" class="ad-custom-card-1">
+            <ad-custom unit-id="{{templateAdId}}" data-field="templateError" data-name="首页页-卡片原生"
+              data-adId="{{templateAdId}}" capture-bind:tap="appletsAdClick" bindload="appletsAdLoad"
+              binderror="appletsAdError" style="height: 100%;margin-bottom: 20rpx;"></ad-custom>
           </view>
       </block>
     </view>

+ 2 - 1
pages/video/video.wxss

@@ -330,7 +330,8 @@
 
 .ad-custom-card-1 {
   width: 100%;
-  padding: 0 20rpx;
+  /* padding: 0 20rpx; */
   box-sizing: border-box;
   border-radius: 8rpx;
+  margin-bottom: 20rpx;
 }