基础组件库
 
 
 
 
 

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