...
parent
fb412d90e3
commit
2d0c587321
|
|
@ -9,11 +9,11 @@ class ApiService {
|
||||||
static final bool isProduct = true;
|
static final bool isProduct = true;
|
||||||
|
|
||||||
/// 登录及其他管理后台接口
|
/// 登录及其他管理后台接口
|
||||||
// static final String basePath = "http://192.168.198.8:30140";
|
static final String basePath = "https://skqhdg.porthebei.com:9007";
|
||||||
static final String basePath =
|
// static final String basePath =
|
||||||
isProduct
|
// isProduct
|
||||||
? "https://gbs-gateway.qhdsafety.com"
|
// ? "https://gbs-gateway.qhdsafety.com"
|
||||||
: "http://192.168.20.100:30140";
|
// : "http://192.168.20.100:30140";
|
||||||
|
|
||||||
|
|
||||||
/// 图片文件服务
|
/// 图片文件服务
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ import 'package:qhd_prevention/http/HttpManager.dart';
|
||||||
import 'package:qhd_prevention/services/SessionService.dart';
|
import 'package:qhd_prevention/services/SessionService.dart';
|
||||||
|
|
||||||
class AppMenuApi {
|
class AppMenuApi {
|
||||||
static Future<Map<String, dynamic>> getAppMenu() async {
|
static Future<Map<String, dynamic>> getAppMenu(Map data) async {
|
||||||
return HttpManager().request(
|
return HttpManager().request(
|
||||||
ApiService.basePath,
|
ApiService.basePath,
|
||||||
'/appmenu/appMenu/appListTree',
|
'/appmenu/appMenu/appListTree',
|
||||||
method: Method.get,
|
method: Method.get,
|
||||||
data: {
|
data: {
|
||||||
'menuAttribution': 'QINGANG_RELATED_PARTIES',
|
'menuAttribution': 'QINGANG_RELATED_PARTIES',
|
||||||
|
...data
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ class AuthApi {
|
||||||
static Future<Map<String, dynamic>> getUserData() {
|
static Future<Map<String, dynamic>> getUserData() {
|
||||||
return HttpManager().request(
|
return HttpManager().request(
|
||||||
ApiService.basePath,
|
ApiService.basePath,
|
||||||
// '/basicInfo/user/getInfo',
|
'/basicInfo/user/getInfo',
|
||||||
'/basicInfo/user/${SessionService.instance.accountId}',
|
// '/basicInfo/user/${SessionService.instance.accountId}',
|
||||||
method: Method.get,
|
method: Method.get,
|
||||||
data: {},
|
data: {},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class HomePageState extends RouteAwareState<HomePage>
|
||||||
"todoStats": "dashboard-todo-sort",
|
"todoStats": "dashboard-todo-sort",
|
||||||
"checklist": "dashboard-todo-list",
|
"checklist": "dashboard-todo-list",
|
||||||
"scan": "dashboard-scan",
|
"scan": "dashboard-scan",
|
||||||
|
"joinFirm": "dashboard-start-work",
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -419,7 +420,7 @@ class HomePageState extends RouteAwareState<HomePage>
|
||||||
|
|
||||||
final routeService = RouteService();
|
final routeService = RouteService();
|
||||||
final bool showScan = routeService.hasPerm(_modulePerms['scan']!);
|
final bool showScan = routeService.hasPerm(_modulePerms['scan']!);
|
||||||
final bool showJoin = true; // 加入企业图标始终显示(或根据业务决定)
|
final bool showJoin = routeService.hasPerm(_modulePerms['joinFirm']!);
|
||||||
|
|
||||||
final List<Widget> children = [];
|
final List<Widget> children = [];
|
||||||
if (showScan) {
|
if (showScan) {
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,24 @@ import 'dart:convert';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:qhd_prevention/common/route_service.dart';
|
import 'package:qhd_prevention/common/route_service.dart';
|
||||||
|
import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart';
|
||||||
import 'package:qhd_prevention/http/modules/appmenu_api.dart';
|
import 'package:qhd_prevention/http/modules/appmenu_api.dart';
|
||||||
import 'package:qhd_prevention/pages/badge_manager.dart';
|
import 'package:qhd_prevention/pages/badge_manager.dart';
|
||||||
import 'package:qhd_prevention/pages/home/home_page.dart';
|
import 'package:qhd_prevention/pages/home/home_page.dart';
|
||||||
import 'package:qhd_prevention/pages/my_appbar.dart';
|
import 'package:qhd_prevention/pages/my_appbar.dart';
|
||||||
import 'package:qhd_prevention/pages/notif/notif_page.dart';
|
import 'package:qhd_prevention/pages/notif/notif_page.dart';
|
||||||
|
import 'package:qhd_prevention/pages/user/login_page.dart';
|
||||||
|
import 'package:qhd_prevention/services/SessionService.dart';
|
||||||
import 'package:qhd_prevention/services/heartbeat_service.dart';
|
import 'package:qhd_prevention/services/heartbeat_service.dart';
|
||||||
import 'package:qhd_prevention/tools/tools.dart';
|
import 'package:qhd_prevention/tools/tools.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'mine/mine_page.dart';
|
import 'mine/mine_page.dart';
|
||||||
|
|
||||||
/// 用于向子树公布当前 tab 索引
|
/// 用于向子树公布当前 tab 索引
|
||||||
class CurrentTabNotifier extends InheritedWidget {
|
class CurrentTabNotifier extends InheritedWidget {
|
||||||
final int currentIndex;
|
final int currentIndex;
|
||||||
|
|
||||||
const CurrentTabNotifier({
|
const CurrentTabNotifier({
|
||||||
required this.currentIndex,
|
required this.currentIndex,
|
||||||
required Widget child,
|
required Widget child,
|
||||||
|
|
@ -68,7 +73,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
_badgeManager.initAllModules();
|
_badgeManager.initAllModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 初始化固定页面(顺序固定) — **这里保持你要求的构造不变**
|
// 初始化固定页面(顺序固定) — **这里保持你要求的构造不变**
|
||||||
_pages = <Widget>[
|
_pages = <Widget>[
|
||||||
HomePage(key: _homeKey, isChooseFirm: widget.isChooseFirm),
|
HomePage(key: _homeKey, isChooseFirm: widget.isChooseFirm),
|
||||||
|
|
@ -91,33 +95,28 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
try {
|
try {
|
||||||
Map? route;
|
Map? route;
|
||||||
// 接口获取
|
// 接口获取
|
||||||
// try {
|
|
||||||
// LoadingDialogHelper.show(message: '加载中...');
|
|
||||||
|
|
||||||
// final res = await AppMenuApi.getAppMenu();
|
|
||||||
// if (res != null && res['success'] == true && res['data'] is List) {
|
|
||||||
// route = res;
|
|
||||||
// } else {
|
|
||||||
// debugPrint('AppMenuApi.getAppMenu returned no data or failed; fallback to local assets.');
|
|
||||||
// }
|
|
||||||
// } catch (e) {
|
|
||||||
// debugPrint('AppMenuApi.getAppMenu error: $e -> fallback to local assets.');
|
|
||||||
// }
|
|
||||||
// 本地获取
|
|
||||||
try {
|
try {
|
||||||
final routeString = await loadFromAssets();
|
LoadingDialogHelper.show(message: '加载中...');
|
||||||
route = jsonDecode(routeString) as Map<String, dynamic>;
|
final roleId = SessionService.instance.roleId;
|
||||||
|
final res = await AppMenuApi.getAppMenu({'roleId': roleId});
|
||||||
|
LoadingDialogHelper.hide();
|
||||||
|
if (res['success'] == true) {
|
||||||
|
route = res;
|
||||||
|
} else {}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('loadFromAssets error: $e');
|
debugPrint(
|
||||||
|
'AppMenuApi.getAppMenu error: $e -> fallback to local assets.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
// 本地获取
|
||||||
if (route != null && route['data'] is List) {
|
// try {
|
||||||
final data = route['data'] as List<dynamic>;
|
// final routeString = await loadFromAssets();
|
||||||
|
// route = jsonDecode(routeString) as Map<String, dynamic>;
|
||||||
|
// } catch (e) {
|
||||||
|
// debugPrint('loadFromAssets error: $e');
|
||||||
|
// }
|
||||||
|
final data = route?['data'] ?? [];
|
||||||
RouteService().initializeRoutes(data);
|
RouteService().initializeRoutes(data);
|
||||||
// initializeRoutes 内部会 notifyListeners -> _onRoutesUpdated 被调用
|
|
||||||
} else {
|
|
||||||
debugPrint('No valid route data to initialize RouteService.');
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('获取路由配置失败: $e');
|
debugPrint('获取路由配置失败: $e');
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -145,6 +144,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
// 使用 mainTabs,如果为空(尚未有路由或后端返回空),保持当前 _tabVisibility(即不自动显示)
|
// 使用 mainTabs,如果为空(尚未有路由或后端返回空),保持当前 _tabVisibility(即不自动显示)
|
||||||
final mainTabs = routeService.mainTabs;
|
final mainTabs = routeService.mainTabs;
|
||||||
if (mainTabs.isEmpty) {
|
if (mainTabs.isEmpty) {
|
||||||
|
_showErrorDialog();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,10 +157,10 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
if (!homeVisible && perms == 'dashboard' && m.visible) {
|
if (!homeVisible && perms == 'dashboard' && m.visible) {
|
||||||
homeVisible = true;
|
homeVisible = true;
|
||||||
}
|
}
|
||||||
if (!notifVisible && perms == 'notice'&& m.visible) {
|
if (!notifVisible && perms == 'notice' && m.visible) {
|
||||||
notifVisible = true;
|
notifVisible = true;
|
||||||
}
|
}
|
||||||
if (!mineVisible && perms == 'my-center'&& m.visible) {
|
if (!mineVisible && perms == 'my-center' && m.visible) {
|
||||||
mineVisible = true;
|
mineVisible = true;
|
||||||
}
|
}
|
||||||
if (homeVisible && notifVisible && mineVisible) break;
|
if (homeVisible && notifVisible && mineVisible) break;
|
||||||
|
|
@ -168,7 +168,11 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
|
|
||||||
// 后端未匹配到就隐藏(不兜底)
|
// 后端未匹配到就隐藏(不兜底)
|
||||||
setState(() {
|
setState(() {
|
||||||
_tabVisibility = [homeVisible, widget.isChooseFirm ? notifVisible : false, mineVisible];
|
_tabVisibility = [
|
||||||
|
homeVisible,
|
||||||
|
widget.isChooseFirm ? notifVisible : false,
|
||||||
|
mineVisible,
|
||||||
|
];
|
||||||
|
|
||||||
// 若当前激活的 tab 被隐藏,则切换到第一个可见 tab(若没有可见 tab,则保持当前索引为 0)
|
// 若当前激活的 tab 被隐藏,则切换到第一个可见 tab(若没有可见 tab,则保持当前索引为 0)
|
||||||
if (!_isIndexVisible(_currentIndex)) {
|
if (!_isIndexVisible(_currentIndex)) {
|
||||||
|
|
@ -176,6 +180,31 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
_currentIndex = first;
|
_currentIndex = first;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!homeVisible && !notifVisible && !mineVisible) {
|
||||||
|
_showErrorDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _showErrorDialog() async {
|
||||||
|
final confirmed = await CustomAlertDialog.showConfirm(
|
||||||
|
context,
|
||||||
|
title: '温馨提示',
|
||||||
|
content: '暂无登录权限,请联系管理员授权!',
|
||||||
|
force: true,
|
||||||
|
);
|
||||||
|
if (confirmed) {
|
||||||
|
// 清除用户登录状态
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.remove('isLoggedIn');
|
||||||
|
// 清理 SessionService 中的内容(如果你需要)
|
||||||
|
SessionService.instance.clear();
|
||||||
|
// 跳转到登录页并清除所有历史路由
|
||||||
|
Navigator.pushAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => LoginPage()),
|
||||||
|
(Route<dynamic> route) => false, // 移除所有历史路由
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回第一个可见 tab 的索引;如果没有可见项,返回给定的 fallback(默认0)
|
// 返回第一个可见 tab 的索引;如果没有可见项,返回给定的 fallback(默认0)
|
||||||
|
|
@ -292,33 +321,63 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
if (_tabVisibility[i]) {
|
if (_tabVisibility[i]) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
visibleItems.add(BottomNavigationBarItem(
|
visibleItems.add(
|
||||||
icon: Image.asset('assets/tabbar/basics.png', width: 24, height: 24),
|
BottomNavigationBarItem(
|
||||||
activeIcon: Image.asset('assets/tabbar/basics_cur.png', width: 24, height: 24),
|
icon: Image.asset(
|
||||||
|
'assets/tabbar/basics.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
|
activeIcon: Image.asset(
|
||||||
|
'assets/tabbar/basics_cur.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
label: '首页',
|
label: '首页',
|
||||||
));
|
),
|
||||||
|
);
|
||||||
visiblePages.add(_pages[i]);
|
visiblePages.add(_pages[i]);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
visibleItems.add(BottomNavigationBarItem(
|
visibleItems.add(
|
||||||
|
BottomNavigationBarItem(
|
||||||
icon: _buildIconWithBadge(
|
icon: _buildIconWithBadge(
|
||||||
icon: Image.asset('assets/tabbar/works.png', width: 24, height: 24),
|
icon: Image.asset(
|
||||||
|
'assets/tabbar/works.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
badgeCount: bm.notifCount,
|
badgeCount: bm.notifCount,
|
||||||
),
|
),
|
||||||
activeIcon: _buildIconWithBadge(
|
activeIcon: _buildIconWithBadge(
|
||||||
icon: Image.asset('assets/tabbar/works_cur.png', width: 24, height: 24),
|
icon: Image.asset(
|
||||||
|
'assets/tabbar/works_cur.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
badgeCount: bm.notifCount,
|
badgeCount: bm.notifCount,
|
||||||
),
|
),
|
||||||
label: '通知',
|
label: '通知',
|
||||||
));
|
),
|
||||||
|
);
|
||||||
visiblePages.add(_pages[i]);
|
visiblePages.add(_pages[i]);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
visibleItems.add(BottomNavigationBarItem(
|
visibleItems.add(
|
||||||
icon: Image.asset('assets/tabbar/my.png', width: 24, height: 24),
|
BottomNavigationBarItem(
|
||||||
activeIcon: Image.asset('assets/tabbar/my_cur.png', width: 24, height: 24),
|
icon: Image.asset(
|
||||||
|
'assets/tabbar/my.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
|
activeIcon: Image.asset(
|
||||||
|
'assets/tabbar/my_cur.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
label: '我的',
|
label: '我的',
|
||||||
));
|
),
|
||||||
|
);
|
||||||
visiblePages.add(_pages[i]);
|
visiblePages.add(_pages[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -329,7 +388,10 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
final bool hasVisiblePages = visiblePages.isNotEmpty;
|
final bool hasVisiblePages = visiblePages.isNotEmpty;
|
||||||
|
|
||||||
// 将当前索引映射到可见Tab的索引(用于 IndexedStack/BottomNavigationBar)
|
// 将当前索引映射到可见Tab的索引(用于 IndexedStack/BottomNavigationBar)
|
||||||
final visibleCurrentIndex = _originalToVisibleIndex(_currentIndex, _tabVisibility);
|
final visibleCurrentIndex = _originalToVisibleIndex(
|
||||||
|
_currentIndex,
|
||||||
|
_tabVisibility,
|
||||||
|
);
|
||||||
|
|
||||||
// ---------- 关键:根据 visibleItems 个数选择底栏渲染方式 ----------
|
// ---------- 关键:根据 visibleItems 个数选择底栏渲染方式 ----------
|
||||||
Widget? bottomBarWidget;
|
Widget? bottomBarWidget;
|
||||||
|
|
@ -341,7 +403,10 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
selectedItemColor: Colors.blue,
|
selectedItemColor: Colors.blue,
|
||||||
unselectedItemColor: Colors.grey,
|
unselectedItemColor: Colors.grey,
|
||||||
onTap: (visibleIndex) {
|
onTap: (visibleIndex) {
|
||||||
final originalIndex = _visibleToOriginalIndex(visibleIndex, _tabVisibility);
|
final originalIndex = _visibleToOriginalIndex(
|
||||||
|
visibleIndex,
|
||||||
|
_tabVisibility,
|
||||||
|
);
|
||||||
setState(() => _currentIndex = originalIndex);
|
setState(() => _currentIndex = originalIndex);
|
||||||
},
|
},
|
||||||
items: visibleItems,
|
items: visibleItems,
|
||||||
|
|
@ -349,11 +414,17 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
} else if (visibleItems.length == 1) {
|
} else if (visibleItems.length == 1) {
|
||||||
// 自定义单个 tab 底栏(避免 BottomNavigationBar 的断言)
|
// 自定义单个 tab 底栏(避免 BottomNavigationBar 的断言)
|
||||||
final single = visibleItems[0];
|
final single = visibleItems[0];
|
||||||
final singleVisibleOriginalIndex = _visibleToOriginalIndex(0, _tabVisibility);
|
final singleVisibleOriginalIndex = _visibleToOriginalIndex(
|
||||||
|
0,
|
||||||
|
_tabVisibility,
|
||||||
|
);
|
||||||
final isSelected = _currentIndex == singleVisibleOriginalIndex;
|
final isSelected = _currentIndex == singleVisibleOriginalIndex;
|
||||||
|
|
||||||
// 取选中或未选中的 icon 小部件
|
// 取选中或未选中的 icon 小部件
|
||||||
final Widget iconWidget = isSelected && single.activeIcon != null ? single.activeIcon! : single.icon;
|
final Widget iconWidget =
|
||||||
|
isSelected && single.activeIcon != null
|
||||||
|
? single.activeIcon!
|
||||||
|
: single.icon;
|
||||||
|
|
||||||
bottomBarWidget = Material(
|
bottomBarWidget = Material(
|
||||||
elevation: 8,
|
elevation: 8,
|
||||||
|
|
@ -400,7 +471,8 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
currentIndex: _currentIndex,
|
currentIndex: _currentIndex,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: null,
|
appBar: null,
|
||||||
body: hasVisiblePages
|
body:
|
||||||
|
hasVisiblePages
|
||||||
? IndexedStack(
|
? IndexedStack(
|
||||||
index: visibleCurrentIndex,
|
index: visibleCurrentIndex,
|
||||||
children: visiblePages,
|
children: visiblePages,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import 'package:qhd_prevention/common/route_model.dart';
|
||||||
|
|
||||||
class MinePage extends StatefulWidget {
|
class MinePage extends StatefulWidget {
|
||||||
const MinePage({super.key, required this.isChooseFirm});
|
const MinePage({super.key, required this.isChooseFirm});
|
||||||
|
|
||||||
final bool isChooseFirm;
|
final bool isChooseFirm;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -63,7 +64,7 @@ class MinePageState extends State<MinePage> {
|
||||||
'title': '扫码入职',
|
'title': '扫码入职',
|
||||||
'icon': 'assets/images/ico10.png',
|
'icon': 'assets/images/ico10.png',
|
||||||
// 如果你希望扫码入职也受后端控制,可以保留下面 perm;否则置空 []
|
// 如果你希望扫码入职也受后端控制,可以保留下面 perm;否则置空 []
|
||||||
'perms': ['dashboard-scan'],
|
'perms': ['my-center-Scan-Code-Onboarding'],
|
||||||
'action': 'scanOnboarding',
|
'action': 'scanOnboarding',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -130,7 +131,9 @@ class MinePageState extends State<MinePage> {
|
||||||
RouteService().addListener(_onRouteServiceUpdated);
|
RouteService().addListener(_onRouteServiceUpdated);
|
||||||
|
|
||||||
// 尝试立即应用(如果 route 已加载)
|
// 尝试立即应用(如果 route 已加载)
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _updateVisibilityFromRoute());
|
WidgetsBinding.instance.addPostFrameCallback(
|
||||||
|
(_) => _updateVisibilityFromRoute(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -189,20 +192,27 @@ class MinePageState extends State<MinePage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户信息(保持原逻辑)
|
// 获取用户信息
|
||||||
Future<void> _getUserInfo() async {
|
Future<void> _getUserInfo() async {
|
||||||
final res = await BasicInfoApi.getUserMessage(
|
|
||||||
'${SessionService.instance.accountId}',
|
|
||||||
);
|
|
||||||
if (res['success'] == true) {
|
|
||||||
final data = res['data'] as Map<String, dynamic>;
|
|
||||||
SessionService.instance.updateFromApiResponse(data);
|
|
||||||
await SessionService.instance.saveToPrefs();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
name = SessionService.instance.userData?.name ?? "登录/注册";
|
name = SessionService.instance.userData?.name ?? "登录/注册";
|
||||||
phone = SessionService.instance.userData?.phone ?? "";
|
phone = SessionService.instance.userData?.phone ?? "";
|
||||||
});
|
});
|
||||||
}
|
// final accountId =
|
||||||
|
// SessionService.instance.accountId ??
|
||||||
|
// SessionService.instance.userData?.id ??
|
||||||
|
// SessionService.instance.userData?.accountId ??
|
||||||
|
// '';
|
||||||
|
// final res = await BasicInfoApi.getUserMessage(accountId);
|
||||||
|
// if (res['success'] == true) {
|
||||||
|
// final data = res['data'] as Map<String, dynamic>;
|
||||||
|
// SessionService.instance.updateFromApiResponse(data);
|
||||||
|
// await SessionService.instance.saveToPrefs();
|
||||||
|
// setState(() {
|
||||||
|
// name = SessionService.instance.userData?.name ?? "登录/注册";
|
||||||
|
// phone = SessionService.instance.userData?.phone ?? "";
|
||||||
|
// });
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _logout() async {
|
Future<void> _logout() async {
|
||||||
|
|
@ -232,15 +242,14 @@ class MinePageState extends State<MinePage> {
|
||||||
title: '手机号:${SessionService.instance.phone}',
|
title: '手机号:${SessionService.instance.phone}',
|
||||||
onGetCode: () async {
|
onGetCode: () async {
|
||||||
LoadingDialogHelper.show();
|
LoadingDialogHelper.show();
|
||||||
final res = await BasicInfoApi.sendRegisterSms({
|
final res = await BasicInfoApi.sendRegisterSms({'phone': phone});
|
||||||
'phone': phone,
|
|
||||||
});
|
|
||||||
LoadingDialogHelper.dismiss();
|
LoadingDialogHelper.dismiss();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
onConfirm: (code) async {
|
onConfirm: (code) async {
|
||||||
_quit(code);
|
_quit(code);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -252,10 +261,7 @@ class MinePageState extends State<MinePage> {
|
||||||
// 离职
|
// 离职
|
||||||
Future<void> _quit(String code) async {
|
Future<void> _quit(String code) async {
|
||||||
LoadingDialogHelper.show();
|
LoadingDialogHelper.show();
|
||||||
Map data = {
|
Map data = {'id': SessionService.instance.accountId, 'phoneCode': code};
|
||||||
'id': SessionService.instance.accountId,
|
|
||||||
'phoneCode': code,
|
|
||||||
};
|
|
||||||
await BasicInfoApi.logout(data).then((res) async {
|
await BasicInfoApi.logout(data).then((res) async {
|
||||||
LoadingDialogHelper.dismiss();
|
LoadingDialogHelper.dismiss();
|
||||||
if (res['success'] == true) {
|
if (res['success'] == true) {
|
||||||
|
|
@ -343,18 +349,31 @@ class MinePageState extends State<MinePage> {
|
||||||
void _onSettingTapAction(String action) async {
|
void _onSettingTapAction(String action) async {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'userinfo':
|
case 'userinfo':
|
||||||
await pushPage(FullUserinfoPage(isEidt: false, isChooseFirm: true), context);
|
await pushPage(
|
||||||
|
FullUserinfoPage(isEidt: false, isChooseFirm: true),
|
||||||
|
context,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'changePwd':
|
case 'changePwd':
|
||||||
await pushPage(MineSetPwdPage('0'), context);
|
await pushPage(MineSetPwdPage('0'), context);
|
||||||
break;
|
break;
|
||||||
case 'scanOnboarding':
|
case 'scanOnboarding':
|
||||||
final result = await pushPage(ScanPage(type: ScanType.Onboarding), context);
|
final result = await pushPage(
|
||||||
|
ScanPage(type: ScanType.Onboarding),
|
||||||
|
context,
|
||||||
|
);
|
||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
pushPage(OnboardingFullPage(scanData: result), context);
|
pushPage(OnboardingFullPage(scanData: result), context);
|
||||||
break;
|
break;
|
||||||
case 'face':
|
case 'face':
|
||||||
pushPage(const FaceRecognitionPage(studentId: '', data: {}, mode: FaceMode.setUpdata), context);
|
pushPage(
|
||||||
|
const FaceRecognitionPage(
|
||||||
|
studentId: '',
|
||||||
|
data: {},
|
||||||
|
mode: FaceMode.setUpdata,
|
||||||
|
),
|
||||||
|
context,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'certificate':
|
case 'certificate':
|
||||||
pushPage(const CertificateListPage(), context);
|
pushPage(const CertificateListPage(), context);
|
||||||
|
|
@ -392,12 +411,14 @@ class MinePageState extends State<MinePage> {
|
||||||
// 只在 isChooseFirm 为 true 时显示
|
// 只在 isChooseFirm 为 true 时显示
|
||||||
if (title == '切换账户' && !widget.isChooseFirm) continue;
|
if (title == '切换账户' && !widget.isChooseFirm) continue;
|
||||||
|
|
||||||
children.add(_buildSettingItem(
|
children.add(
|
||||||
|
_buildSettingItem(
|
||||||
title: title,
|
title: title,
|
||||||
icon: item['icon'] as String,
|
icon: item['icon'] as String,
|
||||||
value: false,
|
value: false,
|
||||||
onChanged: (_) => _onSettingTapAction(item['action'] as String),
|
onChanged: (_) => _onSettingTapAction(item['action'] as String),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|
@ -414,21 +435,28 @@ class MinePageState extends State<MinePage> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(children: children),
|
||||||
children: children,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
RouteModel? showLogot = RouteService().findRouteByPerm('my-center-Logout');
|
||||||
|
bool showLogout = showLogot?.showFlag == 1;
|
||||||
|
|
||||||
final double headerHeight = 300.0;
|
final double headerHeight = 300.0;
|
||||||
final double overlap = 100.0;
|
final double overlap = 100.0;
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: MediaQuery.of(context).size.height,
|
height: MediaQuery.of(context).size.height,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
Positioned(top: 0, left: 0, right: 0, height: headerHeight, child: _buildHeaderSection()),
|
Positioned(
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
height: headerHeight,
|
||||||
|
child: _buildHeaderSection(),
|
||||||
|
),
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: NotificationListener<OverscrollIndicatorNotification>(
|
child: NotificationListener<OverscrollIndicatorNotification>(
|
||||||
onNotification: (overscroll) {
|
onNotification: (overscroll) {
|
||||||
|
|
@ -436,10 +464,16 @@ class MinePageState extends State<MinePage> {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: EdgeInsets.only(top: headerHeight - overlap, bottom: 24, left: 0, right: 0),
|
padding: EdgeInsets.only(
|
||||||
|
top: headerHeight - overlap,
|
||||||
|
bottom: 24,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
),
|
||||||
children: [
|
children: [
|
||||||
_buildSettingsList(),
|
_buildSettingsList(),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
|
if (showLogout)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: CustomButton(
|
child: CustomButton(
|
||||||
|
|
@ -455,7 +489,9 @@ class MinePageState extends State<MinePage> {
|
||||||
await _clearUserSession();
|
await _clearUserSession();
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const LoginPage()),
|
MaterialPageRoute(
|
||||||
|
builder: (context) => const LoginPage(),
|
||||||
|
),
|
||||||
(Route<dynamic> route) => false,
|
(Route<dynamic> route) => false,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -488,7 +524,11 @@ class MinePageState extends State<MinePage> {
|
||||||
top: 51,
|
top: 51,
|
||||||
child: Text(
|
child: Text(
|
||||||
"我的",
|
"我的",
|
||||||
style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_buildSloganSection(),
|
_buildSloganSection(),
|
||||||
|
|
|
||||||
|
|
@ -395,6 +395,8 @@ class SessionService {
|
||||||
|
|
||||||
// ---------- convenience setters ----------
|
// ---------- convenience setters ----------
|
||||||
void setToken(String t) => token = t;
|
void setToken(String t) => token = t;
|
||||||
|
// void setRoleId(String t) => roleId = t;
|
||||||
|
|
||||||
void setName(String t) => name = t;
|
void setName(String t) => name = t;
|
||||||
|
|
||||||
void setLoginPhone(String phone) => loginPhone = phone;
|
void setLoginPhone(String phone) => loginPhone = phone;
|
||||||
|
|
@ -408,6 +410,8 @@ class SessionService {
|
||||||
print('姓名: ${userData!.name}');
|
print('姓名: ${userData!.name}');
|
||||||
print('部门: ${userData!.departmentName}');
|
print('部门: ${userData!.departmentName}');
|
||||||
print('租户ID: ${userData!.tenantId}');
|
print('租户ID: ${userData!.tenantId}');
|
||||||
|
print('Account ID: ${userData!.id}');
|
||||||
|
|
||||||
// printLongString(text)
|
// printLongString(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,14 @@ class AuthService {
|
||||||
};
|
};
|
||||||
return AuthService.gbsLogin(username, password, data);
|
return AuthService.gbsLogin(username, password, data);
|
||||||
} else if (firmList.length > 1) {
|
} else if (firmList.length > 1) {
|
||||||
|
// 多个企业 也没有缓存过登录的企业
|
||||||
|
return {
|
||||||
|
'isChooseFirm': false,
|
||||||
|
'isInfoComplete': isInfoComplete,
|
||||||
|
'firmList': firmList,
|
||||||
|
'userName': username,
|
||||||
|
'password': password,
|
||||||
|
};
|
||||||
// 如果入职多个
|
// 如果入职多个
|
||||||
if (StorageService.instance.getString('key.saveJoinFirmInfo') != null) {
|
if (StorageService.instance.getString('key.saveJoinFirmInfo') != null) {
|
||||||
// 有缓存的登录过的企业,并且这个企业在登录返回的企业列表中
|
// 有缓存的登录过的企业,并且这个企业在登录返回的企业列表中
|
||||||
|
|
@ -124,14 +132,14 @@ class AuthService {
|
||||||
final success = result['success'] as bool;
|
final success = result['success'] as bool;
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Fluttertoast.showToast(msg: result['errMessage'] ?? '');
|
Fluttertoast.showToast(msg: result['errMessage'] ?? '');
|
||||||
return result;
|
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
printLongString('token:${jsonEncode(result['data']['token'])}');
|
printLongString('token:${jsonEncode(result['data']['token'])}');
|
||||||
final data = result['data'] as Map<String, dynamic>;
|
final data = result['data'] as Map<String, dynamic>;
|
||||||
final token = data['token'] ?? '';
|
final token = data['token'] ?? '';
|
||||||
SessionService.instance.setToken(token);
|
SessionService.instance.setToken(token);
|
||||||
|
// SessionService.instance.setRo(token);
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setString(_keyUser, json.encode(data));
|
await prefs.setString(_keyUser, json.encode(data));
|
||||||
await prefs.setStringList(_keyRemember, [username, password]);
|
await prefs.setStringList(_keyRemember, [username, password]);
|
||||||
|
|
@ -156,6 +164,8 @@ class AuthService {
|
||||||
SessionService.instance.printUserInfo();
|
SessionService.instance.printUserInfo();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return result;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoadingDialogHelper.hide();
|
LoadingDialogHelper.hide();
|
||||||
Fluttertoast.showToast(msg: '用户信息获取失败,请重试');
|
Fluttertoast.showToast(msg: '用户信息获取失败,请重试');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue