import articleApi from "../../../api/articleApi" import userArticleApi from '../../../api/userArticleApi' import Dialog from '@vant/weapp/dialog/dialog'; import clientConfig from "../../../config/index" import tool from "../../../utils/tool" let rewardedVideoAd = null Page({ previewImage(e) { const url = e.currentTarget.dataset.url; wx.previewImage({ current: url, urls: [url] }); }, data: { article: {}, downloaded: false, collectioned: false }, goback() { const pages = getCurrentPages(); if (pages.length > 1) { wx.navigateBack(1) } else { wx.switchTab({ url: '/pages/tabpages/index/index' }) } }, handleCollection() { let param = { id: this.data.article.id } userArticleApi.addUserArticleCollection(param).then(res => { if (res.code === 200) { this.setData({ collectioned: !this.data.collectioned }) wx.showToast({ title: res.msg, icon: 'none' }) } }) }, handleDownloadNoAd() { // 复制到剪贴板 wx.setClipboardData({ data: this.data.article.attachmentUrl, success: function (res) { wx.showToast({ title: '已复制到剪贴板', icon: 'none' }) } }) }, handleDownloadHasAd() { let _this = this; wx.showModal({ title: '温馨提示', content: '为了持续维护小程序,为大家更新更多优质项目源码。领取免费资料时需要看小广告,即可获取。', confirmText: '可以理解', // 自定义确认按钮文本 cancelText: '残忍拒绝', // 自定义取消按钮文本 success: function (res) { if (res.confirm) { console.log('用户点击确定执行'); _this.openVideoAd(); } else if (res.cancel) { console.log('用户点击取消操作'); } } }); }, onShareAppMessage() { var that = this; return { title: that.article.title, path: `pages/subpages/articledetail/articledetail?id=${that.article.id}`, imageUrl: that.article.cover } }, openVideoAd() { if (rewardedVideoAd) { rewardedVideoAd.show().then(() => {}).catch(() => { // 失败重试 rewardedVideoAd.load().then(() => rewardedVideoAd.show()).catch(err => { console.log('激励视频 广告显示失败') }) }) } }, onLoad(options) { // const userId = tool.data.get('USER_INFO').id let id = options.id articleApi.detail({ id }).then(res => { // res.data.tags = JSON.parse(res.data.tags) res.data.cover = res.data.fileList[0].fileUrl this.setData({ article: res.data }) // if (res.data.downloadUserIds) { // const downloadUserIds = res.data.downloadUserIds.split(',') // if (downloadUserIds.includes(userId)) { // this.setData({downloaded: true}) // // 获取下载链接 // articleApi.getDownLoadLink({id: this.data.article.id}).then(res=>{ // this.setData({ // 'article.link': res.data // }) // }) // } // } if (res.data.collectionUserIds) { const collectionUserIds = res.data.collectionUserIds.split(',') if (collectionUserIds.includes(userId)) { this.setData({ collectioned: true }) } } if(wx.createRewardedVideoAd){ rewardedVideoAd = wx.createRewardedVideoAd({ adUnitId: 'adunit-448866eb135432e9' }) rewardedVideoAd.onLoad(() => { console.log('onLoad event emit') }) rewardedVideoAd.onError((err) => { console.log('onError event emit', err) }) rewardedVideoAd.onClose((res) => { if (res && res.isEnded || res === undefined) { // 复制到剪贴板 wx.setClipboardData({ data: this.data.article.attachmentUrl, success: function (res) { wx.showToast({ title: '已复制到剪贴板', icon: 'none' }) } }) } else { //不下发奖励 } }) } }) } })