fix: point exp

This commit is contained in:
zzc
2026-02-25 10:27:30 +08:00
parent 1fef1818d8
commit a6e9c1c9ce
4 changed files with 79 additions and 20 deletions

View File

@@ -82,10 +82,13 @@ export const createTracking = async (data) => {
});
};
export const watchAdReward = async () => {
export const watchAdReward = async (token) => {
return request({
url: "/api/blessing/ad/reward",
method: "POST",
data: {
rewardToken: token,
},
});
};

View File

@@ -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,7 +56,14 @@ onUnmounted(() => {
}
});
const show = () => {
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
@@ -62,13 +71,23 @@ const show = () => {
.then(() => videoAd.show())
.catch((err) => {
console.error("Ad show failed", err);
uni.showToast({ title: "广告加载失败,请稍后再试", icon: "none" });
uni.showToast({
title: "广告加载失败,请稍后再试",
icon: "none",
});
emit("onError", err);
});
});
} else {
uni.showToast({ title: "当前环境不支持广告", icon: "none" });
}
} else {
uni.showToast({ title: "广告启动失败,请稍后再试", icon: "none" });
}
} catch (e) {
console.error("watchAdStart failed", e);
uni.showToast({ title: "广告启动失败,请稍后再试", icon: "none" });
}
};
defineExpose({ show });

View File

@@ -286,9 +286,9 @@ const previewImage = (index) => {
});
};
const handleAdReward = async () => {
const handleAdReward = async (token) => {
try {
const res = await watchAdReward();
const res = await watchAdReward(token);
if (res) {
uni.showToast({
title: "获得50积分",

View File

@@ -91,6 +91,7 @@
@logind="handleLogind"
:share-token="shareToken"
/>
<RewardAd ref="rewardAdRef" @onReward="handleAdReward" />
</view>
</template>
@@ -103,16 +104,18 @@ import {
getShareToken,
} 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 { saveViewRequest, trackRecord } from "@/utils/common.js";
import NavBar from "@/components/NavBar/NavBar.vue";
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 userScore = computed(() => userStore.userInfo.score || 0);
const userScore = computed(() => userStore.userInfo.points || 0);
const downloadCost = ref(20);
const categories = ref([]);
@@ -267,6 +270,22 @@ const previewImage = (index) => {
});
};
const handleAdReward = async (token) => {
try {
const res = await watchAdReward(token);
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 downloadWallpaper = async (item) => {
trackRecord({
eventName: "wallpaper_download_click",
@@ -290,6 +309,21 @@ const downloadWallpaper = async (item) => {
});
return;
}
if (
abilityRes?.blockType === "need_ad" &&
abilityRes?.message === "观看广告可继续"
) {
uni.showModal({
title: "积分不足",
content: "观看广告可获得50积分继续下载",
success: (res) => {
if (res.confirm) {
rewardAdRef.value.show();
}
},
});
return;
}
uni.showToast({
title: "您今日壁纸下载次数已用完,明日再试",
icon: "none",
@@ -299,7 +333,10 @@ const downloadWallpaper = async (item) => {
uni.showLoading({ title: "下载中..." });
await saveRemoteImageToLocal(item.imageUrl);
saveRecordRequest("", item.id, "wallpaper_download", item.imageUrl);
await saveRecordRequest("", item.id, "wallpaper_download", item.imageUrl);
await userStore.fetchUserAssets();
uni.showToast({ title: "保存成功 消耗 20 积分", icon: "success" });
};
const shareWallpaper = (item) => {};