token_replaced_handler.dart 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import 'package:fis_ui/values.dart';
  2. import 'package:fis_i18n/i18n.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:fis_ui/usual/alert.dart';
  5. import 'package:flutter/foundation.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/services.dart';
  8. import 'package:flyinsono/architecture/define.dart';
  9. import 'package:flyinsono/architecture/router/index.dart';
  10. import 'package:flyinsono/architecture/services/entity/local_setting.dart';
  11. import 'package:flyinsono/architecture/states/states.dart';
  12. import 'package:flyinsono/lab/env/env.dart';
  13. import 'package:flyinsono/pages/main/home/widgets/dialog_page.dart';
  14. import 'package:flyinsono/rpc.dart';
  15. import 'package:get/get.dart';
  16. import 'package:universal_html/js.dart' as js;
  17. import 'package:fis_common/index.dart';
  18. /// 账号被挤出通知
  19. class TokenReplacedNotificationHandler
  20. extends NotificationHandler<TokenReplacedNotification> {
  21. TokenReplacedNotificationHandler()
  22. : super(NotificationTypeEnum.TokenReplacedNotification);
  23. @override
  24. void execute(TokenReplacedNotification message) {
  25. super.execute(message);
  26. if (kIsWeb) {
  27. // 关闭其他标签页
  28. js.context.callMethod("closeOtherTabs");
  29. }
  30. if (Get.context == null) return;
  31. try {
  32. Get.find<FWebviewInteractiveController>().onDialogCreate();
  33. } catch (e) {
  34. print(e);
  35. }
  36. FConfirmAlert.show(
  37. context: Get.context!,
  38. title: i18nBook.common.tip.t,
  39. subTitle: i18nBook.auth.tokenReplacedTips.t,
  40. isShowCancel: false,
  41. businessParent: FVirtualPageWidget.global,
  42. cancelLabel: i18nBook.common.cancel.t,
  43. confrimLabel: i18nBook.common.confirm.t,
  44. onConfirm: () async {
  45. if (kIsLab) {
  46. try {
  47. await Store.user.handelLogOut();
  48. } catch (e) {}
  49. Get.offNamed(RouteNames.Lab.Login);
  50. return;
  51. }
  52. try {
  53. if ((FPlatform.isWindows || FPlatform.isMacOS) &&
  54. LocalSetting.ins.isUseSecondWindow!) {
  55. rpc.platform.tokenExpired();
  56. }
  57. Get.find<FWebviewInteractiveController>().onDialogDispose();
  58. } catch (e) {
  59. print(e);
  60. }
  61. // 重新登录
  62. await Store.user.handelLogOut();
  63. Store.app.cancelBusy();
  64. /// 如果当前是横屏,切换到竖屏
  65. if (kIsMobile && Get.context!.isLandscape) {
  66. SystemChrome.setPreferredOrientations(
  67. [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  68. // 延迟1000ms,等待屏幕旋转完成
  69. await Future.delayed(Duration(milliseconds: 300));
  70. router.offAll(RouteNames.Auth.AuthBoard);
  71. } else {
  72. router.offAll(RouteNames.Auth.AuthBoard);
  73. }
  74. },
  75. );
  76. }
  77. }