feat(vip): 实现VIP服务权限控制和食物识别功能限制
- 添加VIP服务权限检查hook,支持免费使用次数限制 - 为食物识别功能添加登录验证和VIP权限检查 - 优化RevenueCat用户标识同步逻辑 - 修复会员购买状态检查的类型安全问题 - 为营养成分分析添加登录验证
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { HeaderBar } from '@/components/ui/HeaderBar';
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { useMembershipModal } from '@/contexts/MembershipModalContext';
|
||||
import { useAppDispatch } from '@/hooks/redux';
|
||||
import { useAuthGuard } from '@/hooks/useAuthGuard';
|
||||
import { useCosUpload } from '@/hooks/useCosUpload';
|
||||
import { useSafeAreaTop } from '@/hooks/useSafeAreaWithPadding';
|
||||
import { useVipService } from '@/hooks/useVipService';
|
||||
import { recognizeFood } from '@/services/foodRecognition';
|
||||
import { saveRecognitionResult, setError, setLoading } from '@/store/foodRecognitionSlice';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
@@ -37,6 +40,11 @@ export default function FoodRecognitionScreen() {
|
||||
const [currentStep, setCurrentStep] = useState<'idle' | 'uploading' | 'recognizing' | 'completed' | 'failed'>('idle');
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
// 添加认证和VIP服务相关hooks
|
||||
const { ensureLoggedIn } = useAuthGuard();
|
||||
const { handleServiceAccess } = useVipService();
|
||||
const { openMembershipModal } = useMembershipModal();
|
||||
|
||||
// 动画引用
|
||||
const scaleAnim = useRef(new Animated.Value(1)).current;
|
||||
const fadeAnim = useRef(new Animated.Value(0)).current;
|
||||
@@ -125,6 +133,28 @@ export default function FoodRecognitionScreen() {
|
||||
})
|
||||
]).start();
|
||||
|
||||
// 先验证登录状态
|
||||
const isLoggedIn = await ensureLoggedIn();
|
||||
if (!isLoggedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查用户是否可以使用 AI 食物识别功能
|
||||
const canAccess = handleServiceAccess(
|
||||
() => {
|
||||
// 允许使用,继续执行识别流程
|
||||
},
|
||||
() => {
|
||||
// 不允许使用,显示会员付费弹窗
|
||||
openMembershipModal();
|
||||
}
|
||||
);
|
||||
|
||||
// 如果用户没有权限,直接返回
|
||||
if (!canAccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setShowRecognitionProcess(true);
|
||||
setRecognitionLogs([]);
|
||||
|
||||
Reference in New Issue
Block a user