// 路由拦截服务 import 'package:dating_touchme_app/controller/global.dart'; import 'package:get/get.dart'; import '../pages/mine/user_info_page.dart'; class RouteGuardService extends GetxService { static RouteGuardService get to => Get.find(); // 带认证检查的跳转 Future toWithAuth(dynamic page, dynamic arguments) async { bool checked = false; if (GlobalData().userData != null) { final information = GlobalData().userData!; if(information.id != null && information.id!.isNotEmpty && information.birthYear != null){ checked = true; } } if(!checked){ final result = await Get.to(() => UserInfoPage()); if (result != true) { // return null; } return null; } return Get.to(() => page, arguments: arguments); } // 带权限检查的跳转 // Future toWithRole(dynamic page, String requiredRole) async { // // 先检查登录 // if (!await _checkAuth()) return null; // // // 再检查权限 // if (!AuthService.to.hasRole(requiredRole)) { // Get.snackbar('权限不足', '需要$requiredRole权限'); // return null; // } // // return Get.to(() => page); // } // VIP 功能跳转 // Future toWithVIP(dynamic page) async { // if (!await _checkAuth()) return null; // // if (!AuthService.to.isVIP.value) { // final result = await Get.to(() => VIPPurchasePage()); // if (result != true) return null; // } // return Get.to(() => page); // } // Future _checkAuth() async { // if (!AuthService.to.isLoggedIn.value) { // final result = await Get.to(() => LoginPage()); // return result == true; // } // return true; // } }