7 changed files with 122 additions and 32 deletions
Split View
Diff Options
-
9lib/controller/mine/auth_controller.dart
-
21lib/controller/mine/user_controller.dart
-
62lib/extension/router_service.dart
-
50lib/model/mine/user_data.dart
-
3lib/pages/main/main_page.dart
-
6lib/pages/mine/auth_center_page.dart
-
3lib/pages/mine/mine_page.dart
@ -0,0 +1,62 @@ |
|||
// 路由拦截服务 |
|||
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.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; |
|||
// } |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save