app.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'dart:collection';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/architecture/app_parameters.dart';
  4. import 'package:vitalapp/architecture/defines.dart';
  5. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  6. import '../defines.dart';
  7. class AppState extends StateModuleBase {
  8. final _busy = false.obs;
  9. final _serverOptions = <String>[].obs;
  10. final _serverUrl = AppParameters.data.serverGateway.obs;
  11. final _homePageUrl = AppParameters.data.homePageUrl.obs;
  12. final _enableEncryptSensitiveInfo = false.obs;
  13. /// 程序处理是否忙碌中
  14. bool get busy => _busy.value;
  15. set busy(bool v) {
  16. _busy.value = v;
  17. if (v) {
  18. PromptBox.loading("加载中...");
  19. } else {
  20. PromptBox.dismiss();
  21. }
  22. }
  23. /// 服务地址选项
  24. List<String> get serverOptions => UnmodifiableListView(_serverOptions);
  25. set serverOptions(List<String> v) => _serverOptions.value = v;
  26. /// 服务地址
  27. String get serverUrl => _serverUrl.value;
  28. set serverUrl(String v) => _serverUrl.updateValue(v);
  29. /// 首页地址
  30. String get homePageUrl => _homePageUrl.value;
  31. set homePageUrl(String v) => _homePageUrl.updateValue(v);
  32. /// 启用敏感信息脱敏
  33. bool get enableEncryptSensitiveInfo => _enableEncryptSensitiveInfo.value;
  34. set enableEncryptSensitiveInfo(bool v) =>
  35. _enableEncryptSensitiveInfo.updateValue(v);
  36. void setBusy(String text) {
  37. _busy.value = true;
  38. PromptBox.loading(text);
  39. }
  40. void cancelBusy() => busy = false;
  41. @override
  42. Future<void> acceptPersistenceJson(Map<String, dynamic> map) async {
  43. map.pickPersistentProp('serverUrl', (x) => serverUrl = x);
  44. map.pickPersistentProp('homePageUrl', (x) => homePageUrl = x);
  45. map.pickPersistentProp('serverOptions', (x) {
  46. if (x != null) {
  47. serverOptions = (x as List).map((e) => e as String).toList();
  48. }
  49. final arr = [...serverOptions];
  50. if (!arr.contains(serverUrl)) {
  51. arr.insert(0, serverUrl);
  52. }
  53. if (!arr.contains(AppParameters.data.serverGateway)) {
  54. arr.insert(0, AppParameters.data.serverGateway);
  55. }
  56. serverOptions = arr;
  57. });
  58. }
  59. @override
  60. Map<String, dynamic> toPersistenceJson() {
  61. return {
  62. "serverUrl": serverUrl,
  63. "homePageUrl": homePageUrl,
  64. "serverOptions": serverOptions,
  65. };
  66. }
  67. }