// pages/advertisement/index.js Page({ /** * 页面的初始数据 */ data: { plan_id: '', videoAd: undefined, ad2: '', bol: true, tid: '', clickid: '', adid: '', debugging: '', sid: '', id: '', loadding: true, check: 2, isTap: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let _this = this _this.setData({ tid: options.tid || '', clickid: options.clickid || '', adid: options.adid || '', debugging: options.debugging || '', sid: options.sid || '', id: options.id || '' }) wx.login({ success: function success(res) { if (res.code) { //发起网络请求 wx.request({ url: 'https://honmeigui.huiliuwan.cn/reg', data: { code: res.code, transitpage: 1, tid: options.tid || '', clickid: options.clickid || '', adid: options.adid || '', debugging: options.debugging || '', sid: options.sid || '', id: options.id || '' }, success: function success(res) { wx.setStorageSync('uid', res.data.uid || ''); _this.setData({ plan_id: res.data.ad1, ad2: res.data.ad2 }); wx.showLoading({ title: '视频加载中...', mask: true }) _this.setUserCount(res.data.uid, options) _this.getUserType(); } }); } else { console.log('登录失败!' + res.errMsg); } }, fail: () => { } }); }, setUserCount(uid, options) { let _this = this wx.request({ url: 'https://honmeigui.huiliuwan.cn/setUserCount', data: { transitpage: 1, tid: options.tid || '', clickid: options.clickid || '', adid: options.adid || '', debugging: options.debugging || '', uid: uid }, success: function success(res) { console.log(res) } }); }, adPlay() { this.data.videoAd.show().then(res => { wx.hideLoading(); }).catch(e => { wx.hideLoading(); }) }, adLoad() { this.data.videoAd.load().then(() => { this.adPlay(); }).catch(r => { wx.hideLoading(); }) }, nooe() { this.data.videoAd = wx.createInterstitialAd({ adUnitId: this.data.plan_id }); this.adLoad(); this.data.videoAd.onError(err => { wx.hideLoading(); }) this.data.videoAd.onClose(res => { // 用户点击了【关闭广告】按钮 // 小于 2.1.0 的基础库版本,res 是一个 undefined }) }, navRouter() { const _this = this; wx.redirectTo({ url: '/pages/video/index?tid=' + _this.data.tid + '&clickid=' + _this.data.clickid + '&adid=' + _this.data.adid + '&debugging=' + _this.data.debugging + '&sid=' + _this.data.sid + '&id=' + _this.data.id }) }, getUserType() { let _this = this wx.request({ url: 'https://honmeigui.huiliuwan.cn/getUserType', data: {}, success: function success(res) { if (res.data.check == 1) { _this.setData({ bol: false, check: 1 }) _this.nooe(); } else { if (!this.data.tid) return; wx.redirectTo({ url: '/pages/video/index?tid=' + _this.data.tid + '&clickid=' + _this.data.clickid + '&adid=' + _this.data.adid + '&debugging=' + _this.data.debugging + '&sid=' + _this.data.sid + '&id=' + _this.data.id }) } } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })