123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vnoteapp/architecture/defines.dart';
- import 'package:vnoteapp/architecture/utils/common_util.dart';
- import 'package:vnoteapp/managers/interfaces/account.dart';
- import 'package:vnoteapp/pages/controllers/home_nav_mixin.dart';
- import 'package:vnoteapp/pages/home/models/menu.dart';
- import 'state.dart';
- class HomeController extends FControllerBase with HomeNavMixin {
- final state = HomeState();
- /// 当前选中路由
- int currentIndex = -1;
- /// 登出
- Future<void> logOut() async {
- final result = await Get.find<IAccountManager>().logout();
- if (result) {
- Get.offAllNamed("/login");
- }
- }
- @override
- void onInit() {
- initMenus();
- super.onInit();
- }
- /// 切换活动菜单
- void switchActiveMenu(HomeMenuItem data) {
- CommonUtil.throttle(() {
- switchNavByName(data.routeName);
- });
- // final index =
- // state.menuItems.indexWhere((e) => e.routeName == data.routeName);
- // if (index < 0) return;
- // final array = state.menuItems;
- // array.firstWhereOrNull((e) => e.isSelected)?.isSelected = false;
- // array[index].isSelected = true;
- // state.menuItems = array;
- // Get.offAllNamed(data.routeName, id: 1001);
- }
- void switchNavByName(String name) {
- final index = state.menuItems.indexWhere((e) => e.routeName == name);
- if (index < 0 || currentIndex == index) return;
- final array = state.menuItems;
- array.firstWhereOrNull((e) => e.isSelected)?.isSelected = false;
- array[index].isSelected = true;
- state.menuItems = array;
- currentIndex = index;
- Get.offAllNamed(name, id: 1001);
- }
- void initMenus() {
- state.menuItems = [
- HomeMenuItem(
- title: "主页",
- routeName: "/dashboard",
- iconData: Icons.home_outlined,
- isSelected: true,
- ),
- HomeMenuItem(
- title: "健康检测",
- routeName: "/medical",
- iconWidget: _buildImgIcon('diagnosisDisplay.png'),
- ),
- HomeMenuItem(
- title: "设置中心",
- routeName: "/settings",
- iconData: Icons.settings,
- ),
- ];
- }
- void updateMenus() {
- state.menuItems = [
- HomeMenuItem(
- title: "主页",
- routeName: "/dashboard",
- iconData: Icons.home_outlined,
- isSelected: true,
- ),
- HomeMenuItem(
- title: "健康档案",
- routeName: "/patient/detail",
- iconWidget: _buildImgIcon('healthRecord.png'),
- ),
- HomeMenuItem(
- title: "医生签约",
- routeName: "/contract/package_list",
- iconWidget: _buildImgIcon('doctorSigning.png'),
- ),
- HomeMenuItem(
- title: "健康体检",
- routeName: "/check/form",
- iconWidget: _buildImgIcon('healthCheckup.png'),
- ),
- HomeMenuItem(
- title: "人群随访",
- routeName: "/check/follow_up",
- iconWidget: _buildImgIcon('populationFollowUp.png'),
- ),
- HomeMenuItem(
- title: "健康检测",
- routeName: "/medical",
- iconWidget: _buildImgIcon('diagnosisDisplay.png'),
- ),
- HomeMenuItem(
- title: "设置中心",
- routeName: "/settings",
- iconData: Icons.settings,
- ),
- ];
- }
- Widget _buildImgIcon(String assetName) {
- return ClipRect(
- child: SizedBox(
- height: 34,
- child: Image.asset(
- "assets/images/home/$assetName",
- width: 46,
- height: 46,
- fit: BoxFit.fitWidth,
- ),
- ),
- );
- }
- }
|