fix: ability

This commit is contained in:
zzc
2026-03-04 12:35:59 +08:00
parent b39ac7cb24
commit d15012841c
6 changed files with 90 additions and 106 deletions

View File

@@ -2,7 +2,7 @@ import { request } from "@/utils/request.js";
export const abilityCheck = async (scene) => { export const abilityCheck = async (scene) => {
return request({ return request({
url: "/api/blessing/ability/check?scene=" + scene, url: "/api/ability/check?scene=" + scene,
method: "GET", method: "GET",
}); });
}; };

View File

@@ -116,7 +116,8 @@ 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, watchAdReward } from "@/api/system.js"; import { getShareReward, watchAdReward } from "@/api/system.js";
import { checkAbilityAndHandle } from "@/utils/ability.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";
import RewardAd from "@/components/RewardAd/RewardAd.vue"; import RewardAd from "@/components/RewardAd/RewardAd.vue";
@@ -313,41 +314,11 @@ const downloadAvatar = async (item) => {
return; return;
} }
// Use avatar specific ability check if exists, otherwise reuse generic or skip? const canProceed = await checkAbilityAndHandle(
// Assuming 'avatar_download' ability check exists or similar "avatar_download",
const abilityRes = await abilityCheck("avatar_download"); rewardAdRef,
if (!abilityRes.canUse) { );
if ( if (!canProceed) return;
abilityRes?.blockType === "need_share" &&
abilityRes?.message === "分享可继续"
) {
uni.showToast({
title: "分享给好友即可下载",
icon: "none",
});
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",
});
return;
}
uni.showLoading({ title: "下载中..." }); uni.showLoading({ title: "下载中..." });
try { try {

View File

@@ -272,7 +272,7 @@
</view> </view>
<view class="rule-item"> <view class="rule-item">
<uni-icons type="calendar-filled" size="18" color="#ff9800" /> <uni-icons type="calendar-filled" size="18" color="#ff9800" />
<text class="rule-text">每日签到+40积分</text> <text class="rule-text">每日签到+20积分</text>
</view> </view>
<view class="rule-item"> <view class="rule-item">
<uni-icons type="videocam-filled" size="18" color="#ff9800" /> <uni-icons type="videocam-filled" size="18" color="#ff9800" />

View File

@@ -115,7 +115,8 @@ import {
trackRecord, trackRecord,
} from "@/utils/common.js"; } from "@/utils/common.js";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import { abilityCheck, watchAdReward } from "@/api/system.js"; import { watchAdReward } from "@/api/system.js";
import { checkAbilityAndHandle } from "@/utils/ability.js";
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue"; import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
import RewardAd from "@/components/RewardAd/RewardAd.vue"; import RewardAd from "@/components/RewardAd/RewardAd.vue";
@@ -287,39 +288,11 @@ const downloadWallpaper = async () => {
return; return;
} }
const abilityRes = await abilityCheck("wallpaper_download"); const canProceed = await checkAbilityAndHandle(
if (!abilityRes.canUse) { "wallpaper_download",
if ( rewardAdRef,
abilityRes?.blockType === "need_share" && );
abilityRes?.message === "分享可继续" if (!canProceed) return;
) {
uni.showToast({
title: "分享给好友即可下载",
icon: "none",
});
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",
});
return;
}
uni.showLoading({ title: "下载中..." }); uni.showLoading({ title: "下载中..." });
try { try {

View File

@@ -104,7 +104,8 @@ 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, watchAdReward } from "@/api/system.js"; import { getShareReward, watchAdReward } from "@/api/system.js";
import { checkAbilityAndHandle } from "@/utils/ability.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";
@@ -303,39 +304,11 @@ const downloadWallpaper = async (item) => {
return; return;
} }
const abilityRes = await abilityCheck("wallpaper_download"); const canProceed = await checkAbilityAndHandle(
if (!abilityRes.canUse) { "wallpaper_download",
if ( rewardAdRef,
abilityRes?.blockType === "need_share" && );
abilityRes?.message === "分享可继续" if (!canProceed) return;
) {
uni.showToast({
title: "分享给好友即可下载",
icon: "none",
});
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",
});
return;
}
uni.showLoading({ title: "下载中..." }); uni.showLoading({ title: "下载中..." });
try { try {

67
utils/ability.js Normal file
View File

@@ -0,0 +1,67 @@
import { abilityCheck } from "@/api/system";
/**
* Checks if a user has the ability to perform an action (e.g., download).
* Handles common blocking scenarios like "need_share" or "need_ad".
*
* @param {string} scene - The scene identifier for the ability check (e.g., "wallpaper_download").
* @param {Object} rewardAdRef - The ref to the RewardAd component (must have a .value.show() method or be the instance itself).
* @returns {Promise<boolean>} - Returns true if the action can proceed, false otherwise.
*/
export const checkAbilityAndHandle = async (scene, rewardAdRef) => {
try {
const abilityRes = await abilityCheck(scene);
if (abilityRes.canUse) {
return true;
}
if (
abilityRes?.blockType === "need_share" &&
abilityRes?.message === "分享可继续"
) {
uni.showToast({
title: "分享给好友即可下载",
icon: "none",
});
return false;
}
if (
abilityRes?.blockType === "need_ad" &&
abilityRes?.message === "观看广告可继续"
) {
uni.showModal({
title: "积分不足",
content: "观看广告可获得50积分继续下载",
success: (res) => {
if (res.confirm) {
// Check if rewardAdRef is a ref (has .value) or the component instance itself
if (
rewardAdRef &&
rewardAdRef.value &&
typeof rewardAdRef.value.show === "function"
) {
rewardAdRef.value.show();
} else if (rewardAdRef && typeof rewardAdRef.show === "function") {
rewardAdRef.show();
} else {
console.error("RewardAd component reference is invalid");
uni.showToast({ title: "广告加载失败", icon: "none" });
}
}
},
});
return false;
}
uni.showToast({
title: "您今日下载次数已用完,明日再试",
icon: "none",
});
return false;
} catch (e) {
console.error("Ability check failed", e);
uni.showToast({ title: "系统繁忙,请稍后重试", icon: "none" });
return false;
}
};