401增加节流
This commit is contained in:
22
ln_jq_app/lib/common/AuthGuard.dart
Normal file
22
ln_jq_app/lib/common/AuthGuard.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:getx_scaffold/common/index.dart';
|
||||
import 'package:ln_jq_app/pages/login/view.dart';
|
||||
import 'package:ln_jq_app/storage_service.dart';
|
||||
|
||||
class AuthGuard {
|
||||
static bool _handling401 = false;
|
||||
|
||||
static Future<void> handle401(String? message) async {
|
||||
if (_handling401) return;
|
||||
_handling401 = true;
|
||||
|
||||
try {
|
||||
await StorageService.to.clearLoginInfo();
|
||||
Get.offAll(() => const LoginPage());
|
||||
} finally {
|
||||
// 防止意外卡死,可视情况是否延迟重置
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
_handling401 = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user