|
- import 'dart:convert';
-
- import 'package:zhiying_comm/util/shared_prefe_util.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
-
- // 应用配置信息
-
- class AppConfigModel {
- // 应用配置的key
- AppConfigKeyModel keys;
-
- // 引导页
- AppConfigGuideModel guideImage;
-
- // H5根域名
- DomainModel domain;
-
- ///新引导页参数
- GuideData guideData;
-
- static String appStartDelay = "0.5";
-
- static AppConfigModel _config;
-
- AppConfigModel({this.keys, this.guideImage, this.domain});
-
- static AppConfigModel getConfig() => _config;
-
- static Future<AppConfigModel> init({bool isGetCache = false}) async {
- try {
- String cacheData = await SharedPreferencesUtil.getStringValue(GlobalConfig.GUIDE, defaultVal: '1');
- if (isGetCache && cacheData != '1') {
- _config = AppConfigModel.fromJson(Map<String, dynamic>.from(json.decode(cacheData)));
- Logger.debug('基础设置初始化');
- NetUtil.request('/api/v1/app/guide', onSuccess: (data) {
- Logger.log(json.encode(data));
- var cacheString = json.encode(data);
- SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, cacheString);
- });
- return _config;
- } else {
- Map result = await NetUtil.post('/api/v1/app/guide', method: NetMethod.GET);
- var data = result['data'];
- _config = AppConfigModel.fromJson(Map<String, dynamic>.from(data));
- Logger.debug('基础设置初始化');
- SharedPreferencesUtil.setNetCacheResult(GlobalConfig.GUIDE, json.encode(data));
- return _config;
- }
- } catch (err) {
- Logger.error(err);
-
- return null;
- }
- }
-
- AppConfigModel.fromJson(Map<String, dynamic> json) {
- keys = json['keys'] != null ? new AppConfigKeyModel.fromJson(json['keys']) : null;
- guideImage = json['guide_image'] != null ? new AppConfigGuideModel.fromJson(json['guide_image']) : null;
- guideData = json['guide_data'] != null ? GuideData.fromJson(json['guide_data']) : null;
- appStartDelay = json['app_start_delay'] != null ? json['app_start_delay'] : '0.5';
- domain = json['domain'] != null ? new DomainModel.fromJson(json['domain']) : null;
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- if (this.keys != null) {
- data['keys'] = this.keys.toJson();
- }
- if (this.guideImage != null) {
- data['guide_image'] = this.guideImage.toJson();
- }
- if (this.domain != null) {
- data['domain'] = this.domain.toJson();
- }
- return data;
- }
- }
-
- class AppConfigKeyModel {
- AppConfigKeyItemModel weibo;
- AppConfigKeyItemModel qq;
- AppConfigKeyItemModel weixin;
- AppConfigKeyItemModel jdIos;
- AppConfigKeyItemModel jdAndroid;
- AppConfigKeyItemModel taobao;
- AppConfigKeyItemModel bugly;
- GDModel gd;
-
-
- AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid, this.taobao, this.bugly});
-
- AppConfigKeyModel.fromJson(Map<String, dynamic> json) {
- weibo = json['weibo'] != null ? new AppConfigKeyItemModel.fromJson(json['weibo']) : null;
- qq = json['qq'] != null ? new AppConfigKeyItemModel.fromJson(json['qq']) : null;
- weixin = json['weixin'] != null ? new AppConfigKeyItemModel.fromJson(json['weixin']) : null;
- jdIos = json['jd_ios'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_ios']) : null;
- jdAndroid = json['jd_android'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_android']) : null;
- taobao = json['taobao'] != null ? new AppConfigKeyItemModel.fromJson(json['taobao']) : null;
- gd = json['gd'] != null ? GDModel.fromJson(json['gd']) : null;
- bugly = json['bugly_list'] != null ? new AppConfigKeyItemModel.fromJson(json['bugly_list']) : null;
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- if (this.weibo != null) {
- data['weibo'] = this.weibo.toJson();
- }
- if (this.qq != null) {
- data['qq'] = this.qq.toJson();
- }
- if (this.weixin != null) {
- data['weixin'] = this.weixin.toJson();
- }
- if (this.jdIos != null) {
- data['jd_ios'] = this.jdIos.toJson();
- }
- if (this.jdAndroid != null) {
- data['jd_android'] = this.jdAndroid.toJson();
- }
- if (this.taobao != null) {
- data['taobao'] = this.taobao.toJson();
- }
- if (this.gd != null) {
- data['gd'] = this.gd.toJson();
- }
- if (this.bugly != null) {
- data['bugly_list'] = this.bugly.toJson();
- }
- return data;
- }
- }
-
- class GuideData {
- String indicatorType;
- String indicatorCssType;
- String indicatorChooseColor;
- String indicatorUnchooseColor;
- String btnText;
- String btnBgColor;
- String btnTextColor;
- List<GuideCss> guideCss;
-
- GuideData({this.indicatorType, this.indicatorCssType, this.indicatorChooseColor, this.indicatorUnchooseColor, this.btnText, this.btnBgColor, this.btnTextColor, this.guideCss});
-
- GuideData.fromJson(Map<String, dynamic> json) {
- indicatorType = json['indicator_type'];
- indicatorCssType = json['indicator_css_type'];
- indicatorChooseColor = json['indicator_choose_color'];
- indicatorUnchooseColor = json['indicator_unchoose_color'];
- btnText = json['btn_text'];
- btnBgColor = json['btn_bg_color'];
- btnTextColor = json['btn_text_color'];
- if (json['guide_css'] != null) {
- guideCss = new List<GuideCss>();
- json['guide_css'].forEach((v) {
- guideCss.add(new GuideCss.fromJson(v));
- });
- }
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['indicator_type'] = this.indicatorType;
- data['indicator_css_type'] = this.indicatorCssType;
- data['indicator_choose_color'] = this.indicatorChooseColor;
- data['indicator_unchoose_color'] = this.indicatorUnchooseColor;
- data['btn_text'] = this.btnText;
- data['btn_bg_color'] = this.btnBgColor;
- data['btn_text_color'] = this.btnTextColor;
- if (this.guideCss != null) {
- data['guide_css'] = this.guideCss.map((v) => v.toJson()).toList();
- }
- return data;
- }
- }
-
- class GuideCss {
- String bgImage;
- String contentImage;
-
- GuideCss({this.bgImage, this.contentImage});
-
- GuideCss.fromJson(Map<String, dynamic> json) {
- bgImage = json['bg_image'];
- contentImage = json['content_image'];
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['bg_image'] = this.bgImage;
- data['content_image'] = this.contentImage;
- return data;
- }
- }
-
- class AppConfigKeyItemModel {
- String appId;
- String appkey;
- String secret;
- String redirectUrl;
- String universalLink;
- String androidKey;
- String iosKey;
- String androidAppId;
- String androidAppKey;
- String iosAppId;
- String iosAppKey;
-
- AppConfigKeyItemModel({
- this.appkey,
- this.secret,
- this.redirectUrl,
- this.androidKey,
- this.iosKey,
- this.androidAppId,
- this.androidAppKey,
- this.iosAppId,
- this.iosAppKey
- });
-
- AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
- appId = json['app_id'];
- appkey = json['appkey'];
- secret = json['secret'];
- androidKey = json['android_key'];
- iosKey = json['ios_key'];
- redirectUrl = json['redirect_url'];
- universalLink = json['universal_link'];
- androidAppId = json['android_appid'];
- androidAppKey = json['android_appkey'];
- iosAppId = json['ios_appid'];
- iosAppKey = json['ios_appkey'];
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['app_id'] = this.appId;
- data['appkey'] = this.appkey;
- data['secret'] = this.secret;
- data['redirect_url'] = this.redirectUrl;
- data['android_key'] = this.androidKey;
- data['ios_key'] = this.iosKey;
- data['universal_link'] = this.universalLink;
- data['android_appid'] = this.androidAppId;
- data['android_appkey'] = this.androidAppKey;
- data['ios_appid'] = this.iosAppId;
- data['ios_appkey'] = this.iosAppKey;
- return data;
- }
- }
-
- class AppConfigGuideModel {
- String isShowIndicator;
- List<String> images;
-
- AppConfigGuideModel({this.isShowIndicator, this.images});
-
- AppConfigGuideModel.fromJson(Map<String, dynamic> json) {
- isShowIndicator = json['is_show_indicator'];
- images = json['images'].cast<String>();
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['is_show_indicator'] = this.isShowIndicator;
- data['images'] = this.images;
- return data;
- }
- }
-
- class DomainModel {
- String h5Url;
-
- DomainModel({this.h5Url});
-
- DomainModel.fromJson(Map<String, dynamic> json) {
- h5Url = json['h5_url']?.toString();
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['h5_url'] = this.h5Url;
- return data;
- }
-
- }
-
- class GDModel {
- String androidKey;
- String iosKey;
-
- GDModel({this.androidKey, this.iosKey});
-
- GDModel.fromJson(Map<String, dynamic> json) {
- androidKey = json['android_key'];
- iosKey = json['ios_key'];
- }
-
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['android_key'] = this.androidKey;
- data['ios_key'] = this.iosKey;
- return data;
- }
- }
|