基础组件库
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

150 рядки
4.5 KiB

  1. import 'dart:convert';
  2. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  3. import 'package:zhiying_comm/zhiying_comm.dart';
  4. // 应用配置信息
  5. class AppConfigModel {
  6. // 应用配置的key
  7. AppConfigKeyModel keys;
  8. // 引导页
  9. AppConfigGuideModel guideImage;
  10. static AppConfigModel _config;
  11. AppConfigModel({this.keys, this.guideImage});
  12. static AppConfigModel getConfig() => _config;
  13. static Future<AppConfigModel> init({bool isGetCache = false}) async {
  14. try {
  15. String cacheData = await SharedPreferencesUtil.getStringValue(GlobalConfig.GUIDE, defaultVal: '1');
  16. if (isGetCache && cacheData != '1') {
  17. _config = AppConfigModel.fromJson(Map<String, dynamic>.from(json.decode(cacheData)));
  18. Logger.debug('基础设置初始化');
  19. NetUtil.request('/api/v1/app/guide', onSuccess: (data) {
  20. print(data);
  21. var cacheString = json.encode(data);
  22. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, cacheString);
  23. });
  24. return _config;
  25. } else {
  26. Map result = await NetUtil.post('/api/v1/app/guide', method: NetMethod.GET);
  27. var data = result['data'];
  28. _config = AppConfigModel.fromJson(Map<String, dynamic>.from(data));
  29. Logger.debug('基础设置初始化');
  30. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, json.encode(data));
  31. return _config;
  32. }
  33. } catch (err) {
  34. Logger.error(err);
  35. return null;
  36. }
  37. }
  38. AppConfigModel.fromJson(Map<String, dynamic> json) {
  39. keys = json['keys'] != null ? new AppConfigKeyModel.fromJson(json['keys']) : null;
  40. guideImage = json['guide_image'] != null ? new AppConfigGuideModel.fromJson(json['guide_image']) : null;
  41. }
  42. Map<String, dynamic> toJson() {
  43. final Map<String, dynamic> data = new Map<String, dynamic>();
  44. if (this.keys != null) {
  45. data['keys'] = this.keys.toJson();
  46. }
  47. if (this.guideImage != null) {
  48. data['guide_image'] = this.guideImage.toJson();
  49. }
  50. return data;
  51. }
  52. }
  53. class AppConfigKeyModel {
  54. AppConfigKeyItemModel weibo;
  55. AppConfigKeyItemModel qq;
  56. AppConfigKeyItemModel weixin;
  57. AppConfigKeyItemModel jdIos;
  58. AppConfigKeyItemModel jdAndroid;
  59. AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid});
  60. AppConfigKeyModel.fromJson(Map<String, dynamic> json) {
  61. weibo = json['weibo'] != null ? new AppConfigKeyItemModel.fromJson(json['weibo']) : null;
  62. qq = json['qq'] != null ? new AppConfigKeyItemModel.fromJson(json['qq']) : null;
  63. weixin = json['weixin'] != null ? new AppConfigKeyItemModel.fromJson(json['weixin']) : null;
  64. jdIos = json['jd_ios'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_ios']) : null;
  65. jdAndroid = json['jd_android'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_android']) : null;
  66. }
  67. Map<String, dynamic> toJson() {
  68. final Map<String, dynamic> data = new Map<String, dynamic>();
  69. if (this.weibo != null) {
  70. data['weibo'] = this.weibo.toJson();
  71. }
  72. if (this.qq != null) {
  73. data['qq'] = this.qq.toJson();
  74. }
  75. if (this.weixin != null) {
  76. data['weixin'] = this.weixin.toJson();
  77. }
  78. if (this.jdIos != null) {
  79. data['jd_ios'] = this.jdIos.toJson();
  80. }
  81. if (this.jdAndroid != null) {
  82. data['jd_android'] = this.jdAndroid.toJson();
  83. }
  84. return data;
  85. }
  86. }
  87. class AppConfigKeyItemModel {
  88. String appId;
  89. String appkey;
  90. String secret;
  91. String redirectUrl;
  92. String universalLink;
  93. AppConfigKeyItemModel({this.appkey, this.secret, this.redirectUrl});
  94. AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
  95. appId = json['app_id'];
  96. appkey = json['appkey'];
  97. secret = json['secret'];
  98. redirectUrl = json['redirect_url'];
  99. universalLink = json['universal_link'];
  100. }
  101. Map<String, dynamic> toJson() {
  102. final Map<String, dynamic> data = new Map<String, dynamic>();
  103. data['app_id'] = this.appId;
  104. data['appkey'] = this.appkey;
  105. data['secret'] = this.secret;
  106. data['redirect_url'] = this.redirectUrl;
  107. data['universal_link'] = this.universalLink;
  108. return data;
  109. }
  110. }
  111. class AppConfigGuideModel {
  112. String isShowIndicator;
  113. List<String> images;
  114. AppConfigGuideModel({this.isShowIndicator, this.images});
  115. AppConfigGuideModel.fromJson(Map<String, dynamic> json) {
  116. isShowIndicator = json['is_show_indicator'];
  117. images = json['images'].cast<String>();
  118. }
  119. Map<String, dynamic> toJson() {
  120. final Map<String, dynamic> data = new Map<String, dynamic>();
  121. data['is_show_indicator'] = this.isShowIndicator;
  122. data['images'] = this.images;
  123. return data;
  124. }
  125. }