123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import {
- submitTask
- } from '~/api/global'
- var videoAd = null;
- Component({
-
- properties: {
- },
- lifetimes: {
- attached() {
- this.createVideo()
- }
- },
-
- data: {
- },
-
- methods: {
- rewardedVideo() {
- if (!videoAd) {
- this.createVideo()
- }
- videoAd.show().catch(err => {
-
- videoAd.load()
- .then(() => videoAd.show())
- })
- },
-
- createVideo() {
- if (wx.createRewardedVideoAd) {
-
- videoAd = wx.createRewardedVideoAd({
- adUnitId: 'adunit-77f46b2dc73da123'
- })
-
- videoAd.onError(err => {
- console.log(err);
- })
-
- videoAd.onClose((status) => {
- videoAd.offClose()
- videoAd = null
- if (status && status.isEnded || status === undefined) {
-
- submitTask({
- id: 3
- }).then(res => {
- wx.showToast({
- icon: 'none',
- title: '观看成功!',
- })
- this.triggerEvent('taskOver')
- })
- } else {
-
- wx.showToast({
- icon: 'none',
- title: '取消观看',
- })
- }
- })
- }
- }
- }
- })
|