From 6aab12f536ca7aebe99b61db28c8055a1b5441dd Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Tue, 26 Mar 2024 16:02:49 +0800 Subject: [PATCH] feat: first open app init --- lib/index.dart | 5 +++- .../components/change_button_roe.dart | 2 +- .../components/custom_app_bar.dart | 2 +- .../components/date_container.dart | 2 +- .../inventory_inout/components/dates.dart | 2 +- .../components/inventory_inout_info.dart | 1 + .../components/inventory_inout_page_View.dart | 2 +- .../inventory_inout/components/task_list.dart | 2 +- .../components/today_button.dart | 2 +- .../components/upper_body.dart | 2 +- .../inventory_inout_controller.dart | 4 +-- lib/screens/landing/landing.dart | 1 + lib/screens/landing/landing_controller.dart | 30 +++++++++++++++++-- .../components/category_input.dart | 2 +- .../components/date_time.dart | 2 +- .../components/description_input.dart | 2 +- .../components/illustration_list.dart | 2 +- .../components/lable_input.dart | 2 +- .../components/text_input.dart | 2 +- .../new_inventory_inout.dart | 6 ++-- .../new_inventory_inout_controller.dart | 4 +-- lib/services/app_info.service.dart | 23 +------------- lib/services/dio.service.dart | 4 +-- lib/store/auth.store.dart | 13 +++++--- lib/store/dict.store.dart | 3 ++ lib/widgets/bottom_nav_bar.dart | 4 +-- 26 files changed, 72 insertions(+), 54 deletions(-) diff --git a/lib/index.dart b/lib/index.dart index 5d54244..2b03d15 100644 --- a/lib/index.dart +++ b/lib/index.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:sk_base_mobile/config.dart'; +import 'package:sk_base_mobile/screens/landing/landing.dart'; +import 'package:sk_base_mobile/screens/login/login%20copy.dart'; import 'package:sk_base_mobile/services/storage.service.dart'; import 'package:sk_base_mobile/app_theme.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; @@ -18,6 +20,8 @@ class IndexPage extends StatelessWidget { Widget build(BuildContext context) { final isLandscape = MediaQuery.of(context).orientation == Orientation.landscape; + final isLogin = + StorageService.to.getString(CacheKeys.token, isWithUser: false) != null; return ScreenUtilInit( minTextAdapt: true, designSize: isLandscape @@ -35,7 +39,6 @@ class IndexPage extends StatelessWidget { title: GloablConfig.DOMAIN_NAME, getPages: RouteConfig.getPages, initialRoute: getInitialRoute(), - // initialRoute: RouteConfig.onboarding, debugShowCheckedModeBanner: false, builder: (_, widget) { return Obx(() => MediaQuery( diff --git a/lib/screens/inventory_inout/components/change_button_roe.dart b/lib/screens/inventory_inout/components/change_button_roe.dart index 82a698f..8af1443 100644 --- a/lib/screens/inventory_inout/components/change_button_roe.dart +++ b/lib/screens/inventory_inout/components/change_button_roe.dart @@ -8,7 +8,7 @@ import 'package:sk_base_mobile/util/screen_adaper_util.dart'; class ChangeButtonRow extends StatelessWidget { ChangeButtonRow({super.key}); - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return Padding( diff --git a/lib/screens/inventory_inout/components/custom_app_bar.dart b/lib/screens/inventory_inout/components/custom_app_bar.dart index 5b8b855..cc3241c 100644 --- a/lib/screens/inventory_inout/components/custom_app_bar.dart +++ b/lib/screens/inventory_inout/components/custom_app_bar.dart @@ -10,7 +10,7 @@ import 'package:sk_base_mobile/widgets/core/zt_base_date_picker.dart'; class CustomAppBar extends StatelessWidget { CustomAppBar({super.key}); - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return Padding( diff --git a/lib/screens/inventory_inout/components/date_container.dart b/lib/screens/inventory_inout/components/date_container.dart index d17fa46..d0d5a25 100644 --- a/lib/screens/inventory_inout/components/date_container.dart +++ b/lib/screens/inventory_inout/components/date_container.dart @@ -8,7 +8,7 @@ import 'dates.dart'; class DateContainer extends StatelessWidget { final int index; DateContainer({super.key, required this.index}); - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { final size = MediaQuery.sizeOf(context); diff --git a/lib/screens/inventory_inout/components/dates.dart b/lib/screens/inventory_inout/components/dates.dart index 2ed19dc..e76c508 100644 --- a/lib/screens/inventory_inout/components/dates.dart +++ b/lib/screens/inventory_inout/components/dates.dart @@ -6,7 +6,7 @@ import 'package:sk_base_mobile/util/util.dart'; class Dates extends StatelessWidget { Dates({super.key, required this.index}); final int index; - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return Column( diff --git a/lib/screens/inventory_inout/components/inventory_inout_info.dart b/lib/screens/inventory_inout/components/inventory_inout_info.dart index b7d0de0..8f99894 100644 --- a/lib/screens/inventory_inout/components/inventory_inout_info.dart +++ b/lib/screens/inventory_inout/components/inventory_inout_info.dart @@ -176,6 +176,7 @@ class InventoryInouInfoController extends GetxController { @override onReady() { + super.onReady(); getData(); } diff --git a/lib/screens/inventory_inout/components/inventory_inout_page_View.dart b/lib/screens/inventory_inout/components/inventory_inout_page_View.dart index a0f5a09..3ee4da6 100644 --- a/lib/screens/inventory_inout/components/inventory_inout_page_View.dart +++ b/lib/screens/inventory_inout/components/inventory_inout_page_View.dart @@ -5,7 +5,7 @@ import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controlle class InventoryInoutView extends StatelessWidget { InventoryInoutView({super.key}); - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return PageView( diff --git a/lib/screens/inventory_inout/components/task_list.dart b/lib/screens/inventory_inout/components/task_list.dart index 1740a97..58568b3 100644 --- a/lib/screens/inventory_inout/components/task_list.dart +++ b/lib/screens/inventory_inout/components/task_list.dart @@ -35,7 +35,7 @@ class Grid extends StatelessWidget { final int crossAsis; final double ratio; final int ind; - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); Grid( {super.key, required this.crossAsis, diff --git a/lib/screens/inventory_inout/components/today_button.dart b/lib/screens/inventory_inout/components/today_button.dart index 43356ee..f94237d 100644 --- a/lib/screens/inventory_inout/components/today_button.dart +++ b/lib/screens/inventory_inout/components/today_button.dart @@ -10,7 +10,7 @@ class TodayButton extends StatelessWidget { @override Widget build(BuildContext context) { - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); return InkWell( borderRadius: BorderRadius.circular(ScreenAdaper.sp(30)), onTap: () => controller.pageController.animateToPage(0, diff --git a/lib/screens/inventory_inout/components/upper_body.dart b/lib/screens/inventory_inout/components/upper_body.dart index 022c1cb..4722c0f 100644 --- a/lib/screens/inventory_inout/components/upper_body.dart +++ b/lib/screens/inventory_inout/components/upper_body.dart @@ -8,7 +8,7 @@ import 'package:sk_base_mobile/util/util.dart'; class UperBody extends StatelessWidget { UperBody({super.key}); - final controller = Get.put(InventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return Column( diff --git a/lib/screens/inventory_inout/inventory_inout_controller.dart b/lib/screens/inventory_inout/inventory_inout_controller.dart index 76a01c4..635be56 100644 --- a/lib/screens/inventory_inout/inventory_inout_controller.dart +++ b/lib/screens/inventory_inout/inventory_inout_controller.dart @@ -33,8 +33,8 @@ class InventoryInoutController extends GetxController { final ScrollController scrollController = ScrollController(); final daysNum = 20; @override - void onInit() { - super.onInit(); + onReady() { + super.onReady(); getData(); } diff --git a/lib/screens/landing/landing.dart b/lib/screens/landing/landing.dart index 1a5f223..4f9c0ac 100644 --- a/lib/screens/landing/landing.dart +++ b/lib/screens/landing/landing.dart @@ -13,6 +13,7 @@ class LandingPage extends StatelessWidget { @override Widget build(BuildContext context) { + printInfo(info: 'landing'); return Material( child: Stack(children: [ const BackColors(), diff --git a/lib/screens/landing/landing_controller.dart b/lib/screens/landing/landing_controller.dart index 475b594..d5ac3a2 100644 --- a/lib/screens/landing/landing_controller.dart +++ b/lib/screens/landing/landing_controller.dart @@ -1,15 +1,41 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:sk_base_mobile/models/app_bottom_nav_item.dart'; +import 'package:sk_base_mobile/screens/inventory/inventory.dart'; +import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout.dart'; +import 'package:sk_base_mobile/screens/mine/mine.dart'; +import 'package:sk_base_mobile/screens/workbench/workbench.dart'; import 'package:sk_base_mobile/services/app_info.service.dart'; class LandingController extends GetxController { RxInt currentIndex = 0.obs; RxBool showCreateBtn = true.obs; List pages = []; - + List? bottomNavItems = [ + AppBottomNavItem( + icon: Icons.home_max_outlined, + activeIcon: Icons.home_max_outlined, + label: '登记', + page: InvenotryInoutPage()), + AppBottomNavItem( + icon: Icons.inventory_outlined, + activeIcon: Icons.inventory_rounded, + label: '库存', + page: InventoryPage()), + AppBottomNavItem( + icon: Icons.widgets_outlined, + activeIcon: Icons.widgets_rounded, + label: '工作台', + page: WorkBenchPage()), + AppBottomNavItem( + icon: Icons.person_outline_outlined, + activeIcon: Icons.person, + label: '我的', + page: MinePage()), + ]; @override onInit() { super.onInit(); - pages = AppInfoService.to.bottomNavItems!.map((e) => e.page!).toList(); + pages = bottomNavItems!.map((e) => e.page!).toList(); } } diff --git a/lib/screens/new_inventory_inout/components/category_input.dart b/lib/screens/new_inventory_inout/components/category_input.dart index 545cceb..474f1ef 100644 --- a/lib/screens/new_inventory_inout/components/category_input.dart +++ b/lib/screens/new_inventory_inout/components/category_input.dart @@ -7,7 +7,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c class CategoryInput extends StatelessWidget { CategoryInput({super.key}); - final controller = Get.put(NewInventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { diff --git a/lib/screens/new_inventory_inout/components/date_time.dart b/lib/screens/new_inventory_inout/components/date_time.dart index 219541a..ff1650d 100644 --- a/lib/screens/new_inventory_inout/components/date_time.dart +++ b/lib/screens/new_inventory_inout/components/date_time.dart @@ -6,7 +6,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c class DateTimeInput extends StatelessWidget { DateTimeInput({super.key}); - final controller = Get.put(NewInventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { diff --git a/lib/screens/new_inventory_inout/components/description_input.dart b/lib/screens/new_inventory_inout/components/description_input.dart index c867a35..d6bd550 100644 --- a/lib/screens/new_inventory_inout/components/description_input.dart +++ b/lib/screens/new_inventory_inout/components/description_input.dart @@ -5,7 +5,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/components/text_input import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_controller.dart'; class DescriptionInput extends StatelessWidget { - final controller = Get.put(NewInventoryInoutController()); + final controller = Get.find(); DescriptionInput({super.key}); @override Widget build(BuildContext context) { diff --git a/lib/screens/new_inventory_inout/components/illustration_list.dart b/lib/screens/new_inventory_inout/components/illustration_list.dart index 5ea0f24..3a01553 100644 --- a/lib/screens/new_inventory_inout/components/illustration_list.dart +++ b/lib/screens/new_inventory_inout/components/illustration_list.dart @@ -6,7 +6,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c class SelectImageList extends StatelessWidget { SelectImageList({super.key}); - final controller = Get.put(NewInventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return Column( diff --git a/lib/screens/new_inventory_inout/components/lable_input.dart b/lib/screens/new_inventory_inout/components/lable_input.dart index 48b6568..7d3e05a 100644 --- a/lib/screens/new_inventory_inout/components/lable_input.dart +++ b/lib/screens/new_inventory_inout/components/lable_input.dart @@ -7,7 +7,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c class LabelInput extends StatelessWidget { LabelInput({super.key}); - final controller = Get.put(NewInventoryInoutController()); + final controller = Get.find(); @override Widget build(BuildContext context) { return Padding( diff --git a/lib/screens/new_inventory_inout/components/text_input.dart b/lib/screens/new_inventory_inout/components/text_input.dart index 38f361f..59ed851 100644 --- a/lib/screens/new_inventory_inout/components/text_input.dart +++ b/lib/screens/new_inventory_inout/components/text_input.dart @@ -14,7 +14,7 @@ class TextInputField extends StatelessWidget { required this.hint, required this.focus, required this.onTap}); - final taskController = Get.put(NewInventoryInoutController()); + final taskController = Get.find(); @override Widget build(BuildContext context) { return AnimatedContainer( diff --git a/lib/screens/new_inventory_inout/new_inventory_inout.dart b/lib/screens/new_inventory_inout/new_inventory_inout.dart index 0525534..0873f42 100644 --- a/lib/screens/new_inventory_inout/new_inventory_inout.dart +++ b/lib/screens/new_inventory_inout/new_inventory_inout.dart @@ -24,8 +24,10 @@ class NewInventoryInout extends StatelessWidget { final dictService = Get.find(); final int inOrOut; NewInventoryInout({Key? key, this.inOrOut = InventoryInOrOutEnum.In}) - : controller = Get.put(NewInventoryInoutController(inOrOut: inOrOut)), - super(key: key); + : controller = Get.find(), + super(key: key) { + controller.inOrOut = inOrOut; + } @override Widget build(BuildContext context) { diff --git a/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart b/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart index 10d9ba6..cdd1b80 100644 --- a/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart +++ b/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart @@ -16,7 +16,7 @@ import 'package:sk_base_mobile/util/snack_bar.util.dart'; class NewInventoryInoutController extends GetxController { final formKey = GlobalKey(); - final int? inOrOut; + int? inOrOut; DateTime? pickedDate; final DbHelper db = DbHelper(); RxInt selectedImage = 0.obs; @@ -28,7 +28,7 @@ class NewInventoryInoutController extends GetxController { RxString startTime = ''.obs; RxString endTime = ''.obs; RxBool loading = false.obs; - final inventoryInoutController = Get.put(InventoryInoutController()); + final inventoryInoutController = Get.find(); final label = TextEditingController().obs; final description = TextEditingController().obs; final category = TextEditingController().obs; diff --git a/lib/services/app_info.service.dart b/lib/services/app_info.service.dart index 8b1a16e..2640679 100644 --- a/lib/services/app_info.service.dart +++ b/lib/services/app_info.service.dart @@ -27,28 +27,7 @@ class AppInfoService extends GetxService { final scale = RxDouble(1.0); final isLarge = RxBool(false); final isCameraing = RxBool(false); - List? bottomNavItems = [ - AppBottomNavItem( - icon: Icons.home_max_outlined, - activeIcon: Icons.home_max_outlined, - label: '登记', - page: InvenotryInoutPage()), - AppBottomNavItem( - icon: Icons.inventory_outlined, - activeIcon: Icons.inventory_rounded, - label: '库存', - page: InventoryPage()), - AppBottomNavItem( - icon: Icons.widgets_outlined, - activeIcon: Icons.widgets_rounded, - label: '工作台', - page: WorkBenchPage()), - AppBottomNavItem( - icon: Icons.person_outline_outlined, - activeIcon: Icons.person, - label: '我的', - page: MinePage()), - ]; + Future init() async { LoggerUtil() .info("[service-appInfo] Register app-related information service"); diff --git a/lib/services/dio.service.dart b/lib/services/dio.service.dart index 1e6f2fe..6f30c2e 100644 --- a/lib/services/dio.service.dart +++ b/lib/services/dio.service.dart @@ -62,9 +62,7 @@ class DioService extends Get.GetxService { e.response?.data['message'], ); } else if (e.response?.statusCode == 401) { - await SnackBarUtil().error( - 'Your role at this season has been updated. Please log in again.', - ); + await SnackBarUtil().error('请重新登录'); // dio.lock(); LoggerUtil().error('[Service-dio] logout:${e.response}'); await AuthStore().logout(force: true); diff --git a/lib/store/auth.store.dart b/lib/store/auth.store.dart index b5fe0df..efe354f 100644 --- a/lib/store/auth.store.dart +++ b/lib/store/auth.store.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:dio/dio.dart' as Dio; import 'package:get/get.dart'; import 'package:sk_base_mobile/apis/index.dart'; +import 'package:sk_base_mobile/store/dict.store.dart'; import 'package:sk_base_mobile/util/logger_util.dart'; import 'package:sk_base_mobile/widgets/tap_to_dismiss_keyboard.dart'; import 'package:sk_base_mobile/models/auth.dart'; @@ -11,7 +12,7 @@ import 'package:sk_base_mobile/services/service.dart'; import '../constants/constants.dart'; import '../util/util.dart'; -class AuthStore extends GetxController { +class AuthStore extends GetxService { static AuthStore get to => Get.find(); final userInfo = UserInfoModel().obs; @@ -59,8 +60,10 @@ class AuthStore extends GetxController { // final response = await Api.logout(); // if (response.data != null) { LoggerUtil().info('[Store-Auth] Logout succeed.'); - Get.offAllNamed(RouteConfig.login); - // } + // 如果当前已经在login界面 不需要跳转 + if (Get.currentRoute != RouteConfig.login) { + Get.offAllNamed(RouteConfig.login); + } } catch (e) { print(e); } finally { @@ -92,7 +95,7 @@ class AuthStore extends GetxController { } await getUserInfo(); Get.offNamed(RouteConfig.home); - // getCommonInfo(); + getCommonInfo(); } } catch (e) { await SnackBarUtil().error('账号密码错误'); @@ -141,6 +144,8 @@ class AuthStore extends GetxController { Future getCommonInfo() async { await AppInfoService.to.getAppConfig(); await Future.wait([ + DictService.to.getDictTypes() + /// 依赖业务信息 // Get.putAsync(() => BlockStore().init()), ]); diff --git a/lib/store/dict.store.dart b/lib/store/dict.store.dart index bbf6dd0..ec384d3 100644 --- a/lib/store/dict.store.dart +++ b/lib/store/dict.store.dart @@ -4,6 +4,7 @@ import 'package:sk_base_mobile/constants/dict_enum.dart'; import 'package:sk_base_mobile/models/dict_item.model.dart'; import 'package:sk_base_mobile/models/dict_type.model.dart'; import 'package:sk_base_mobile/apis/index.dart'; +import 'package:sk_base_mobile/store/auth.store.dart'; import 'package:sk_base_mobile/util/logger_util.dart'; const needCachedKey = [ @@ -13,7 +14,9 @@ const needCachedKey = [ ]; class DictService extends GetxService { + static DictService get to => Get.find(); Future init() async { + if (AuthStore.to.userInfo.value.id == null) return this; await getDictTypes(); return this; } diff --git a/lib/widgets/bottom_nav_bar.dart b/lib/widgets/bottom_nav_bar.dart index 5e6ae17..0e824c1 100644 --- a/lib/widgets/bottom_nav_bar.dart +++ b/lib/widgets/bottom_nav_bar.dart @@ -35,12 +35,12 @@ class BottomNavBar extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Icon( - AppInfoService.to.bottomNavItems![index].icon, + controller.bottomNavItems![index].icon, size: ScreenAdaper.sp(40), color: color, ), AutoSizeText( - AppInfoService.to.bottomNavItems![index].label ?? '', + controller.bottomNavItems![index].label ?? '', maxLines: 1, style: TextStyle(color: color, fontSize: ScreenAdaper.sp(20)), group: autoSizeGroup,