解决了用户不同账户退出登录后一些数据滞留到最新账户下的缓存问题,保证了使用的正确性。
This commit is contained in:
@@ -16,6 +16,9 @@ import '../../../../core/storage/user_storage.dart';
|
|||||||
import '../../../devices/domain/usecases/get_user_device_usecase.dart';
|
import '../../../devices/domain/usecases/get_user_device_usecase.dart';
|
||||||
import '../../../devices/domain/usecases/switch_device_usecase.dart';
|
import '../../../devices/domain/usecases/switch_device_usecase.dart';
|
||||||
import '../../../devices/presentation/bloc/devices_cubit.dart';
|
import '../../../devices/presentation/bloc/devices_cubit.dart';
|
||||||
|
import '../../../devices/presentation/bloc/device_status_bloc.dart';
|
||||||
|
import '../../../devices/presentation/bloc/device_status_event.dart';
|
||||||
|
import '../../../devices/presentation/bloc/devices_state.dart';
|
||||||
import '../../data/datasources/auth_tcp_datasource.dart';
|
import '../../data/datasources/auth_tcp_datasource.dart';
|
||||||
import '../../data/datasources/impl/auth_tcp_datasource_impl.dart';
|
import '../../data/datasources/impl/auth_tcp_datasource_impl.dart';
|
||||||
import 'auth_state.dart';
|
import 'auth_state.dart';
|
||||||
@@ -76,12 +79,40 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
/// 退出登录 (主动或被动)
|
/// 退出登录 (主动或被动)
|
||||||
Future<void> logout() async {
|
Future<void> logout() async {
|
||||||
//print("退出登录");
|
//print("退出登录");
|
||||||
|
|
||||||
|
// 🔥 关键修复:在断开TCP前,先清空所有业务状态,避免重连触发旧数据
|
||||||
|
_clearAllBusinessState();
|
||||||
|
|
||||||
await storage.deleteUser();
|
await storage.deleteUser();
|
||||||
tcp.disconnect();
|
tcp.disconnect();
|
||||||
appCubit.clearAuth();
|
appCubit.clearAuth();
|
||||||
emit(AuthUnauthenticated());
|
emit(AuthUnauthenticated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 🔥 新增:清空所有业务状态,防止数据泄露到新账户
|
||||||
|
void _clearAllBusinessState() {
|
||||||
|
try {
|
||||||
|
final devicesCubit = GetIt.I<DevicesCubit>();
|
||||||
|
final deviceStatusBloc = GetIt.I<DeviceStatusBloc>();
|
||||||
|
|
||||||
|
// 1. 清空设备列表和选中设备
|
||||||
|
devicesCubit.emit(const DevicesState());
|
||||||
|
debugPrint('✅ [AUTH] 已清空 DevicesCubit 状态');
|
||||||
|
_logger.logWithLevel('✅ [AUTH] 已清空 DevicesCubit 状态');
|
||||||
|
|
||||||
|
// 2. 清空设备实时状态
|
||||||
|
deviceStatusBloc.add(DeviceStatusReset());
|
||||||
|
debugPrint('✅ [AUTH] 已重置 DeviceStatusBloc 状态');
|
||||||
|
_logger.logWithLevel('✅ [AUTH] 已重置 DeviceStatusBloc 状态');
|
||||||
|
|
||||||
|
debugPrint('✅ [AUTH] 所有业务状态已清空');
|
||||||
|
_logger.logWithLevel('✅ [AUTH] 所有业务状态已清空');
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('❌ [AUTH] 清空业务状态失败: $e');
|
||||||
|
_logger.logWithLevel('❌ [AUTH] 清空业务状态失败: $e', level: 'ERROR');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// TCP 指令监听
|
/// TCP 指令监听
|
||||||
// void _listenToAuthResponse() {
|
// void _listenToAuthResponse() {
|
||||||
// print('>>> [AUTH] begin指令监听: ');
|
// print('>>> [AUTH] begin指令监听: ');
|
||||||
|
|||||||
Reference in New Issue
Block a user