基础组件库
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

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