From 8cd94f9c87ff6fc949cf5e4ca08c1504f966c493 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Sat, 6 Dec 2025 15:27:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(account):=20=E5=9C=A8=E7=99=BB=E5=87=BA?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E7=90=86=E7=94=A8=E6=88=B7=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加User.clearUserSession()调用以确保用户登出时完全清理会话数据 同时在蓝牙管理器中增加登录状态检查,防止未登录时跳转配对页面 --- lib/data/services/account_service.dart | 3 +++ lib/data/services/bluetooth_manager.dart | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/data/services/account_service.dart b/lib/data/services/account_service.dart index c2c9748bd..1293ecec5 100644 --- a/lib/data/services/account_service.dart +++ b/lib/data/services/account_service.dart @@ -7,6 +7,7 @@ import '../../modules/login/controllers/facebookLogin.dart'; import '../services/network/api.dart'; import 'db/database_helper.dart'; import 'meeting/meeting_task_service.dart'; +import '../../data/models/user_Info.dart'; /// 账号管理服务 /// @@ -33,6 +34,7 @@ class AccountService extends GetxService { await _storage.write("logintoken", null); await _storage.write("user_info", null); await _storage.write("local_avatar", null); + User.clearUserSession(); logger.d('用户数据清理成功'); return true; } catch (e) { @@ -45,6 +47,7 @@ class AccountService extends GetxService { // 清理所有用户数据 try { await _storage.erase(); + User.clearUserSession(); logger.d('所有用户数据清理成功'); return true; } catch (e) { diff --git a/lib/data/services/bluetooth_manager.dart b/lib/data/services/bluetooth_manager.dart index ee28c94fa..7075fa3d4 100644 --- a/lib/data/services/bluetooth_manager.dart +++ b/lib/data/services/bluetooth_manager.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:get/get.dart'; import 'package:classic_bluetooth/classic_bluetooth.dart'; +import 'package:get_storage/get_storage.dart'; import '../../core/utils/logger.dart'; import '../../routes/app_routes.dart'; import 'ble_manager.dart'; @@ -21,6 +22,7 @@ class BluetoothManager extends GetxService { final Rx currentDeviceRx = Rx(null); BluetoothDevice? get currentDevice => currentDeviceRx.value; final BleManager _bleManager = Get.find(); + final GetStorage _storage = GetStorage(); // 订阅 StreamSubscription? _bluetoothSubscription; @@ -76,7 +78,8 @@ class BluetoothManager extends GetxService { currentDeviceRx.value = newDevice; // 检查当前是否在OTA升级界面,如果是则不跳转 - if (!_isInOtaUpgradePage() && + if (_isLoggedIn() && + !_isInOtaUpgradePage() && !_bleManager.isConnected && Get.currentRoute != Routes.pairing) { Get.toNamed(Routes.pairing, arguments: newDevice); @@ -161,4 +164,14 @@ class BluetoothManager extends GetxService { return false; } } + + /// 是否已登录 + bool _isLoggedIn() { + try { + final token = _storage.read('logintoken'); + return token != null && token is String && token.isNotEmpty; + } catch (e) { + return false; + } + } }