fix: point exp

This commit is contained in:
zzc
2026-02-25 09:54:41 +08:00
parent 6c1084ef32
commit 1fef1818d8
3 changed files with 89 additions and 43 deletions

View File

@@ -97,6 +97,7 @@
@logind="handleLogind"
:share-token="shareToken"
/>
<RewardAd ref="rewardAdRef" @onReward="handleAdReward" />
</view>
</template>
@@ -118,11 +119,11 @@ import { onShareAppMessage, onShareTimeline, onLoad } from "@dcloudio/uni-app";
import { getShareReward, abilityCheck, watchAdReward } from "@/api/system.js";
import { useUserStore } from "@/stores/user";
import NavBar from "@/components/NavBar/NavBar.vue";
let videoAd = null;
import RewardAd from "@/components/RewardAd/RewardAd.vue";
const userStore = useUserStore();
const loginPopupRef = ref(null);
const rewardAdRef = ref(null);
const isLoggedIn = computed(() => !!userStore.userInfo.nickName);
const userPoints = computed(() => userStore.userInfo.points || 0);
@@ -188,29 +189,6 @@ onLoad((options) => {
eventName: "avatar_download_page_visit",
eventType: `visit`,
});
// Initialize Rewarded Video Ad
if (uni.createRewardedVideoAd) {
videoAd = uni.createRewardedVideoAd({
adUnitId: "adunit-d7a28e0357d98947",
});
videoAd.onLoad(() => {
console.log("ad loaded");
});
videoAd.onError((err) => {
console.error("ad load error", err);
});
videoAd.onClose((res) => {
console.log(1212121212, res);
if (res && res.isEnded) {
handleAdReward();
} else {
// Playback not completed
uni.showToast({ title: "观看完整广告才能获取积分哦", icon: "none" });
}
});
}
});
const getThumbUrl = (url) => {
@@ -308,23 +286,6 @@ const previewImage = (index) => {
});
};
const showRewardAd = () => {
if (videoAd) {
videoAd.show().catch(() => {
// Failed to load, try loading again
videoAd
.load()
.then(() => videoAd.show())
.catch((err) => {
console.error("Ad show failed", err);
uni.showToast({ title: "广告加载失败,请稍后再试", icon: "none" });
});
});
} else {
uni.showToast({ title: "当前环境不支持广告", icon: "none" });
}
};
const handleAdReward = async () => {
try {
const res = await watchAdReward();
@@ -375,7 +336,7 @@ const downloadAvatar = async (item) => {
content: "观看广告可获得50积分继续下载",
success: (res) => {
if (res.confirm) {
showRewardAd();
rewardAdRef.value.show();
}
},
});