基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

86 lines
2.8 KiB

  1. import 'dart:io';
  2. import 'dart:convert';
  3. import 'package:zhiying_comm/util/net_util.dart';
  4. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  5. import 'package:zhiying_comm/zhiying_comm.dart';
  6. class BaseSettingModel {
  7. String fileProvider;
  8. String fileBucketHost;
  9. String fileBucketHostProtocol;
  10. String isIosReview;
  11. Map<String, dynamic> tab;
  12. static BaseSettingModel _setting;
  13. static BaseSettingModel get setting {
  14. if (_setting == null) {
  15. Logger.error('暂未初始化');
  16. }
  17. return _setting;
  18. }
  19. BaseSettingModel({this.fileProvider, this.fileBucketHost, this.fileBucketHostProtocol});
  20. BaseSettingModel.fromJson(Map<String, dynamic> json) {
  21. fileProvider = json['file_provider'];
  22. fileBucketHost = json['file_bucket_host'];
  23. fileBucketHostProtocol = json['file_bucket_host_protocol'];
  24. isIosReview = json['is_ios_review']?.toString();
  25. tab = Map<String, dynamic>.from(json['bottom_nav']);
  26. }
  27. Map<String, dynamic> toJson() {
  28. final Map<String, dynamic> data = new Map<String, dynamic>();
  29. data['file_provider'] = this.fileProvider;
  30. data['file_bucket_host'] = this.fileBucketHost;
  31. data['file_bucket_host_protocol'] = this.fileBucketHostProtocol;
  32. data['bottom_nav'] = this.tab;
  33. data['is_ios_review'] = this.isIosReview;
  34. return data;
  35. }
  36. static Future<BaseSettingModel> init({bool isGetCache}) async {
  37. try {
  38. ///判断是否获取缓存
  39. String configData = await SharedPreferencesUtil.getStringValue(GlobalConfig.MAIN_CONFIG, defaultVal: '1');
  40. if (isGetCache != null && isGetCache && configData != "1") {
  41. createBaseSet(json.decode(configData));
  42. Logger.debug('基础设置初始化');
  43. NetUtil.request('/api/v1/new/config.json',onSuccess: (data){
  44. print(data);
  45. var cacheString=json.encode(data);
  46. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.MAIN_CONFIG, cacheString);
  47. });
  48. return _setting;
  49. } else {
  50. Map result =
  51. await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET);
  52. var data = result['data'];
  53. var cacheString=json.encode(data);
  54. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.MAIN_CONFIG, cacheString);
  55. createBaseSet(data);
  56. return _setting;
  57. }
  58. } catch (err) {
  59. Logger.error(err);
  60. }
  61. return null;
  62. }
  63. static createBaseSet(dynamic data){
  64. _setting = BaseSettingModel.fromJson(Map<String, dynamic>.from(data));
  65. if (Platform.isIOS) {
  66. if (null != setting && _setting.isIosReview == '1') {
  67. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1');
  68. } else {
  69. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0');
  70. }
  71. }
  72. Logger.debug('基础设置初始化');
  73. }
  74. }