|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 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;
-
- static AppConfigModel _config;
-
- AppConfigModel({this.keys, this.guideImage});
-
- 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) {
- print(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;
- }
-
- 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();
- }
- return data;
- }
- }
-
- class AppConfigKeyModel {
- AppConfigKeyItemModel weibo;
- AppConfigKeyItemModel qq;
- AppConfigKeyItemModel weixin;
- AppConfigKeyItemModel jdIos;
- AppConfigKeyItemModel jdAndroid;
-
- AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid});
-
- 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;
- }
-
- 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();
- }
- return data;
- }
- }
-
- class AppConfigKeyItemModel {
- String appId;
- String appkey;
- String secret;
- String redirectUrl;
- String universalLink;
-
- AppConfigKeyItemModel({this.appkey, this.secret, this.redirectUrl});
-
- AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
- appId = json['app_id'];
- appkey = json['appkey'];
- secret = json['secret'];
- redirectUrl = json['redirect_url'];
- universalLink = json['universal_link'];
- }
-
- 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['universal_link'] = this.universalLink;
- 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;
- }
- }
|