40 lines
1.3 KiB
Dart
40 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:sk_base_mobile/constants/constants.dart';
|
|
import 'package:sk_base_mobile/store/resource.store.dart';
|
|
import 'package:sk_base_mobile/util/snack_bar.util.dart';
|
|
|
|
class RouterUtil {
|
|
static List<String> hasPermissionRoute = [
|
|
RouteConfig.hrManage,
|
|
RouteConfig.inventory,
|
|
RouteConfig.saleQuotation,
|
|
];
|
|
// static List<String> whiteList = [RouteConfig.saleQuotationGuide];
|
|
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;
|
|
bool hasPermission = isExsited || !hasPermissionRoute.contains(routeName);
|
|
if (!hasPermission) {
|
|
SnackBarUtil().info('您没有权限,请联系管理员分配权限,后期将隐藏无权限的菜单');
|
|
return null;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|