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

app_config_model.dart 6.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. ///新引导页参数
  11. GuideData guideData;
  12. static String appStartDelay="0.5";
  13. static AppConfigModel _config;
  14. AppConfigModel({this.keys, this.guideImage});
  15. static AppConfigModel getConfig() => _config;
  16. static Future<AppConfigModel> init({bool isGetCache = false}) async {
  17. try {
  18. String cacheData = await SharedPreferencesUtil.getStringValue(GlobalConfig.GUIDE, defaultVal: '1');
  19. if (isGetCache && cacheData != '1') {
  20. _config = AppConfigModel.fromJson(Map<String, dynamic>.from(json.decode(cacheData)));
  21. Logger.debug('基础设置初始化');
  22. NetUtil.request('/api/v1/app/guide', onSuccess: (data) {
  23. Logger.log(json.encode(data));
  24. var cacheString = json.encode(data);
  25. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, cacheString);
  26. });
  27. return _config;
  28. } else {
  29. Map result = await NetUtil.post('/api/v1/app/guide', method: NetMethod.GET);
  30. var data = result['data'];
  31. _config = AppConfigModel.fromJson(Map<String, dynamic>.from(data));
  32. Logger.debug('基础设置初始化');
  33. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, json.encode(data));
  34. return _config;
  35. }
  36. } catch (err) {
  37. Logger.error(err);
  38. return null;
  39. }
  40. }
  41. AppConfigModel.fromJson(Map<String, dynamic> json) {
  42. keys = json['keys'] != null ? new AppConfigKeyModel.fromJson(json['keys']) : null;
  43. guideImage = json['guide_image'] != null ? new AppConfigGuideModel.fromJson(json['guide_image']) : null;
  44. guideData = json['guide_data'] != null ? GuideData.fromJson(json['guide_data']) : null;
  45. appStartDelay=json['app_start_delay']!=null?json['app_start_delay']:'0.5';
  46. }
  47. Map<String, dynamic> toJson() {
  48. final Map<String, dynamic> data = new Map<String, dynamic>();
  49. if (this.keys != null) {
  50. data['keys'] = this.keys.toJson();
  51. }
  52. if (this.guideImage != null) {
  53. data['guide_image'] = this.guideImage.toJson();
  54. }
  55. return data;
  56. }
  57. }
  58. class AppConfigKeyModel {
  59. AppConfigKeyItemModel weibo;
  60. AppConfigKeyItemModel qq;
  61. AppConfigKeyItemModel weixin;
  62. AppConfigKeyItemModel jdIos;
  63. AppConfigKeyItemModel jdAndroid;
  64. AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid});
  65. AppConfigKeyModel.fromJson(Map<String, dynamic> json) {
  66. weibo = json['weibo'] != null ? new AppConfigKeyItemModel.fromJson(json['weibo']) : null;
  67. qq = json['qq'] != null ? new AppConfigKeyItemModel.fromJson(json['qq']) : null;
  68. weixin = json['weixin'] != null ? new AppConfigKeyItemModel.fromJson(json['weixin']) : null;
  69. jdIos = json['jd_ios'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_ios']) : null;
  70. jdAndroid = json['jd_android'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_android']) : null;
  71. }
  72. Map<String, dynamic> toJson() {
  73. final Map<String, dynamic> data = new Map<String, dynamic>();
  74. if (this.weibo != null) {
  75. data['weibo'] = this.weibo.toJson();
  76. }
  77. if (this.qq != null) {
  78. data['qq'] = this.qq.toJson();
  79. }
  80. if (this.weixin != null) {
  81. data['weixin'] = this.weixin.toJson();
  82. }
  83. if (this.jdIos != null) {
  84. data['jd_ios'] = this.jdIos.toJson();
  85. }
  86. if (this.jdAndroid != null) {
  87. data['jd_android'] = this.jdAndroid.toJson();
  88. }
  89. return data;
  90. }
  91. }
  92. class GuideData {
  93. String indicatorType;
  94. String indicatorCssType;
  95. String indicatorChooseColor;
  96. String indicatorUnchooseColor;
  97. String btnText;
  98. String btnBgColor;
  99. String btnTextColor;
  100. List<GuideCss> guideCss;
  101. GuideData({this.indicatorType, this.indicatorCssType, this.indicatorChooseColor, this.indicatorUnchooseColor, this.btnText, this.btnBgColor, this.btnTextColor, this.guideCss});
  102. GuideData.fromJson(Map<String, dynamic> json) {
  103. indicatorType = json['indicator_type'];
  104. indicatorCssType = json['indicator_css_type'];
  105. indicatorChooseColor = json['indicator_choose_color'];
  106. indicatorUnchooseColor = json['indicator_unchoose_color'];
  107. btnText = json['btn_text'];
  108. btnBgColor = json['btn_bg_color'];
  109. btnTextColor = json['btn_text_color'];
  110. if (json['guide_css'] != null) {
  111. guideCss = new List<GuideCss>();
  112. json['guide_css'].forEach((v) {
  113. guideCss.add(new GuideCss.fromJson(v));
  114. });
  115. }
  116. }
  117. Map<String, dynamic> toJson() {
  118. final Map<String, dynamic> data = new Map<String, dynamic>();
  119. data['indicator_type'] = this.indicatorType;
  120. data['indicator_css_type'] = this.indicatorCssType;
  121. data['indicator_choose_color'] = this.indicatorChooseColor;
  122. data['indicator_unchoose_color'] = this.indicatorUnchooseColor;
  123. data['btn_text'] = this.btnText;
  124. data['btn_bg_color'] = this.btnBgColor;
  125. data['btn_text_color'] = this.btnTextColor;
  126. if (this.guideCss != null) {
  127. data['guide_css'] = this.guideCss.map((v) => v.toJson()).toList();
  128. }
  129. return data;
  130. }
  131. }
  132. class GuideCss {
  133. String bgImage;
  134. String contentImage;
  135. GuideCss({this.bgImage, this.contentImage});
  136. GuideCss.fromJson(Map<String, dynamic> json) {
  137. bgImage = json['bg_image'];
  138. contentImage = json['content_image'];
  139. }
  140. Map<String, dynamic> toJson() {
  141. final Map<String, dynamic> data = new Map<String, dynamic>();
  142. data['bg_image'] = this.bgImage;
  143. data['content_image'] = this.contentImage;
  144. return data;
  145. }
  146. }
  147. class AppConfigKeyItemModel {
  148. String appId;
  149. String appkey;
  150. String secret;
  151. String redirectUrl;
  152. String universalLink;
  153. AppConfigKeyItemModel({this.appkey, this.secret, this.redirectUrl});
  154. AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
  155. appId = json['app_id'];
  156. appkey = json['appkey'];
  157. secret = json['secret'];
  158. redirectUrl = json['redirect_url'];
  159. universalLink = json['universal_link'];
  160. }
  161. Map<String, dynamic> toJson() {
  162. final Map<String, dynamic> data = new Map<String, dynamic>();
  163. data['app_id'] = this.appId;
  164. data['appkey'] = this.appkey;
  165. data['secret'] = this.secret;
  166. data['redirect_url'] = this.redirectUrl;
  167. data['universal_link'] = this.universalLink;
  168. return data;
  169. }
  170. }
  171. class AppConfigGuideModel {
  172. String isShowIndicator;
  173. List<String> images;
  174. AppConfigGuideModel({this.isShowIndicator, this.images});
  175. AppConfigGuideModel.fromJson(Map<String, dynamic> json) {
  176. isShowIndicator = json['is_show_indicator'];
  177. images = json['images'].cast<String>();
  178. }
  179. Map<String, dynamic> toJson() {
  180. final Map<String, dynamic> data = new Map<String, dynamic>();
  181. data['is_show_indicator'] = this.isShowIndicator;
  182. data['images'] = this.images;
  183. return data;
  184. }
  185. }