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

306 lines
9.0 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. // H5根域名
  11. DomainModel domain;
  12. ///新引导页参数
  13. GuideData guideData;
  14. static String appStartDelay = "0.5";
  15. static AppConfigModel _config;
  16. AppConfigModel({this.keys, this.guideImage, this.domain});
  17. static AppConfigModel getConfig() => _config;
  18. static Future<AppConfigModel> init({bool isGetCache = false}) async {
  19. try {
  20. String cacheData = await SharedPreferencesUtil.getStringValue(GlobalConfig.GUIDE, defaultVal: '1');
  21. if (isGetCache && cacheData != '1') {
  22. _config = AppConfigModel.fromJson(Map<String, dynamic>.from(json.decode(cacheData)));
  23. Logger.debug('基础设置初始化');
  24. NetUtil.request('/api/v1/app/guide', onSuccess: (data) {
  25. Logger.log(json.encode(data));
  26. var cacheString = json.encode(data);
  27. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, cacheString);
  28. });
  29. return _config;
  30. } else {
  31. Map result = await NetUtil.post('/api/v1/app/guide', method: NetMethod.GET);
  32. var data = result['data'];
  33. _config = AppConfigModel.fromJson(Map<String, dynamic>.from(data));
  34. Logger.debug('基础设置初始化');
  35. SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, json.encode(data));
  36. return _config;
  37. }
  38. } catch (err) {
  39. Logger.error(err);
  40. return null;
  41. }
  42. }
  43. AppConfigModel.fromJson(Map<String, dynamic> json) {
  44. keys = json['keys'] != null ? new AppConfigKeyModel.fromJson(json['keys']) : null;
  45. guideImage = json['guide_image'] != null ? new AppConfigGuideModel.fromJson(json['guide_image']) : null;
  46. guideData = json['guide_data'] != null ? GuideData.fromJson(json['guide_data']) : null;
  47. appStartDelay = json['app_start_delay'] != null ? json['app_start_delay'] : '0.5';
  48. domain = json['domain'] != null ? new DomainModel.fromJson(json['domain']) : null;
  49. }
  50. Map<String, dynamic> toJson() {
  51. final Map<String, dynamic> data = new Map<String, dynamic>();
  52. if (this.keys != null) {
  53. data['keys'] = this.keys.toJson();
  54. }
  55. if (this.guideImage != null) {
  56. data['guide_image'] = this.guideImage.toJson();
  57. }
  58. if (this.domain != null) {
  59. data['domain'] = this.domain.toJson();
  60. }
  61. return data;
  62. }
  63. }
  64. class AppConfigKeyModel {
  65. AppConfigKeyItemModel weibo;
  66. AppConfigKeyItemModel qq;
  67. AppConfigKeyItemModel weixin;
  68. AppConfigKeyItemModel jdIos;
  69. AppConfigKeyItemModel jdAndroid;
  70. AppConfigKeyItemModel taobao;
  71. AppConfigKeyItemModel bugly;
  72. GDModel gd;
  73. AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid, this.taobao, this.bugly});
  74. AppConfigKeyModel.fromJson(Map<String, dynamic> json) {
  75. weibo = json['weibo'] != null ? new AppConfigKeyItemModel.fromJson(json['weibo']) : null;
  76. qq = json['qq'] != null ? new AppConfigKeyItemModel.fromJson(json['qq']) : null;
  77. weixin = json['weixin'] != null ? new AppConfigKeyItemModel.fromJson(json['weixin']) : null;
  78. jdIos = json['jd_ios'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_ios']) : null;
  79. jdAndroid = json['jd_android'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_android']) : null;
  80. taobao = json['taobao'] != null ? new AppConfigKeyItemModel.fromJson(json['taobao']) : null;
  81. gd = json['gd'] != null ? GDModel.fromJson(json['gd']) : null;
  82. bugly = json['bugly_list'] != null ? new AppConfigKeyItemModel.fromJson(json['bugly_list']) : null;
  83. }
  84. Map<String, dynamic> toJson() {
  85. final Map<String, dynamic> data = new Map<String, dynamic>();
  86. if (this.weibo != null) {
  87. data['weibo'] = this.weibo.toJson();
  88. }
  89. if (this.qq != null) {
  90. data['qq'] = this.qq.toJson();
  91. }
  92. if (this.weixin != null) {
  93. data['weixin'] = this.weixin.toJson();
  94. }
  95. if (this.jdIos != null) {
  96. data['jd_ios'] = this.jdIos.toJson();
  97. }
  98. if (this.jdAndroid != null) {
  99. data['jd_android'] = this.jdAndroid.toJson();
  100. }
  101. if (this.taobao != null) {
  102. data['taobao'] = this.taobao.toJson();
  103. }
  104. if (this.gd != null) {
  105. data['gd'] = this.gd.toJson();
  106. }
  107. if (this.bugly != null) {
  108. data['bugly_list'] = this.bugly.toJson();
  109. }
  110. return data;
  111. }
  112. }
  113. class GuideData {
  114. String indicatorType;
  115. String indicatorCssType;
  116. String indicatorChooseColor;
  117. String indicatorUnchooseColor;
  118. String btnText;
  119. String btnBgColor;
  120. String btnTextColor;
  121. List<GuideCss> guideCss;
  122. GuideData({this.indicatorType, this.indicatorCssType, this.indicatorChooseColor, this.indicatorUnchooseColor, this.btnText, this.btnBgColor, this.btnTextColor, this.guideCss});
  123. GuideData.fromJson(Map<String, dynamic> json) {
  124. indicatorType = json['indicator_type'];
  125. indicatorCssType = json['indicator_css_type'];
  126. indicatorChooseColor = json['indicator_choose_color'];
  127. indicatorUnchooseColor = json['indicator_unchoose_color'];
  128. btnText = json['btn_text'];
  129. btnBgColor = json['btn_bg_color'];
  130. btnTextColor = json['btn_text_color'];
  131. if (json['guide_css'] != null) {
  132. guideCss = new List<GuideCss>();
  133. json['guide_css'].forEach((v) {
  134. guideCss.add(new GuideCss.fromJson(v));
  135. });
  136. }
  137. }
  138. Map<String, dynamic> toJson() {
  139. final Map<String, dynamic> data = new Map<String, dynamic>();
  140. data['indicator_type'] = this.indicatorType;
  141. data['indicator_css_type'] = this.indicatorCssType;
  142. data['indicator_choose_color'] = this.indicatorChooseColor;
  143. data['indicator_unchoose_color'] = this.indicatorUnchooseColor;
  144. data['btn_text'] = this.btnText;
  145. data['btn_bg_color'] = this.btnBgColor;
  146. data['btn_text_color'] = this.btnTextColor;
  147. if (this.guideCss != null) {
  148. data['guide_css'] = this.guideCss.map((v) => v.toJson()).toList();
  149. }
  150. return data;
  151. }
  152. }
  153. class GuideCss {
  154. String bgImage;
  155. String contentImage;
  156. GuideCss({this.bgImage, this.contentImage});
  157. GuideCss.fromJson(Map<String, dynamic> json) {
  158. bgImage = json['bg_image'];
  159. contentImage = json['content_image'];
  160. }
  161. Map<String, dynamic> toJson() {
  162. final Map<String, dynamic> data = new Map<String, dynamic>();
  163. data['bg_image'] = this.bgImage;
  164. data['content_image'] = this.contentImage;
  165. return data;
  166. }
  167. }
  168. class AppConfigKeyItemModel {
  169. String appId;
  170. String appkey;
  171. String secret;
  172. String redirectUrl;
  173. String universalLink;
  174. String androidKey;
  175. String iosKey;
  176. String androidAppId;
  177. String androidAppKey;
  178. String iosAppId;
  179. String iosAppKey;
  180. AppConfigKeyItemModel({
  181. this.appkey,
  182. this.secret,
  183. this.redirectUrl,
  184. this.androidKey,
  185. this.iosKey,
  186. this.androidAppId,
  187. this.androidAppKey,
  188. this.iosAppId,
  189. this.iosAppKey
  190. });
  191. AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
  192. appId = json['app_id'];
  193. appkey = json['appkey'];
  194. secret = json['secret'];
  195. androidKey = json['android_key'];
  196. iosKey = json['ios_key'];
  197. redirectUrl = json['redirect_url'];
  198. universalLink = json['universal_link'];
  199. androidAppId = json['android_appid'];
  200. androidAppKey = json['android_appkey'];
  201. iosAppId = json['ios_appid'];
  202. iosAppKey = json['ios_appkey'];
  203. }
  204. Map<String, dynamic> toJson() {
  205. final Map<String, dynamic> data = new Map<String, dynamic>();
  206. data['app_id'] = this.appId;
  207. data['appkey'] = this.appkey;
  208. data['secret'] = this.secret;
  209. data['redirect_url'] = this.redirectUrl;
  210. data['android_key'] = this.androidKey;
  211. data['ios_key'] = this.iosKey;
  212. data['universal_link'] = this.universalLink;
  213. data['android_appid'] = this.androidAppId;
  214. data['android_appkey'] = this.androidAppKey;
  215. data['ios_appid'] = this.iosAppId;
  216. data['ios_appkey'] = this.iosAppKey;
  217. return data;
  218. }
  219. }
  220. class AppConfigGuideModel {
  221. String isShowIndicator;
  222. List<String> images;
  223. AppConfigGuideModel({this.isShowIndicator, this.images});
  224. AppConfigGuideModel.fromJson(Map<String, dynamic> json) {
  225. isShowIndicator = json['is_show_indicator'];
  226. images = json['images'].cast<String>();
  227. }
  228. Map<String, dynamic> toJson() {
  229. final Map<String, dynamic> data = new Map<String, dynamic>();
  230. data['is_show_indicator'] = this.isShowIndicator;
  231. data['images'] = this.images;
  232. return data;
  233. }
  234. }
  235. class DomainModel {
  236. String h5Url;
  237. DomainModel({this.h5Url});
  238. DomainModel.fromJson(Map<String, dynamic> json) {
  239. h5Url = json['h5_url']?.toString();
  240. }
  241. Map<String, dynamic> toJson() {
  242. final Map<String, dynamic> data = new Map<String, dynamic>();
  243. data['h5_url'] = this.h5Url;
  244. return data;
  245. }
  246. }
  247. class GDModel {
  248. String androidKey;
  249. String iosKey;
  250. GDModel({this.androidKey, this.iosKey});
  251. GDModel.fromJson(Map<String, dynamic> json) {
  252. androidKey = json['android_key'];
  253. iosKey = json['ios_key'];
  254. }
  255. Map<String, dynamic> toJson() {
  256. final Map<String, dynamic> data = new Map<String, dynamic>();
  257. data['android_key'] = this.androidKey;
  258. data['ios_key'] = this.iosKey;
  259. return data;
  260. }
  261. }