You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

62 lines
1.7 KiB

// 路由拦截服务
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<T?> toWithAuth<T>(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<T?> toWithRole<T>(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<T?> toWithVIP<T>(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<bool> _checkAuth() async {
// if (!AuthService.to.isLoggedIn.value) {
// final result = await Get.to(() => LoginPage());
// return result == true;
// }
// return true;
// }
}