controller.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import 'package:get/get.dart';
  2. import 'package:vitalapp/architecture/defines.dart';
  3. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  4. import 'package:vitalapp/managers/interfaces/account.dart';
  5. import 'package:vitalapp/rpc.dart';
  6. import 'package:vitalapp/store/store.dart';
  7. import 'state.dart';
  8. class SettingsController extends FControllerBase {
  9. final state = SettingsState();
  10. void onSubmit() async {
  11. try {
  12. final uri = Uri.parse(state.gateway);
  13. rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == 'https');
  14. rpc.clearCache();
  15. PromptBox.success("保存成功");
  16. } catch (e) {
  17. PromptBox.error("保存失败");
  18. }
  19. }
  20. /// 登出
  21. Future<void> logOut() async {
  22. final result = await Get.find<IAccountManager>().logout();
  23. if (result) {
  24. Store.user.currentSelectPatientInfo = null;
  25. Get.offAllNamed("/login");
  26. }
  27. }
  28. @override
  29. void onInit() {
  30. state.gateway = rpc.currentHostAddress;
  31. state.version = "2.0.0";
  32. super.onInit();
  33. }
  34. @override
  35. void onReady() {
  36. //
  37. super.onReady();
  38. }
  39. @override
  40. void onClose() {
  41. _doDispose();
  42. super.onClose();
  43. }
  44. void _doDispose() {}
  45. }