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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. GDModel gd;
  65. AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid});
  66. AppConfigKeyModel.fromJson(Map<String, dynamic> json) {
  67. weibo = json['weibo'] != null ? new AppConfigKeyItemModel.fromJson(json['weibo']) : null;
  68. qq = json['qq'] != null ? new AppConfigKeyItemModel.fromJson(json['qq']) : null;
  69. weixin = json['weixin'] != null ? new AppConfigKeyItemModel.fromJson(json['weixin']) : null;
  70. jdIos = json['jd_ios'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_ios']) : null;
  71. jdAndroid = json['jd_android'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_android']) : null;
  72. gd = json['gd'] != null ? GDModel.fromJson(json['gd']) : null;
  73. }
  74. Map<String, dynamic> toJson() {
  75. final Map<String, dynamic> data = new Map<String, dynamic>();
  76. if (this.weibo != null) {
  77. data['weibo'] = this.weibo.toJson();
  78. }
  79. if (this.qq != null) {
  80. data['qq'] = this.qq.toJson();
  81. }
  82. if (this.weixin != null) {
  83. data['weixin'] = this.weixin.toJson();
  84. }
  85. if (this.jdIos != null) {
  86. data['jd_ios'] = this.jdIos.toJson();
  87. }
  88. if (this.jdAndroid != null) {
  89. data['jd_android'] = this.jdAndroid.toJson();
  90. }
  91. if (this.gd != null) {
  92. data['gd'] = this.gd.toJson();
  93. }
  94. return data;
  95. }
  96. }
  97. class GuideData {
  98. String indicatorType;
  99. String indicatorCssType;
  100. String indicatorChooseColor;
  101. String indicatorUnchooseColor;
  102. String btnText;
  103. String btnBgColor;
  104. String btnTextColor;
  105. List<GuideCss> guideCss;
  106. GuideData({this.indicatorType, this.indicatorCssType, this.indicatorChooseColor, this.indicatorUnchooseColor, this.btnText, this.btnBgColor, this.btnTextColor, this.guideCss});
  107. GuideData.fromJson(Map<String, dynamic> json) {
  108. indicatorType = json['indicator_type'];
  109. indicatorCssType = json['indicator_css_type'];
  110. indicatorChooseColor = json['indicator_choose_color'];
  111. indicatorUnchooseColor = json['indicator_unchoose_color'];
  112. btnText = json['btn_text'];
  113. btnBgColor = json['btn_bg_color'];
  114. btnTextColor = json['btn_text_color'];
  115. if (json['guide_css'] != null) {
  116. guideCss = new List<GuideCss>();
  117. json['guide_css'].forEach((v) {
  118. guideCss.add(new GuideCss.fromJson(v));
  119. });
  120. }
  121. }
  122. Map<String, dynamic> toJson() {
  123. final Map<String, dynamic> data = new Map<String, dynamic>();
  124. data['indicator_type'] = this.indicatorType;
  125. data['indicator_css_type'] = this.indicatorCssType;
  126. data['indicator_choose_color'] = this.indicatorChooseColor;
  127. data['indicator_unchoose_color'] = this.indicatorUnchooseColor;
  128. data['btn_text'] = this.btnText;
  129. data['btn_bg_color'] = this.btnBgColor;
  130. data['btn_text_color'] = this.btnTextColor;
  131. if (this.guideCss != null) {
  132. data['guide_css'] = this.guideCss.map((v) => v.toJson()).toList();
  133. }
  134. return data;
  135. }
  136. }
  137. class GuideCss {
  138. String bgImage;
  139. String contentImage;
  140. GuideCss({this.bgImage, this.contentImage});
  141. GuideCss.fromJson(Map<String, dynamic> json) {
  142. bgImage = json['bg_image'];
  143. contentImage = json['content_image'];
  144. }
  145. Map<String, dynamic> toJson() {
  146. final Map<String, dynamic> data = new Map<String, dynamic>();
  147. data['bg_image'] = this.bgImage;
  148. data['content_image'] = this.contentImage;
  149. return data;
  150. }
  151. }
  152. class AppConfigKeyItemModel {
  153. String appId;
  154. String appkey;
  155. String secret;
  156. String redirectUrl;
  157. String universalLink;
  158. AppConfigKeyItemModel({this.appkey, this.secret, this.redirectUrl});
  159. AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
  160. appId = json['app_id'];
  161. appkey = json['appkey'];
  162. secret = json['secret'];
  163. redirectUrl = json['redirect_url'];
  164. universalLink = json['universal_link'];
  165. }
  166. Map<String, dynamic> toJson() {
  167. final Map<String, dynamic> data = new Map<String, dynamic>();
  168. data['app_id'] = this.appId;
  169. data['appkey'] = this.appkey;
  170. data['secret'] = this.secret;
  171. data['redirect_url'] = this.redirectUrl;
  172. data['universal_link'] = this.universalLink;
  173. return data;
  174. }
  175. }
  176. class AppConfigGuideModel {
  177. String isShowIndicator;
  178. List<String> images;
  179. AppConfigGuideModel({this.isShowIndicator, this.images});
  180. AppConfigGuideModel.fromJson(Map<String, dynamic> json) {
  181. isShowIndicator = json['is_show_indicator'];
  182. images = json['images'].cast<String>();
  183. }
  184. Map<String, dynamic> toJson() {
  185. final Map<String, dynamic> data = new Map<String, dynamic>();
  186. data['is_show_indicator'] = this.isShowIndicator;
  187. data['images'] = this.images;
  188. return data;
  189. }
  190. }
  191. class GDModel {
  192. String androidKey;
  193. String iosKey;
  194. GDModel({this.androidKey, this.iosKey});
  195. GDModel.fromJson(Map<String, dynamic> json) {
  196. androidKey = json['android_key'];
  197. iosKey = json['ios_key'];
  198. }
  199. Map<String, dynamic> toJson() {
  200. final Map<String, dynamic> data = new Map<String, dynamic>();
  201. data['android_key'] = this.androidKey;
  202. data['ios_key'] = this.iosKey;
  203. return data;
  204. }
  205. }