import 'dart:collection'; import 'package:get/get.dart'; import 'package:vitalapp/architecture/app_parameters.dart'; import 'package:vitalapp/architecture/defines.dart'; import 'package:vitalapp/architecture/utils/prompt_box.dart'; import '../defines.dart'; class AppState extends StateModuleBase { final _busy = false.obs; final _serverOptions = [].obs; final _serverUrl = AppParameters.data.serverGateway.obs; final _homePageUrl = AppParameters.data.homePageUrl.obs; final _enableEncryptSensitiveInfo = false.obs; /// 程序处理是否忙碌中 bool get busy => _busy.value; set busy(bool v) { _busy.value = v; if (v) { PromptBox.loading("加载中..."); } else { PromptBox.dismiss(); } } /// 服务地址选项 List get serverOptions => UnmodifiableListView(_serverOptions); set serverOptions(List v) => _serverOptions.value = v; /// 服务地址 String get serverUrl => _serverUrl.value; set serverUrl(String v) => _serverUrl.updateValue(v); /// 首页地址 String get homePageUrl => _homePageUrl.value; set homePageUrl(String v) => _homePageUrl.updateValue(v); /// 启用敏感信息脱敏 bool get enableEncryptSensitiveInfo => _enableEncryptSensitiveInfo.value; set enableEncryptSensitiveInfo(bool v) => _enableEncryptSensitiveInfo.updateValue(v); void setBusy(String text) { _busy.value = true; PromptBox.loading(text); } void cancelBusy() => busy = false; @override Future acceptPersistenceJson(Map map) async { map.pickPersistentProp('serverUrl', (x) => serverUrl = x); map.pickPersistentProp('homePageUrl', (x) => homePageUrl = x); map.pickPersistentProp('serverOptions', (x) { if (x != null) { serverOptions = (x as List).map((e) => e as String).toList(); } final arr = [...serverOptions]; if (!arr.contains(serverUrl)) { arr.insert(0, serverUrl); } if (!arr.contains(AppParameters.data.serverGateway)) { arr.insert(0, AppParameters.data.serverGateway); } serverOptions = arr; }); } @override Map toPersistenceJson() { return { "serverUrl": serverUrl, "homePageUrl": homePageUrl, "serverOptions": serverOptions, }; } }