Browse Source

fix(account): 在登出时清理用户会话数据

添加User.clearUserSession()调用以确保用户登出时完全清理会话数据
同时在蓝牙管理器中增加登录状态检查,防止未登录时跳转配对页面
weicu
lxm 10 months ago
parent
commit
8cd94f9c87
  1. 3
      lib/data/services/account_service.dart
  2. 15
      lib/data/services/bluetooth_manager.dart

3
lib/data/services/account_service.dart

@ -7,6 +7,7 @@ import '../../modules/login/controllers/facebookLogin.dart';
import '../services/network/api.dart'; import '../services/network/api.dart';
import 'db/database_helper.dart'; import 'db/database_helper.dart';
import 'meeting/meeting_task_service.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("logintoken", null);
await _storage.write("user_info", null); await _storage.write("user_info", null);
await _storage.write("local_avatar", null); await _storage.write("local_avatar", null);
User.clearUserSession();
logger.d('用户数据清理成功'); logger.d('用户数据清理成功');
return true; return true;
} catch (e) { } catch (e) {
@ -45,6 +47,7 @@ class AccountService extends GetxService {
// 清理所有用户数据 // 清理所有用户数据
try { try {
await _storage.erase(); await _storage.erase();
User.clearUserSession();
logger.d('所有用户数据清理成功'); logger.d('所有用户数据清理成功');
return true; return true;
} catch (e) { } catch (e) {

15
lib/data/services/bluetooth_manager.dart

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:classic_bluetooth/classic_bluetooth.dart'; import 'package:classic_bluetooth/classic_bluetooth.dart';
import 'package:get_storage/get_storage.dart';
import '../../core/utils/logger.dart'; import '../../core/utils/logger.dart';
import '../../routes/app_routes.dart'; import '../../routes/app_routes.dart';
import 'ble_manager.dart'; import 'ble_manager.dart';
@ -21,6 +22,7 @@ class BluetoothManager extends GetxService {
final Rx<BluetoothDevice?> currentDeviceRx = Rx<BluetoothDevice?>(null); final Rx<BluetoothDevice?> currentDeviceRx = Rx<BluetoothDevice?>(null);
BluetoothDevice? get currentDevice => currentDeviceRx.value; BluetoothDevice? get currentDevice => currentDeviceRx.value;
final BleManager _bleManager = Get.find<BleManager>(); final BleManager _bleManager = Get.find<BleManager>();
final GetStorage _storage = GetStorage();
// 订阅 // 订阅
StreamSubscription<BluetoothEvent>? _bluetoothSubscription; StreamSubscription<BluetoothEvent>? _bluetoothSubscription;
@ -76,7 +78,8 @@ class BluetoothManager extends GetxService {
currentDeviceRx.value = newDevice; currentDeviceRx.value = newDevice;
// 检查当前是否在OTA升级界面,如果是则不跳转 // 检查当前是否在OTA升级界面,如果是则不跳转
if (!_isInOtaUpgradePage() && if (_isLoggedIn() &&
!_isInOtaUpgradePage() &&
!_bleManager.isConnected && !_bleManager.isConnected &&
Get.currentRoute != Routes.pairing) { Get.currentRoute != Routes.pairing) {
Get.toNamed(Routes.pairing, arguments: newDevice); Get.toNamed(Routes.pairing, arguments: newDevice);
@ -161,4 +164,14 @@ class BluetoothManager extends GetxService {
return false; return false;
} }
} }
/// 是否已登录
bool _isLoggedIn() {
try {
final token = _storage.read('logintoken');
return token != null && token is String && token.isNotEmpty;
} catch (e) {
return false;
}
}
} }

Loading…
Cancel
Save