Commit b5abe691 authored by 张宏's avatar 张宏

777777777777

parent 95cd69f5
...@@ -135,28 +135,11 @@ class _MyAppState extends State<MyApp> { ...@@ -135,28 +135,11 @@ class _MyAppState extends State<MyApp> {
} }
_endInitializing(); _endInitializing();
} else { } else {
// 无 Token,执行静默登录 // 无 Token,直接结束初始化
await _performSilentLogin(); _endInitializing();
}
}
/// 静默登录核心逻辑:使用预设账号自动登录
Future<void> _silentLogin() async {
try {
await _authService.login('13800000001', '111111');
// 登录成功,获取用户信息
_authBloc.add(const AuthFetchUserInfo());
} catch (e) {
// 静默登录失败,不做任何处理
} }
} }
/// 启动时的静默登录,登录完成后结束初始化状态
Future<void> _performSilentLogin() async {
await _silentLogin();
_endInitializing();
}
void _endInitializing() { void _endInitializing() {
if (mounted) { if (mounted) {
setState(() { setState(() {
...@@ -207,20 +190,20 @@ class _MyAppState extends State<MyApp> { ...@@ -207,20 +190,20 @@ class _MyAppState extends State<MyApp> {
], ],
child: MultiBlocListener( child: MultiBlocListener(
listeners: [ listeners: [
// AuthBloc 监听器 - 处理登录/Token 过期/登出 // // AuthBloc 监听器 - 处理登录/Token 过期/登出
BlocListener<AuthBloc, AuthState>( // BlocListener<AuthBloc, AuthState>(
listener: (context, state) { // listener: (context, state) {
if (state is AuthSuccess) { // if (state is AuthSuccess) {
_appRouter.replaceAll([const DefaultLayoutRoute()]); // _appRouter.replaceAll([const DefaultLayoutRoute()]);
} // }
if (state is AuthTokenExpired) { // if (state is AuthTokenExpired) {
_silentLogin(); // _silentLogin();
} // }
if (state is AuthLoggedOut) { // if (state is AuthLoggedOut) {
_silentLogin(); // _silentLogin();
} // }
}, // },
), // ),
// 未来在这里添加其他 Bloc 的监听器: // 未来在这里添加其他 Bloc 的监听器:
// BlocListener<UserBloc, UserState>(listener: ...), // BlocListener<UserBloc, UserState>(listener: ...),
// BlocListener<SettingsBloc, SettingsState>(listener: ...), // BlocListener<SettingsBloc, SettingsState>(listener: ...),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment