fix: point exp
This commit is contained in:
@@ -82,10 +82,13 @@ export const createTracking = async (data) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const watchAdReward = async () => {
|
export const watchAdReward = async (token) => {
|
||||||
return request({
|
return request({
|
||||||
url: "/api/blessing/ad/reward",
|
url: "/api/blessing/ad/reward",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
data: {
|
||||||
|
rewardToken: token,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, onUnmounted } from "vue";
|
import { onMounted, onUnmounted } from "vue";
|
||||||
|
import { watchAdStart } from "@/api/system.js";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
adUnitId: {
|
adUnitId: {
|
||||||
@@ -15,6 +16,7 @@ const props = defineProps({
|
|||||||
const emit = defineEmits(["onReward", "onError", "onClose"]);
|
const emit = defineEmits(["onReward", "onError", "onClose"]);
|
||||||
|
|
||||||
let videoAd = null;
|
let videoAd = null;
|
||||||
|
let rewardToken = "";
|
||||||
|
|
||||||
const onLoadHandler = () => {
|
const onLoadHandler = () => {
|
||||||
console.log("Ad Loaded");
|
console.log("Ad Loaded");
|
||||||
@@ -27,7 +29,7 @@ const onErrorHandler = (err) => {
|
|||||||
|
|
||||||
const onCloseHandler = (res) => {
|
const onCloseHandler = (res) => {
|
||||||
if (res && res.isEnded) {
|
if (res && res.isEnded) {
|
||||||
emit("onReward");
|
emit("onReward", rewardToken);
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: "观看完整广告才能获取奖励哦", icon: "none" });
|
uni.showToast({ title: "观看完整广告才能获取奖励哦", icon: "none" });
|
||||||
emit("onClose");
|
emit("onClose");
|
||||||
@@ -54,20 +56,37 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const show = () => {
|
const show = async () => {
|
||||||
if (videoAd) {
|
try {
|
||||||
videoAd.show().catch(() => {
|
// Step 1: Start Ad Session to get Token
|
||||||
videoAd
|
const res = await watchAdStart();
|
||||||
.load()
|
if (res && res.rewardToken) {
|
||||||
.then(() => videoAd.show())
|
rewardToken = res.rewardToken;
|
||||||
.catch((err) => {
|
|
||||||
console.error("Ad show failed", err);
|
// Step 2: Show Ad
|
||||||
uni.showToast({ title: "广告加载失败,请稍后再试", icon: "none" });
|
if (videoAd) {
|
||||||
emit("onError", err);
|
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 {
|
||||||
} else {
|
uni.showToast({ title: "当前环境不支持广告", icon: "none" });
|
||||||
uni.showToast({ title: "当前环境不支持广告", icon: "none" });
|
}
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: "广告启动失败,请稍后再试", icon: "none" });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("watchAdStart failed", e);
|
||||||
|
uni.showToast({ title: "广告启动失败,请稍后再试", icon: "none" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -286,9 +286,9 @@ const previewImage = (index) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAdReward = async () => {
|
const handleAdReward = async (token) => {
|
||||||
try {
|
try {
|
||||||
const res = await watchAdReward();
|
const res = await watchAdReward(token);
|
||||||
if (res) {
|
if (res) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "获得50积分",
|
title: "获得50积分",
|
||||||
|
|||||||
@@ -91,6 +91,7 @@
|
|||||||
@logind="handleLogind"
|
@logind="handleLogind"
|
||||||
:share-token="shareToken"
|
:share-token="shareToken"
|
||||||
/>
|
/>
|
||||||
|
<RewardAd ref="rewardAdRef" @onReward="handleAdReward" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -103,16 +104,18 @@ import {
|
|||||||
getShareToken,
|
getShareToken,
|
||||||
} 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 { saveViewRequest, trackRecord } from "@/utils/common.js";
|
import { saveViewRequest, trackRecord } from "@/utils/common.js";
|
||||||
import NavBar from "@/components/NavBar/NavBar.vue";
|
import NavBar from "@/components/NavBar/NavBar.vue";
|
||||||
|
import RewardAd from "@/components/RewardAd/RewardAd.vue";
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const loginPopupRef = ref(null);
|
const loginPopupRef = ref(null);
|
||||||
|
const rewardAdRef = ref(null);
|
||||||
|
|
||||||
const isLoggedIn = computed(() => !!userStore.userInfo.nickName);
|
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 downloadCost = ref(20);
|
||||||
|
|
||||||
const categories = ref([]);
|
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) => {
|
const downloadWallpaper = async (item) => {
|
||||||
trackRecord({
|
trackRecord({
|
||||||
eventName: "wallpaper_download_click",
|
eventName: "wallpaper_download_click",
|
||||||
@@ -290,6 +309,21 @@ const downloadWallpaper = async (item) => {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
abilityRes?.blockType === "need_ad" &&
|
||||||
|
abilityRes?.message === "观看广告可继续"
|
||||||
|
) {
|
||||||
|
uni.showModal({
|
||||||
|
title: "积分不足",
|
||||||
|
content: "观看广告可获得50积分,继续下载",
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
rewardAdRef.value.show();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "您今日壁纸下载次数已用完,明日再试",
|
title: "您今日壁纸下载次数已用完,明日再试",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
@@ -299,7 +333,10 @@ const downloadWallpaper = async (item) => {
|
|||||||
|
|
||||||
uni.showLoading({ title: "下载中..." });
|
uni.showLoading({ title: "下载中..." });
|
||||||
await saveRemoteImageToLocal(item.imageUrl);
|
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) => {};
|
const shareWallpaper = (item) => {};
|
||||||
|
|||||||
Reference in New Issue
Block a user