更新
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||
import 'package:vbvs_app/controller/login/login_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/pages/device/BodyDeviceWidget.dart';
|
||||
import 'package:vbvs_app/pages/device/device_detail.dart';
|
||||
import 'package:vbvs_app/pages/device/instant_body_page.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/MobileScannerTestPage.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/bind_device_success.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/blueteeth_device_page.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/device_calibration.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/device_share_list_page.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/device_share_page.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/device_type.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/device_type_list.dart';
|
||||
@@ -12,23 +19,28 @@ import 'package:vbvs_app/pages/device_bind/wifi_page.dart';
|
||||
import 'package:vbvs_app/pages/login/login.dart';
|
||||
import 'package:vbvs_app/pages/login/other_login.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/e_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/follow_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/help_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/home_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/main_page_bottom_change.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/message_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/mine_page.dart';
|
||||
import 'package:vbvs_app/pages/person/person_page.dart';
|
||||
import 'package:vbvs_app/pages/person/update_person_page.dart';
|
||||
import 'package:vbvs_app/pages/repair/apply_repair_page.dart';
|
||||
import 'package:vbvs_app/pages/repair/repair_list_page.dart';
|
||||
import 'package:vbvs_app/pages/setting/language_setting.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/sleep_report_page.dart';
|
||||
import 'package:vbvs_app/pages/user/about_us_page.dart';
|
||||
import 'package:vbvs_app/pages/user/setting_page.dart';
|
||||
import 'package:vbvs_app/pages/user/update_user_page.dart';
|
||||
|
||||
|
||||
|
||||
ThemeController themeController = Get.find();
|
||||
|
||||
var routes = {
|
||||
"/homePage": (contxt) => HomePage(),
|
||||
"/sleepReportPage": (contxt,{arguments}) => SleepReportPage(sleepUri:arguments),
|
||||
"/sleepReportPage": (contxt, {arguments}) =>
|
||||
SleepReportPage(sleepUri: arguments),
|
||||
"/ePage": (contxt) => EPage(),
|
||||
"/messagePage": (contxt) => MessagePage(),
|
||||
"/minePage": (contxt) => MinePage(),
|
||||
@@ -45,33 +57,73 @@ var routes = {
|
||||
"/aboutUsPage": (contxt) => AboutUsPage(),
|
||||
"/bodyDevice": (contxt) => BodyDeviceWidget(),
|
||||
"/deviceTypeList": (contxt) => DeviceTypeListPage(),
|
||||
"/deviceDetail": (contxt,{arguments}) => DeviceDetailPage(device:arguments),
|
||||
"/instantBodyPage": (contxt,{arguments}) => InstantBodyPage(personInfo:arguments),
|
||||
"/deviceDetail": (contxt, {arguments}) => DeviceDetailPage(device: arguments),
|
||||
"/instantBodyPage": (contxt, {arguments}) =>
|
||||
InstantBodyPage(personInfo: arguments),
|
||||
"/qrView": (contxt) => MobileScannerTestPage(),
|
||||
"/updatePersonPage": (contxt) => UpdatePersonPage(),
|
||||
"/deviceSharePage": (contxt,{arguments}) => DeviceSharePage(device:arguments),
|
||||
"/updatePersonPage": (contxt, {arguments}) =>
|
||||
UpdatePersonPage(status: arguments),
|
||||
"/deviceSharePage": (contxt, {arguments}) =>
|
||||
DeviceSharePage(device: arguments),
|
||||
"/deviceShareListPage": (contxt, {arguments}) =>
|
||||
DeviceShareListPage(device: arguments),
|
||||
"/calibrationPage": (contxt, {arguments}) => CalibrationPage(type: arguments),
|
||||
"/applyRepairPage": (contxt) => ApplyRepairPage(),
|
||||
"/languageSetting": (contxt) => LanguageSetting(),
|
||||
"/helpPage": (contxt) => HelpPage(),
|
||||
"/followPage": (contxt) => FollowPage(),
|
||||
"/repairListPage": (contxt) => RepairListPage(),
|
||||
};
|
||||
|
||||
//2、配置onGenerateRoute 固定写法 这个方法也相当于一个中间件,这里可以做权限判断
|
||||
var onGenerateRoute = (RouteSettings settings) {
|
||||
final String? name = settings.name; // /news 或者 /search
|
||||
final Function? pageContentBuilder =
|
||||
routes[name]; // Function = (contxt) { return const NewsPage()}
|
||||
final String? name = settings.name; // 获取路由名称,如 /news 或 /search
|
||||
final Function? pageContentBuilder = routes[name]; // 根据路由名称获取对应的页面构建器
|
||||
|
||||
if (pageContentBuilder != null) {
|
||||
if (settings.arguments != null) {
|
||||
final Route route = CupertinoPageRoute(
|
||||
settings: settings,
|
||||
builder: (context) =>
|
||||
pageContentBuilder(context, arguments: settings.arguments));
|
||||
return route;
|
||||
} else {
|
||||
final Route route = CupertinoPageRoute(
|
||||
settings: settings,
|
||||
builder: (context) => pageContentBuilder(context));
|
||||
UserInfoController userInfoController = Get.find();
|
||||
int loginStatus = userInfoController.model.login!;
|
||||
|
||||
return route;
|
||||
// 检查用户是否已登录,如果未登录且路由不是登录相关页面,跳转到登录页面
|
||||
if (loginStatus != 1) {
|
||||
// 如果用户未登录且访问的不是登录页面等,展示提示并重定向
|
||||
if (settings.name != "/loginPage" &&
|
||||
settings.name != "/otherLoginPage" &&
|
||||
settings.name != "/mianPageBottomChange") {
|
||||
TopSlideNotification.show(
|
||||
Get.context!,
|
||||
text: "必须登录提示".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
|
||||
// 创建新的 RouteSettings,并修改 name 为 /loginPage
|
||||
final updatedSettings = RouteSettings(
|
||||
name: "/loginPage",
|
||||
arguments: settings.arguments,
|
||||
);
|
||||
|
||||
// 创建一个新的路由,跳转到登录页面
|
||||
return CupertinoPageRoute(
|
||||
settings: updatedSettings,
|
||||
builder: (context) => pageContentBuilder!(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有路由参数,传递参数
|
||||
if (settings.arguments != null) {
|
||||
return CupertinoPageRoute(
|
||||
settings: settings,
|
||||
builder: (context) =>
|
||||
pageContentBuilder!(context, arguments: settings.arguments),
|
||||
);
|
||||
} else {
|
||||
// 没有路由参数时,直接构建页面
|
||||
return CupertinoPageRoute(
|
||||
settings: settings,
|
||||
builder: (context) => pageContentBuilder!(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return null; // 如果路由名称没有匹配的页面,返回 null
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user