基础库
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.

base_setting_model.dart 2.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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,s) {
  59. print(s);
  60. Logger.error(err);
  61. }
  62. return null;
  63. }
  64. static createBaseSet(dynamic data){
  65. _setting = BaseSettingModel.fromJson(Map<String, dynamic>.from(data));
  66. if (Platform.isIOS) {
  67. if (null != setting && _setting.isIosReview == '1') {
  68. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1');
  69. } else {
  70. SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0');
  71. }
  72. }
  73. Logger.debug('基础设置初始化');
  74. }
  75. }