基础组件库
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

244 řádky
7.3 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. 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. }