| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import {
- unlockChapter
- } from '../../api/api.js'
- import {
- apple
- } from '../../config/config'
- const novelPlugin = requirePlugin('novel-plugin')
- Component({
- properties: {
- novelManagerId: {
- type: Number,
- value: -1,
- },
- bookId: {
- type: String,
- value: '',
- },
- chapterIndex: {
- type: Number,
- value: -1,
- },
- chapterId: {
- type: String,
- value: '',
- },
- originalId: {
- type: String,
- value: '',
- },
- },
- data: {
- countdownNum: 3,
- isCounting: false
- },
- created() {
- this.rewardVideoLoad()
- },
- ready() {
- setTimeout(() => {
- this.startCountdown()
- }, 500)
- },
- detached() {
- this.stopCountdown(); // 页面卸载时清除定时器
- },
- methods: {
- unlock() {
- this.stopCountdown();
- this.rewardVideoPlayFn()
- },
- // 激励视频加载
- rewardVideoLoad() {
- if (wx.createRewardedVideoAd) {
- let adId = apple.ads.rewardAdId
- this.videoAd = wx.createRewardedVideoAd({
- adUnitId: adId
- })
- this.videoAd.offClose()
- this.videoAd.onLoad(() => {
- console.log('激励加载成功')
- })
- this.videoAd.onError((err) => {
- console.log('激励失败', err)
- })
-
- this.videoAd.onClose((res) => {
- const novelManager = novelPlugin.getNovelManager(this.properties.novelManagerId)
- if (res && res.isEnded) {
- // for (let index = 0; index < getApp().globalData.unlockChapterNum; index++) {
- // }
- let params = {
- chapterNo: this.properties.chapterIndex,
- novelId: getApp().globalData.novelId,
- type: 1
- }
- unlockChapter(params).then(res => {
- console.log(res)
- novelManager.paymentCompleted()
- console.log('章节解锁成功',this.properties.chapterIndex)
- })
- this.videoAd.offClose()
- } else {
- novelManager.closeChargeDialog()
- console.log('关闭解锁组件')
- }
- })
- }
- },
- // 激励视频展示
- rewardVideoPlayFn() {
- wx.showLoading({
- title: '解锁视频中',
- })
- this.videoAd.show().then(() => {
- console.log('激励视频播放成功')
- }).catch((err) => {
- console.log('激励视频播放失败', err)
- }).then(() => {
- wx.hideLoading()
- })
- },
- startCountdown() {
- this.setData({
- isCounting: true
- });
- let seconds = 3;
- this.countdownTimer = setInterval(() => {
- seconds--;
- this.setData({
- countdownNum: seconds
- });
- if (seconds <= 0) {
- this.stopCountdown();
- this.onCountdownEnd();
- }
- }, 1000);
- },
- stopCountdown() {
- clearInterval(this.countdownTimer);
- this.setData({
- isCounting: false
- });
- },
- onCountdownEnd() {
- this.rewardVideoPlayFn()
- }
- },
- })
|