12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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 = <String>[].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<String> get serverOptions => UnmodifiableListView(_serverOptions);
- set serverOptions(List<String> 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<void> acceptPersistenceJson(Map<String, dynamic> 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<String, dynamic> toPersistenceJson() {
- return {
- "serverUrl": serverUrl,
- "homePageUrl": homePageUrl,
- "serverOptions": serverOptions,
- };
- }
- }
|