mobile_skt/lib/router/router.util.dart

39 lines
1.2 KiB
Dart
Raw Normal View History

2024-04-10 17:38:23 +08:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2024-04-12 09:56:00 +08:00
import 'package:sk_base_mobile/constants/constants.dart';
2024-04-10 17:38:23 +08:00
import 'package:sk_base_mobile/store/resource.store.dart';
import 'package:sk_base_mobile/util/snack_bar.util.dart';
class RouterUtil {
2024-04-12 09:56:00 +08:00
static List<String> hasPermissionRoute = [
RouteConfig.hrManage,
RouteConfig.inventory,
RouteConfig.saleQuotation,
];
2024-04-10 17:38:23 +08:00
static Future<T?> toNamed<T>(String routeName, {arguments}) async {
//关闭键盘
if (Get.context != null) {
FocusScope.of(Get.context!).requestFocus(FocusNode());
}
bool isExsited = ResourceService.to.resources
.firstWhereOrNull((element) => element.path == routeName) !=
null;
2024-04-12 09:56:00 +08:00
bool hasPermission = isExsited || !hasPermissionRoute.contains(routeName);
if (!hasPermission) {
2024-04-10 17:38:23 +08:00
SnackBarUtil().info('您没有权限,请联系管理员分配权限,后期将隐藏无权限的菜单');
return null;
}
2024-04-12 09:56:00 +08:00
return Get.toNamed<T?>(routeName, arguments: arguments);
}
/// 返回
static Future<void> back<T>({T? result}) async {
//关闭键盘
if (Get.context != null) {
FocusScope.of(Get.context!).requestFocus(FocusNode());
}
Get.key.currentState?.pop(result);
2024-04-10 17:38:23 +08:00
}
}