12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import 'dart:convert';
- import 'package:fis_common/logger/logger.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/services.dart';
- /// 应用参数(随编译引入)
- class AppParameters {
- static const _path = "assets/app_params.json";
- static late final AppParameterDataModel _data;
- static bool _hasLoaded = false;
- /// 数据内容
- static AppParameterDataModel get data => _data;
- /// 加载预置参数数据
- static Future<void> load() async {
- if (_hasLoaded) return;
- try {
- final dynamic jsonMap;
- final json = await rootBundle.loadString(_path, cache: false);
- jsonMap = jsonDecode(json);
- _data = AppParameterDataModel.fromJson(jsonMap);
- } catch (e) {
- logger.e("Load AppConfig error.", e);
- _data = AppParameterDataModel();
- }
- _hasLoaded = true;
- }
- }
- class AppParameterDataModel {
- // ignore: constant_identifier_names
- static const C_DEFAULT_GATEWAY =
- "https://platform.xinglinghui.com:9400"; // TODO:
- static const C_HOME_PAGE_URL = "http://192.168.6.80:8408"; // TODO:
- static const C_LOCAL_STATION = false;
- static const C_PURE_SOFTWAREMODE = false;
- static const C_EXCEL_IMPORTURL = "https://platform.xinglinghui.com:9314";
- AppParameterDataModel({
- this.serverGateway = C_DEFAULT_GATEWAY,
- this.homePageUrl = C_HOME_PAGE_URL,
- this.isLocalStation = C_LOCAL_STATION,
- this.isPureSoftwareMode = C_PURE_SOFTWAREMODE,
- this.excelImportUrl = C_EXCEL_IMPORTURL,
- });
- factory AppParameterDataModel.fromJson(Map<String, dynamic> map) {
- final homePageUrl = map['home_page_url'] ?? C_HOME_PAGE_URL;
- final isLocalStation = map['local_station'] ?? C_LOCAL_STATION;
- final isPureSoftwareMode =
- kIsWeb && (map['pure_software_mode'] ?? C_PURE_SOFTWAREMODE);
- final serverGetway = isLocalStation
- ? map['server_local_gateway']
- : map['server_gateway'] ?? C_DEFAULT_GATEWAY;
- final excelImportUrl = map["excel_import_url"] ?? C_EXCEL_IMPORTURL;
- return AppParameterDataModel(
- serverGateway: serverGetway,
- homePageUrl: homePageUrl,
- isLocalStation: isLocalStation,
- isPureSoftwareMode: isPureSoftwareMode,
- excelImportUrl: excelImportUrl,
- );
- }
- String serverGateway;
- String homePageUrl;
- ///Excel 导入站点
- String excelImportUrl;
- ///是否本地工作站,默认false,如果设置为true,将会在App启动时轮询调用成功Server的接口才会进行登录,否则将会一直处于Splash页面
- bool isLocalStation;
- ///是否纯软件模式,目前仅在web和Windows下使用
- bool isPureSoftwareMode;
- }
|