From 6c1084ef322410038f6fcd5215dd8d4dd816237c Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Wed, 25 Feb 2026 00:25:56 +0800 Subject: [PATCH] fix: point exp --- api/system.js | 7 ++++ pages/avatar/download.vue | 71 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/api/system.js b/api/system.js index 4f0a5ea..888a932 100644 --- a/api/system.js +++ b/api/system.js @@ -81,3 +81,10 @@ export const createTracking = async (data) => { data, }); }; + +export const watchAdReward = async () => { + return request({ + url: "/api/blessing/ad/reward", + method: "POST", + }); +}; diff --git a/pages/avatar/download.vue b/pages/avatar/download.vue index a8acbb6..2948944 100644 --- a/pages/avatar/download.vue +++ b/pages/avatar/download.vue @@ -115,10 +115,12 @@ import { saveViewRequest, } from "@/utils/common.js"; import { onShareAppMessage, onShareTimeline, onLoad } from "@dcloudio/uni-app"; -import { getShareReward, abilityCheck } from "@/api/system.js"; +import { getShareReward, abilityCheck, watchAdReward } from "@/api/system.js"; import { useUserStore } from "@/stores/user"; import NavBar from "@/components/NavBar/NavBar.vue"; +let videoAd = null; + const userStore = useUserStore(); const loginPopupRef = ref(null); @@ -186,6 +188,29 @@ 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) => { @@ -283,6 +308,39 @@ 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(); + if (res) { + uni.showToast({ + title: "获得50积分", + icon: "success", + }); + await userStore.fetchUserAssets(); + } + } catch (e) { + console.error("Reward claim failed", e); + uni.showToast({ title: "奖励发放失败", icon: "none" }); + } +}; + const downloadAvatar = async (item) => { trackRecord({ eventName: "avatar_download_click", @@ -312,9 +370,14 @@ const downloadAvatar = async (item) => { abilityRes?.blockType === "need_ad" && abilityRes?.message === "观看广告可继续" ) { - uni.showToast({ - title: "分享给好友即可下载", - icon: "none", + uni.showModal({ + title: "积分不足", + content: "观看广告可获得50积分,继续下载", + success: (res) => { + if (res.confirm) { + showRewardAd(); + } + }, }); return; }