yaoyao 2 лет назад
Родитель
Сommit
fe5e980676
2 измененных файлов с 56 добавлено и 64 удалено
  1. 56 64
      pages/ad/index.vue
  2. BIN
      static/icon/ad/qcj.png

+ 56 - 64
pages/ad/index.vue

@@ -22,47 +22,18 @@
 						<view class="title2">已观看{{ taskObj.watchCount }}/{{ taskObj.total }}</view>
 					</view>
 					<view style="flex: 1;"></view>
-					<ad-rewarded-video v-if="taskStatus == false" :adpid="adpid" :loadnext="true"
+					<!-- v-if="taskStatus == false"  -->
+					<ad-rewarded-video ref="adRewardedVideo" :adpid="adpid" :preload="false"
 						v-slot:default="{loading, error}" @load="onadload" @close="onadclose" @error="onaderror"
 						:url-callback="callbackData">
 						<!-- <view v-if="error">{{error}}</view> -->
 						<!-- <u-button type="primary" style="width:100px;" size="mini"  :disabled="loading" :loading="loading">去完成</u-button> -->
-						<button :disabled="loading" :loading="loading" class="video-button">去完成</button>
+						<!-- <button :disabled="loading" :loading="loading" class="video-button">去完成</button> -->
 					</ad-rewarded-video>
+					<button v-if="taskStatus == false" :disabled="isLoading" :loading="isLoading" class="video-button" @click="showAd">去完成</button>
 				</view>
 			</view>
 		</view>
-		<!-- <view
-			style="height:200px;background: #14a1ff;padding:10px;border-radius: 5px;display: flex;    flex-direction: column;box-shadow: rgb(204, 204, 204) 0 0 7px 5px;">
-			<view style="color:#fff;font-size:14px;flex:2;">今日奖励</view>
-			<view style="color:#fff;flex:2;text-align: center;font-size: 20px;">抽奖次数1次</view>
-			<view style="flex:1;">
-				<view style="display: flex;justify-content: normal; justify-content: space-around;color:#fff;">
-					<block v-if="taskStatus == false">
-						<view>今日任务次数:{{taskObj.total}}</view>
-						<view>当前已完成任务次数:{{taskObj.watchCount}}</view>
-					</block>
-					<block v-if="taskStatus">
-						<u-button style="width:200px;" @click="toChoujiang">跳转抽奖</u-button>
-					</block>
-				</view>
-				<u-line-progress active-color="#2979ff" :percent="progress"></u-line-progress>
-			</view>
-		</view>
-		<view>
-			<view style="font-size:20px;padding-top:20px;">
-				<view style="display: flex;justify-content: space-between;align-items: center;">
-					<view style="display: flex; align-items: center;">
-						<u-image style="width:25px;" src="@/static/icon/ad.png" mode="widthFix"></u-image>
-						<view style="margin-left:5px;">视频广告</view>
-					</view>
-
-					<view v-if="taskStatus">
-						<u-button type="default">已完成</u-button>
-					</view>
-				</view>
-			</view>
-		</view> -->
 	</view>
 </template>
 
@@ -85,52 +56,89 @@
 					extra: {}
 				},
 				error: "",
-				taskStatus: false
+				taskStatus: false,
+				isLoading: false,
+				adId: '',
 			}
 		},
 		computed: {
 			...mapState(['userInfo', 'userCheckInfo']),
 		},
 		async onLoad() {
+			// this.refreshData();
+			// this.callbackData.userId = this.userInfo.sysUser.id
+		},
+		onShow() {
 			this.refreshData();
 			this.callbackData.userId = this.userInfo.sysUser.id
 		},
-		onShow() {
-
+		onReady() {
+		  // this.isLoading = true;
+		  // this.$refs.adRewardedVideo.load();
 		},
 		methods: {
-			onadload(e) {},
-			onCreateAd() {
-
+			onadload(e) {
+				// this.isLoading = false;
+				console.log(e, 'onadload')
 			},
-			onadclose(e) {
+			// 去看广告
+			async showAd() {
+				if (this.isLoading) {
+				  return
+				}
+				// 获取广告id /callback/advertisingLog
+				let res = await this.$http.post('https://marketing.baoxianzhanggui.com/api/callback/advertisingLog', {
+				// let res = await this.$http.post('/callback/advertisingLog', {
+					userId: this.userInfo.sysUser.id
+				})
+				console.log(res)
+				if (res.code == 200) {
+					this.adId = res.data
+					this.isLoading = true
+					this.callbackData.extra = "{id: " + res.data + "}"
+					this.$refs.adRewardedVideo.show();
+				}
+				
+			},
+			 async onadclose(e) {
 				const detail = e.detail
 				// 用户点击了【关闭广告】按钮
+				let that = this
 				if (detail && detail.isEnded) {
 					//重新拉取数据
-					setTimeout(this.refreshData(), 3000);
+					let times = 0
+					this.timer = setInterval(async () => {
+						times ++
+						let res = await that.$http.get('https://marketing.baoxianzhanggui.com/api/callback/verifyWatch', {
+							id: that.adId
+						})
+						if (times >= 30 || res.data) {
+							clearInterval(that.timer)
+							that.refreshData()
+							that.isLoading = false
+							times = 0
+						}
+					}, 1000)
+					// setTimeout(this.refreshData(), 3000);
 				} else {
 					// 播放中途退出
 					console.log("onadclose " + detail.isEnded);
 				}
 			},
+			// 广告加载失败
 			onaderror(e) {
-
-				// 广告加载失败
-				//  this.$refs.uToast.show({
-				// 	title: '广告加载失败',
-				// 	type: 'default',
-				// })
 				uni.showToast({
 					icon: 'none',
 					title: e.detail.errMsg
 				})
-
+				this.isLoading = false;
 				console.log("onaderror: ", e.detail);
 			},
+			// 刷新数据
 			refreshData() {
 				console.log(this.userInfo)
 				this.$http.post('https://marketing.baoxianzhanggui.com/api/advertising/getUserWatchCount', {
+				// this.$http.post('/advertising/getUserWatchCount', {
 					userId: this.userInfo.sysUser.id
 				}).then(res => {
 					console.log(res)
@@ -144,46 +152,30 @@
 			},
 			toChoujiang() {
 				console.log('抽奖')
-
 				plus.share.getServices(res => {
-
 					let sweixin = null;
-
 					sweixin = res.find(i => i.id === 'weixin')
-
 					if (sweixin) {
-
 						// 分享跳转到微信小程序
-
 						sweixin.launchMiniProgram({
-
 							id: "gh_71ff3b2409d8", //微信小程序原生id
-
 							path: "pages/index/bigWheel/bigWheel?userId=" + this.userInfo.sysUser.id +
 								"&activityId=" + this.activityId, //    打开小程序的页面路径,不传默认跳转首页
-
 							type: 2 //     微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
-
 						})
-
 					} else {
 						uni.showToast({
 							title: '请安装微信',
 							icon: 'none'
 						})
 					}
-
 				}, err => {
 					console.log("分享失败"); // 获取分享服务列表失败
 				});
-
-
-
 				uni.navigateToMiniProgram({
 					appId: 'wx4014825e79c10552',
 					path: 'pages/index/index?userId=' + this.userInfo.sysUser.id,
 					extraData: {
-
 					},
 					success(res) {
 						// 打开成功

BIN
static/icon/ad/qcj.png