// packageI/AdBright/AdBrightIndex/AdBrightIndex.js const app = getApp() // 获取小程序全局对象 let _pageprocessing = null; try { const { pageprocessing } = requirePlugin('adbright-ad') // 插件输出的页面加工函数 _pageprocessing = pageprocessing } catch (error) { console.log(error) } import ADService from '../adService' // 引入步骤8的创建的服务 try { const pageWrap = _pageprocessing( app.adConfig, // 全局的广告配置 ADService // 广告服务 ) Page(pageWrap({ /** * 页面的初始数据 */ data: { integral: '', placementId: '', mini_form_id: '', //小程序流量主广告单元ID level_credit: 0, //当前等级观看可获取积分 level_data: [], adv_list: [], member: {}, level_index: 0, redirectToUrl:'', Partner:false, pid:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const value = wx.getStorageSync('integral'); if (value) { this.setData({ integral: value }); } if(options.pid){ this.data.pid = options.pid } if(options.Partner){ this.data.Partner = true; this.data.redirectToUrl ='/packageF/sharedPartner/sharedPartner'; }else{ this.data.redirectToUrl ='/packageI/AdBright/AdBrightIndex/AdBrightIndex'; } if (options.adv_id && options.wxad) { this.setData({ placementId: options.adv_id, mini_form_id: options.wxad }) console.log('ssssssssssssssssssssssssssss', this.data.placementId, this.data.mini_form_id) wx.showToast({ duration: 2000, title: '跳转广告中', icon: 'none' }); this.getADData() } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, getADData(e) { // 使用微信插屏广告和激励视频广告时,需要在页面加载后,或者触发广告之前通过调用setWeixinAdConfig方法提前设置微信广告相关参数。 this.setWeixinAdConfig({ placementId: this.data.placementId, // 营销去广告ID **必传** weixin: { type: 'motivation', // 广告类型 **必传** unitId: this.data.mini_form_id, // 微信广告单元ID **必传** succcess() { console.log('==============微信广告加载成功回调====================') }, // 微信广告加载成功回调 fail() { console.log('==============微信广告加载失败回调====================') } // 微信广告加载失败回调 } }) if (!app.adConfig.app_id || !app.adConfig.domain) { wx.showToast({ icon: "none", title: '缺失广告配置信息', duration: 1000, }); return } this.getADDataVideo(); }, getADDataVideo() { let that = this; let ad = this.getAdbrightData({ placementId: this.data.placementId, // 营销云平台广告位ID,如123123123 **必传** success() { console.log('getAdbrightData::请求success===========================') }, // 获取营销云广告成功的回调,默认返回广告数据 fail() { console.log('getAdbrightData::请求fail===========================') }, // 获取营销云广告失败的回调,返回错误信息 weixin: { type: 'motivation', // 微信广告类型,目前支持4种,分别是ad、ad-custom、insert、motivation。其中insert、motivation是插屏和激励视频,使用时需要配合setWeixinAdConfig方法一起使用 unitId: this.data.mini_form_id, //广告单元ID,可在微信管理后台的流量主模块新建(同微信小程序ad、ad-custom组件文档) adIntervals: 50, // 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时,广告不会自动刷新)(同微信小程序ad、ad-custom组件文档) adType: 'video', // 广告类型,默认为展示banner,可通过设置该属性为video展示视频广告,grid为格子广告(同微信小程序ad组件文档) adTheme: 'white', // 主题色,默认为white(同微信小程序ad组件文档) success() { console.log('==============微信广告加载成功回调222====================') }, // 广告加载成功的回调(绑定了bindload事件,支持所有的微信广告类型) fail() { console.log('==============微信广告加载失败回调222====================') }, // 广告加载失败的回调(绑定了binderror事件,支持所有的微信广告类型) close() {} // 广告关闭的回调(绑定了bindclose事件,不支持微信模板ad-custom广告类型) } }); // 自有广告点击回调 ad.onClick = () => { console.log("自有广告被点击了") } // 自有广告失败回调 ad.onError = (err) => { console.log("自有广告加载出错了或者加载失败了err: ",ad, err) wx.showToast({ duration: 2000, title: '正在为您加载微信广告', icon: 'none' }); } //自有广告关闭回调(插屏和激励视频) ad.onClose = (res) => { console.log("自有广告关闭了") if (res.isEnded) { console.log("激励视频达到奖励条件") // that.getReward() } else { console.log("激励视频未达到奖励条件") } wx.redirectTo({ url: this.data.redirectToUrl }) } //自有广告视频播放完毕回调(插屏和激励视频) ad.onEnd = (res) => { console.log("自有广告视频播放完毕") if(that.data.Partner){ that.PartnerReward(); return } that.getReward() } // 流量主广告播放完毕回调,暂不支持 ad.onWxEnd = () => { console.log("流量主广告播放完毕了===================") // that.getReward() } // 流量主广告显示回调 ad.onWxShow = () => { console.log("流量主广告显示了") } // 流量主广告出错回调 ad.onWxError = (err) => { console.log("流量主广告加载出错了err: ") wx.showModal({ title: '提示', content: '获取广告失败,请稍后重试', showCancel: false, success(res) { wx.redirectTo({ url: this.data.redirectToUrl }) } }) } // 流量主广告关闭回调 ad.onWxClose = (res) => { console.log("流量主广告关闭了") if (res.isEnded) { if(that.data.Partner){ that.PartnerReward(true); return } that.getReward(true) console.log("流量主广告达到奖励条件") } else { console.log("流量主广告未达到奖励条件") wx.redirectTo({ url: this.data.redirectToUrl }) } } }, PartnerReward(redirectTo){ let that = this; let urlStr = app.getNetAddresss("plugin.share-partner.frontend.dividend.draw"); app._postNetWork({ url: urlStr, data: { dividend_id: this.data.pid, adv_id:this.data.placementId }, success: (resdata) => { let res = resdata.data; wx.showModal({ title: '提示', content: res.msg, showCancel: false, success(res) { // that.getData(); if(redirectTo){ wx.redirectTo({ url: that.data.redirectToUrl }) } } }) }, fail: (res) => { console.log(res); }, }); }, getReward(redirectTo) { let that = this; let urlStr = app.getNetAddresss("plugin.flyers-advertise.frontend.reward.miniReward"); app._postNetWork({ url: urlStr, data: { adv_id: this.data.placementId }, success: (resdata) => { let res = resdata.data; wx.showModal({ title: '提示', content: res.msg, showCancel: false, success(res) { // that.getData(); if(redirectTo){ wx.redirectTo({url: that.data.redirectToUrl}) } } }) }, fail: (res) => { console.log(res); }, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })) } catch (error) { // wx.showModal({ // title: '提示', // content: '广告加载失败,请检查配置', // showCancel: false, // success(res) { // if (res.confirm) { // wx.reLaunch({ // url: "/packageG/index/index" // }); // } // } // }) }