fix: point exp
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted } from "vue";
|
||||
import { watchAdStart } from "@/api/system.js";
|
||||
|
||||
const props = defineProps({
|
||||
adUnitId: {
|
||||
@@ -15,6 +16,7 @@ const props = defineProps({
|
||||
const emit = defineEmits(["onReward", "onError", "onClose"]);
|
||||
|
||||
let videoAd = null;
|
||||
let rewardToken = "";
|
||||
|
||||
const onLoadHandler = () => {
|
||||
console.log("Ad Loaded");
|
||||
@@ -27,7 +29,7 @@ const onErrorHandler = (err) => {
|
||||
|
||||
const onCloseHandler = (res) => {
|
||||
if (res && res.isEnded) {
|
||||
emit("onReward");
|
||||
emit("onReward", rewardToken);
|
||||
} else {
|
||||
uni.showToast({ title: "观看完整广告才能获取奖励哦", icon: "none" });
|
||||
emit("onClose");
|
||||
@@ -54,20 +56,37 @@ onUnmounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
const show = () => {
|
||||
if (videoAd) {
|
||||
videoAd.show().catch(() => {
|
||||
videoAd
|
||||
.load()
|
||||
.then(() => videoAd.show())
|
||||
.catch((err) => {
|
||||
console.error("Ad show failed", err);
|
||||
uni.showToast({ title: "广告加载失败,请稍后再试", icon: "none" });
|
||||
emit("onError", err);
|
||||
const show = async () => {
|
||||
try {
|
||||
// Step 1: Start Ad Session to get Token
|
||||
const res = await watchAdStart();
|
||||
if (res && res.rewardToken) {
|
||||
rewardToken = res.rewardToken;
|
||||
|
||||
// Step 2: Show Ad
|
||||
if (videoAd) {
|
||||
videoAd.show().catch(() => {
|
||||
videoAd
|
||||
.load()
|
||||
.then(() => videoAd.show())
|
||||
.catch((err) => {
|
||||
console.error("Ad show failed", err);
|
||||
uni.showToast({
|
||||
title: "广告加载失败,请稍后再试",
|
||||
icon: "none",
|
||||
});
|
||||
emit("onError", err);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
uni.showToast({ title: "当前环境不支持广告", icon: "none" });
|
||||
} else {
|
||||
uni.showToast({ title: "当前环境不支持广告", icon: "none" });
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: "广告启动失败,请稍后再试", icon: "none" });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("watchAdStart failed", e);
|
||||
uni.showToast({ title: "广告启动失败,请稍后再试", icon: "none" });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user