fix: point exp
This commit is contained in:
@@ -81,3 +81,10 @@ export const createTracking = async (data) => {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const watchAdReward = async () => {
|
||||||
|
return request({
|
||||||
|
url: "/api/blessing/ad/reward",
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -115,10 +115,12 @@ import {
|
|||||||
saveViewRequest,
|
saveViewRequest,
|
||||||
} from "@/utils/common.js";
|
} from "@/utils/common.js";
|
||||||
import { onShareAppMessage, onShareTimeline, onLoad } from "@dcloudio/uni-app";
|
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 { useUserStore } from "@/stores/user";
|
||||||
import NavBar from "@/components/NavBar/NavBar.vue";
|
import NavBar from "@/components/NavBar/NavBar.vue";
|
||||||
|
|
||||||
|
let videoAd = null;
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const loginPopupRef = ref(null);
|
const loginPopupRef = ref(null);
|
||||||
|
|
||||||
@@ -186,6 +188,29 @@ onLoad((options) => {
|
|||||||
eventName: "avatar_download_page_visit",
|
eventName: "avatar_download_page_visit",
|
||||||
eventType: `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) => {
|
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) => {
|
const downloadAvatar = async (item) => {
|
||||||
trackRecord({
|
trackRecord({
|
||||||
eventName: "avatar_download_click",
|
eventName: "avatar_download_click",
|
||||||
@@ -312,9 +370,14 @@ const downloadAvatar = async (item) => {
|
|||||||
abilityRes?.blockType === "need_ad" &&
|
abilityRes?.blockType === "need_ad" &&
|
||||||
abilityRes?.message === "观看广告可继续"
|
abilityRes?.message === "观看广告可继续"
|
||||||
) {
|
) {
|
||||||
uni.showToast({
|
uni.showModal({
|
||||||
title: "分享给好友即可下载",
|
title: "积分不足",
|
||||||
icon: "none",
|
content: "观看广告可获得50积分,继续下载",
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
showRewardAd();
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user