Compare commits

...

2 Commits

Author SHA1 Message Date
imeepos d6fba57afc style: 移除app.css中的Tailwind CSS导入
- 移除@tailwind base、components、utilities导入语句
- 保持基础应用样式配置
2025-09-09 12:10:16 +08:00
imeepos c845ad2102 fix: 优化广告平台适配和下载流程
- 新增平台检测:仅ByteDance平台支持广告功能
- 修复非广告平台用户体验:跳过广告直接下载,避免重复提示
- 优化useAd钩子:非支持平台直接触发奖励回调
- 改进handleDownloadImages:增加skipAdCheck参数绕过广告状态检查
- 提升用户体验:简化提示文案,调整交互延时
2025-09-09 12:09:44 +08:00
3 changed files with 99 additions and 77 deletions

View File

@ -1,8 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
#app{
width: 100vw;
height: 100vh;

View File

@ -17,16 +17,28 @@ interface UseAdOptions {
onReward?: AdRewardCallback; // 观看完整广告后的奖励回调
onClose?: (isEnded: boolean) => void; // 广告关闭回调,传入是否完整观看
}
// 创建平台广告实例
const factory = createPlatformFactory()
export function useAd(options?: UseAdOptions): UseAdReturn {
const [loading, setLoading] = useState(true);
const [adAvailable, setAdAvailable] = useState(false);
const adRef = useRef<RewardedVideoAd | null>(null);
const platform = factory.getPlatform()
// 检查当前平台是否支持广告
const isAdSupportedPlatform = platform === 'bytedance';
useEffect(() => {
// 如果当前平台不支持广告,直接设置为不可用状态
if (!isAdSupportedPlatform) {
console.log(`当前平台 ${platform} 未开通广告,跳过广告初始化`);
setAdAvailable(false);
setLoading(false);
return;
}
try {
// 创建平台广告实例
const factory = createPlatformFactory()
adRef.current = factory.createRewardedVideoAd();
const ad = adRef.current!;
@ -112,14 +124,23 @@ export function useAd(options?: UseAdOptions): UseAdReturn {
setLoading(false);
return () => { }; // 返回空的清理函数
}
}, [options]);
}, [options, isAdSupportedPlatform, platform]);
// 显示广告方法
const showAd = useCallback(() => {
// 如果当前平台不支持广告,直接给予奖励并触发关闭回调
if (!isAdSupportedPlatform) {
console.log(`当前平台 ${platform} 未开通广告,直接给予奖励`);
options?.onReward?.();
options?.onClose?.(true); // 模拟广告播放完成
return;
}
if (!adAvailable) {
console.warn('广告不可用,跳过广告播放');
// 如果广告不可用,直接给予奖励
options?.onReward?.();
options?.onClose?.(true); // 模拟广告播放完成
return;
}
@ -132,17 +153,24 @@ export function useAd(options?: UseAdOptions): UseAdReturn {
setLoading(false);
// 如果显示失败,也给予奖励作为降级处理
options?.onReward?.();
options?.onClose?.(true); // 模拟广告播放完成
}
}
}, [adAvailable, options]);
}, [adAvailable, options, isAdSupportedPlatform, platform]);
// 加载广告方法
const loadAd = useCallback(() => {
// 如果当前平台不支持广告,直接跳过加载
if (!isAdSupportedPlatform) {
console.log(`当前平台 ${platform} 未开通广告,跳过广告加载`);
return;
}
if (adRef.current) {
setLoading(true);
adRef.current.load();
}
}, []);
}, [isAdSupportedPlatform, platform]);
return {
showAd,

View File

@ -70,14 +70,13 @@ const ResultPage: React.FC = () => {
} else if (!adAvailable) {
// 广告不可用(如流量主未开通),直接允许下载
showToast({
title: '已为您跳过广告,直接下载',
title: '已为您跳过广告',
icon: 'success',
duration: 2000
duration: 1500
})
setHasWatchedAd(true) // 标记为已"观看",允许下载
setTimeout(() => {
handleDownloadImages()
}, 500)
handleDownloadImages(true) // 跳过广告检查,直接下载
}, 800)
} else {
// 还没观看广告,先播放广告
showAd()
@ -85,8 +84,8 @@ const ResultPage: React.FC = () => {
}
// 下载图片到本地相册
const handleDownloadImages = async () => {
if (!hasWatchedAd) {
const handleDownloadImages = async (skipAdCheck: boolean = false) => {
if (!skipAdCheck && !hasWatchedAd) {
showToast({
title: '请先观看广告',
icon: 'none',