chengjunhui пре 1 месец
родитељ
комит
038668e276

+ 5 - 2
app.json

@@ -43,7 +43,7 @@
     "pages/quality/detail/index",
     "pages/match/index",
     "pages/match/details/index",
-    "pages/checkin/index"
+    "pages/checkin/index_1874359642"
   ],
   "subPackages": [
     {
@@ -145,8 +145,11 @@
     "uni-ad": {
       "version": "1.3.7",
       "provider": "wxf72d316417b6767f"
+    },
+    "uni-ad-wx": {
+      "version": "1.0.2",
+      "provider": "wxe6129e9cc9619c07"
     }
-    
   },
   "functionalPages": {
     "independent": true

+ 276 - 0
components/uni-ad-native/uni-ad-native.js

@@ -0,0 +1,276 @@
+
+const EventType = {
+  Load: 'load',
+  Close: 'close',
+  Error: 'error'
+}
+
+const AdType = {
+  Banner: "banner",
+  RewardedVideo: "rewardedVideo",
+  Interstitial: "interstitial"
+}
+
+const ProviderType = {
+  WeChat: 10018,
+  UserWeChat: 10017,
+  ShanHu: 10020
+}
+
+Component({
+  properties: {
+    adpid: {
+      type: String,
+      value: '',
+      observer(newVal, oldVal, changedPath) {
+      }
+    },
+    plugins: {
+      type: String,
+      value: '[{"name":"uni-ad","version":"1.3.7","provider":"wxf72d316417b6767f"},{"name":"uni-ad-wx","version":"1.0.2","provider":"wxe6129e9cc9619c07"}]',
+      observer(newVal, oldVal, changedPath) {
+      }
+    }
+  },
+  data: {
+    wxchannel: false,
+    customFullscreen: "",
+  },
+  created: function () {
+    this.loading = false;
+    this._wxRewardedAd = null;
+    this._wxInterstitialAd = null;
+    this._userInvokeShowFlag = false;
+    this._providerType = ProviderType.ShanHu;
+    this.load();
+  },
+  detached: function() {
+    if (this._wxRewardedAd) {
+      this._wxRewardedAd.destroy()
+    }
+    if (this._wxInterstitialAd) {
+      this._wxInterstitialAd.destroy()
+    }
+  },
+  methods: {
+    load () {
+      if (this.loading) {
+        return
+      }
+      this.loading = true
+      this.errorMessage = null
+      if (this._providerType == ProviderType.ShanHu) {
+      } else if (this._providerType == ProviderType.WeChat) {
+        this.selectComponent('.uniad-plugin-wx').load()
+      } else if (this._providerType == ProviderType.UserWeChat) {
+        this._loadWxAd()
+      }
+    },
+
+    show (e) {
+      this.errorMessage = null
+      if (this.loading == true) {
+        this._userInvokeShowFlag = true
+        return
+      }
+      if (this._providerType == ProviderType.ShanHu) {
+        this.selectComponent('.uniad-plugin').show()
+      } else if (this._providerType == ProviderType.WeChat) {
+        this.selectComponent('.uniad-plugin-wx').show()
+      } else if (this._providerType == ProviderType.UserWeChat) {
+        this._showWxAd(e)
+      }
+    },
+
+    destroy() {
+      // console.log('组件被销毁时自动关闭并销毁广告实例')
+    },
+
+    _onclick () {
+      this.show()
+    },
+
+    _canCreateAd () {
+      if (typeof this.adpid === 'string' && this.adpid.length > 0) {
+        return true
+      } else if (typeof this.adpid === 'number') {
+        return  true
+      }
+      return false
+    },
+
+    _onmpload (e) {
+      this.loading = false
+      this.triggerEvent(EventType.Load, {})
+      if (this._userInvokeShowFlag) {
+        this._userInvokeShowFlag = false;
+        setTimeout(() => {
+          this.show();
+        }, 1)
+      }
+    },
+
+    _onmpclose (e) {
+      this.triggerEvent(EventType.Close, e.detail)
+    },
+
+    _onmperror (e) {
+      this.loading = false
+      this.errorMessage = JSON.stringify(e.detail)
+      this.triggerEvent(EventType.Error, e.detail)
+    },
+
+    _onnextchannel (e) {
+      this.setData({
+        wxchannel: true
+      });
+      const adData = e.detail[0];
+      setTimeout(() => {
+        if (adData.provider == 10017) {
+          this._providerType = ProviderType.UserWeChat
+          switch(adData._nt_) {
+            case 4:
+              this.wxAdType = AdType.Banner
+              this.userwx = true
+              this.userUnitId = adData.posid
+              if (adData.tmpl_type === 24) {
+                this.setData({
+                  customFullscreen: 'uni-ad-custom-fullscreen'
+                })
+              }
+              break;
+            case 9:
+              this.wxAdType = AdType.RewardedVideo
+              this._createRewardedAd(adData.posid)
+              break;
+            case 15:
+              this.wxAdType = AdType.Interstitial
+              this._createInterstitialAd(adData.posid)
+              break;
+          }
+        } else if (adData.provider == 10018) {
+          this._providerType = ProviderType.WeChat
+          if (adData.tmpl_type === 24) {
+            this.setData({
+              customFullscreen: 'uni-ad-custom-fullscreen'
+            })
+          }
+          this.loading = true
+          this.selectComponent('.uniad-plugin-wx').setConfig(adData)
+        }
+      })
+    },
+
+    _onwxchannelerror(e) {
+      this.triggerEvent(EventType.Error, e.detail)
+    },
+
+    _loadWxAd () {
+      switch (this.wxAdType) {
+        case AdType.RewardedVideo:
+          if (this._wxRewardedAd) {
+            this._wxRewardedAd.load();
+          }
+          break;
+        case AdType.Interstitial:
+          if (this._wxInterstitialAd) {
+            this._wxInterstitialAd.load();
+          }
+          break;
+      }
+    },
+
+    _showWxAd () {
+      if (this.loading == true) {
+        this._userInvokeShowFlag = true
+        return
+      }
+      switch (this.wxAdType) {
+        case AdType.RewardedVideo:
+          if (!this._wxRewardedAd) {
+            return;
+          }
+          this._wxRewardedAd.show().catch((err) => {
+            this._wxRewardedAd.load().then(() => {
+              this._wxRewardedAd.show();
+            }).catch((err) => {
+              this.triggerEvent(EventType.Error, err);
+            });
+          });
+          break;
+        case AdType.Interstitial:
+          if (!this._wxInterstitialAd) {
+            return;
+          }
+          this._wxInterstitialAd.show().catch((err) => {
+            this._wxInterstitialAd.load().then(() => {
+              this._wxInterstitialAd.show();
+            }).catch((err) => {
+              this.triggerEvent(EventType.Error, err);
+            });
+          });
+          break;
+      }
+    },
+
+    _createRewardedAd(adUnitId) {
+      if (this._wxRewardedAd) {
+        return;
+      }
+
+      this._wxRewardedAd = wx.createRewardedVideoAd({ adUnitId: adUnitId, multiton: true });
+
+      this._wxRewardedAd.onLoad(() => {
+        this.loading = false
+        this.triggerEvent(EventType.Load, {})
+        if (this._userInvokeShowFlag) {
+          this._userInvokeShowFlag = false;
+          this._wxRewardedAd.show();
+        }
+      });
+
+      this._wxRewardedAd.onError(err => {
+        this.loading = false
+        this.triggerEvent(EventType.Error, err);
+      });
+
+      this._wxRewardedAd.onClose(res => {
+        this.triggerEvent(EventType.Close, res);
+      });
+
+      this._wxRewardedAd?.load().then(() => { }).catch((err) => { });
+
+      this.loading = true
+    },
+
+    _createInterstitialAd(adUnitId) {
+      if (this._wxInterstitialAd) {
+        return;
+      }
+
+      this._wxInterstitialAd = wx.createInterstitialAd({ adUnitId: adUnitId });
+
+      this._wxInterstitialAd.onLoad(() => {
+        this.loading = false
+        this.triggerEvent(EventType.Load, {})
+        if (this._userInvokeShowFlag) {
+          this._userInvokeShowFlag = false;
+          this._wxInterstitialAd.show();
+        }
+      });
+
+      this._wxInterstitialAd.onError(err => {
+        this.loading = false
+        this.triggerEvent(EventType.Error, err);
+      });
+
+      this._wxInterstitialAd.onClose(res => {
+        this.triggerEvent(EventType.Close, res);
+      });
+
+      this._wxInterstitialAd?.load().then(() => { }).catch((err) => { });
+
+      this.loading = true
+    }
+  }
+})

+ 7 - 0
components/uni-ad-native/uni-ad-native.json

@@ -0,0 +1,7 @@
+{
+  "component": true,
+  "usingComponents": {
+    "uni-ad": "plugin://uni-ad/ad",
+    "uni-ad-wx": "plugin://uni-ad-wx/ad"
+  }
+}

+ 4 - 0
components/uni-ad-native/uni-ad-native.wxml

@@ -0,0 +1,4 @@
+<view>
+  <uni-ad wx:if="{{!wxchannel}}" class="uniad-plugin" adpid="{{adpid}}" plugins="{{plugins}}" bind:load="_onmpload" bind:close="_onmpclose" bind:error="_onmperror" bind:nextChannel="_onnextchannel"></uni-ad>
+  <uni-ad-wx wx:if="{{wxchannel}}" class="{{['uniad-plugin-wx', customFullscreen]}}" bind:load="_onmpload" bind:close="_onmpclose" bind:error="_onwxchannelerror"></uni-ad-wx>
+</view>

+ 4 - 0
components/uni-ad-native/uni-ad-native.wxss

@@ -0,0 +1,4 @@
+.uni-ad-custom-fullscreen {
+  display: flex;
+  height: 100vh;
+}

+ 15 - 6
pages/checkin/index.js

@@ -292,6 +292,7 @@ Page({
             title: `签到成功`,
             icon: 'success'
           });
+          _this.loadData();
           await _this.getCheckinHistoryFromServer();
           _this.loadList();
         } else {
@@ -353,7 +354,7 @@ Page({
         break;
     }
     if (taskName.indexOf('观看广告') != -1) {
-      console.log('showInterstitialAd')
+      // console.log('showInterstitialAd')
       // this.showInterstitialAd();
       return
     }
@@ -409,7 +410,15 @@ Page({
       },
       async (res) => {
         if (res.code === 0) {
-          _this.loadList();
+          // 积分统计完成
+          wx.showToast({
+            title: `获取成功`,
+            icon: 'success'
+          });
+          setTimeout(() => {
+            _this.loadList();
+            _this.loadData();
+          }, 1000);
         }
       }
     );
@@ -418,19 +427,19 @@ Page({
    * 查看广告
    * */ 
   showRewardedVideoAd: function (e) {
-    console.log('showRewardedVideoAd')
+    // console.log('showRewardedVideoAd')
     this.selectComponent('.uni-rewarded-video-ad').show();
   },
   onadload: function (e) {
-    console.log('广告加载成功:', e)
+    // console.log('广告加载成功:', e)
   },
   onadclose: function (e) {
     const detail = e.detail;
-    console.log("onClose-播放结束:" + detail)
+    // console.log("onClose-播放结束:" + detail)
     // 用户点击了【关闭广告】按钮
     if (detail && detail.isEnded) {
       // 正常播放结束
-      console.log("onClose-正常播放结束:" + detail.isEnded);
+      // console.log("onClose-正常播放结束:" + detail.isEnded);
       this.addWatchAds();
     } else {
       // 播放中途退出

+ 1 - 1
pages/checkin/index.json

@@ -6,6 +6,6 @@
   "enablePullDownRefresh": true,
   "backgroundTextStyle": "dark",
   "usingComponents": {
-    "uni-ad": "plugin://uni-ad/ad"
+    "uni-ad-native": "/components/uni-ad-native/uni-ad-native"
   }
 }

+ 1 - 1
pages/checkin/index.wxml

@@ -76,5 +76,5 @@
     </view>
   </view>
   <!-- 广告 -->
-  <uni-ad adpid="1204664147" class="uni-rewarded-video-ad" bind:load="onadload" bind:close="onadclose" bind:error="onaderror"></uni-ad>
+    <uni-ad-native adpid="1874359642" class="uni-rewarded-video-ad" bind:load="onadload" bind:close="onadclose" bind:error="onaderror"></uni-ad-native>
 </view>

pages/checkin/index.wxss → pages/checkin/index_1874359642.wxss


+ 1 - 1
pages/home/index/partDetail/partDetail.js

@@ -528,7 +528,7 @@ Page({
       });
     } else if (e.currentTarget.dataset.name == "popup5") {
       wx.navigateTo({
-        url: "/pages/checkin/index",
+        url: "/pages/checkin/index_1874359642",
       });
     } else {
       wx.navigateTo({

+ 1 - 1
pages/my/index/index.js

@@ -272,7 +272,7 @@ Page({
       return false
     }
     wx.navigateTo({
-      url: '/pages/checkin/index'
+      url: '/pages/checkin/index_1874359642'
     });
   },