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

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