hank 1 год назад
Родитель
Сommit
37dc53c7c3
3 измененных файлов с 113 добавлено и 7 удалено
  1. 2 2
      api/api.js
  2. 109 3
      pages/video/video.js
  3. 2 2
      pages/video/video.wxml

+ 2 - 2
api/api.js

@@ -106,7 +106,7 @@ export const getBrowsingHistory = () => {
 
 // 获取短剧列表
 export function getVideoList(params = {}) {
-    const {page = 1, size = 10, tag_id = 2245, filter_id = "", next_id = ""} = params;
+    const {page = 1, size = 10, tag_id = 2245, filter_id = "", next_id = "",gh_id = ""} = params;
 
     const requestData = {
         tag_id: tag_id,
@@ -114,7 +114,7 @@ export function getVideoList(params = {}) {
         next_id: next_id,
         count: size,
         uuid: getApp().globalData.uuid, // 固定值,实际应用中可能需要动态生成
-        gh_id: "gh_4e55f615d5dc" // 固定值
+        gh_id: gh_id // 固定值
     };
 
     return postWithCommonParams("https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getvideolist", requestData)

+ 109 - 3
pages/video/video.js

@@ -39,6 +39,8 @@ Page({
 
         share_count: 1,
         templateAdId: '',
+        hasLoadAdConfig: false,
+        templateError: false,
     },
 
     async onLoad() {
@@ -54,8 +56,27 @@ Page({
             box_type: 67,
             uuid: getApp().globalData.uuid
         }).then(res => {
+            console.log('广告ID与配置 ======== ', res)
+            this.config = {
+                data: res || {},
+                get: function (keyStr) {
+                    let keys = keyStr.split('.')
+                    let obj = this.data
+                    for (let i = 0; i < keys.length; i++) {
+                        let temp = obj[keys[i]]
+                        if (temp) {
+                            obj = obj[keys[i]]
+                        } else {
+                            return false
+                        }
+                    }
+                    return obj
+                }
+            }
             this.setData({
-                globalConfig: res.globalConfig
+                globalConfig: res.globalConfig,
+                // ads: this.config.get("ads_config"),
+                hasLoadAdConfig: true
             })
             // 获取视频分类
             this.getVideoCategories()
@@ -237,7 +258,8 @@ Page({
                 // 如果不是第一页,传递最后一个视频的ID作为next_id
                 next_id: this.data.page > 1 && this.data.videoList.length > 0 ?
                     this.data.videoList[this.data.videoList.length - 1].id :
-                    ""
+                    "",
+                gh_id: apple.ghid
             }
 
             let videoList = []
@@ -294,6 +316,18 @@ Page({
         let templateGap = 0,
             rewardGap = 0
 
+        if (this.config.get('globalConfig.isHomeTemplateAd') === 1) {
+            templateGap = this.config.get('globalConfig.homeTemplateAdInterval')
+        } else {
+            templateGap = 0
+        }
+
+        if (this.config.get('globalConfig.isHomeRewardAd') === 1) {
+            rewardGap = this.config.get('globalConfig.homeRewardAdInterval')
+        } else {
+            rewardGap = 0
+        }
+
         // 第二个固定是原生广告
         let result = [arr.shift(), {
             adType: 'templateAd'
@@ -311,6 +345,7 @@ Page({
                     result.push({
                         adType: "templateAd"
                     })
+                    console.log("原生广告id:", this.data.templateAdId)
                     templateAdFlag = false
                     rewardAdFlag = true
                     continue
@@ -500,5 +535,76 @@ Page({
             wxBookId: 'A1Hcfv456vGtMYxQjxUm8KNdJ8',
             chapterId: null
         });
-    }
+    },
+    // 统一小程序广告点击
+    appletsAdClick(e) {
+        console.log('小程序广告加载成功')
+        let _target = e.currentTarget.dataset
+    },
+    // 统一小程序广告加载成功
+    appletsAdLoad(e) {
+        console.log('小程序广告加载成功')
+        let _target = e.currentTarget.dataset
+        this.setData({
+            [`adErrorField.${_target.field}`]: false
+        })
+    },
+    // 统一小程序广告加载失败
+    appletsAdError(e) {
+        console.log('小程序广告加载失败')
+        let _target = e.currentTarget.dataset
+        this.setData({
+            [`adErrorField.${_target.field}`]: true
+        })
+        console.error(_target.name, '错误', e)
+    },
+    // 激励视频加载
+    rewardVideoLoad() {
+        if (wx.createRewardedVideoAd) {
+            let adId = ''
+            if (this.data.ads) {
+                adId = this.data.ads.video_ad_id
+            }
+            let that = this
+            this.videoAd = wx.createRewardedVideoAd({
+                adUnitId: adId
+            })
+
+            this.videoAd.onLoad(() => {
+                console.log('首页激励加载成功')
+            })
+            this.videoAd.onError((err) => {
+                console.log('首页激励失败', err)
+            })
+            this.videoAd.onClose((res) => {
+                // 用户点击了【关闭广告】按钮
+                this.setData({
+                    isLoadingVideo: false
+                })
+                if (res && res.isEnded) {
+                    // 发放奖励
+                    that.setData({
+                        [`categoryList[${that.data.tabIndex}].list[${that.reawrdVideoIndex}].lock`]: false
+                    })
+                    console.log('发放奖励跳转')
+                    wx.navigateTo({
+                        url: `${that.unlockUrl}`
+                    })
+                } else {
+                    // 未看完整视频
+                    // wx.showModal({
+                    //   title: '提示',
+                    //   content: '您需要观看完毕才能进行文章查看,重新播放广告吗?',
+                    //   success (res) {
+                    //     if (res.confirm) {
+                    //       that.rewardVideoPlayFn()
+                    //     } else if (res.cancel) {
+                    //       console.log('用户点击取消')
+                    //     }
+                    //   }
+                    // })
+                }
+            })
+        }
+    },
 })

+ 2 - 2
pages/video/video.wxml

@@ -64,8 +64,8 @@
         </view>
          <!-- 卡片原生广告 -->
          <view wx:if="{{itm.adType === 'templateAd' }}" class="ad-custom-card-1">
-            <ad-custom unit-id="{{templateAdId}}" data-field="templateError" data-name="首页页-卡片原生"
-              data-adId="{{templateAdId}}" capture-bind:tap="appletsAdClick" bindload="appletsAdLoad"
+            <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>