Ver a proveniência

更新结构

tags/0.0.1
Weller há 4 anos
ascendente
cometimento
755c5849d1
7 ficheiros alterados com 286 adições e 140 eliminações
  1. +144
    -140
      example/lib/main.dart
  2. +51
    -0
      lib/models/base/base_setting_model.dart
  3. +50
    -0
      lib/models/base/base_tab_model.dart
  4. +4
    -0
      lib/register.dart
  5. +18
    -0
      lib/util/application.dart
  6. +16
    -0
      lib/util/image_util.dart
  7. +3
    -0
      lib/zhiying_comm.dart

+ 144
- 140
example/lib/main.dart Ver ficheiro

@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_alibc/flutter_alibc.dart';
import 'package:jdsdk/jdsdk.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:zhiying_comm/pages/launch_page/launch_page.dart';
import 'package:zhiying_comm/register.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

import 'taobao_image_viewer.dart';
@@ -17,26 +19,23 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
@override
void initState() {
Jdsdk.init(appKey: '9fc3dec00b9b40cc950dfba5262cd6d3',
appSecret: 'f785613e5fd54a129d0f0359a4e25c23').then((result) {
BaseWidgetRegister.init();
Jdsdk.init(
appKey: '9fc3dec00b9b40cc950dfba5262cd6d3',
appSecret: 'f785613e5fd54a129d0f0359a4e25c23')
.then((result) {
Logger.debug('京东初始化:${result.toString()}');
});
FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
Logger.debug('${result.errorCode} ${result.errorMessage}');
});

super.initState();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('智莺-基础库'),
),
body: HomePage(),
),
);
return MaterialApp(home: LaunchPage(builder: (context) => HomePage(),),);
}
}

@@ -49,71 +48,75 @@ class HomePage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Center(
child: Wrap(
spacing: 10,
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
// return DeviceInfoPage();
}));
},
child: Text('设备信息'),
),
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
// return PackageInfoPage();
}));
},
child: Text('应用信息'),
),
RaisedButton(
onPressed: () {
NetUtil.post('/siteapi/v1/ucenter/login/', params: {
'username': 'xiangguohui',
'password': 'fnuo123com'
});
},
child: Text('登录请求'),
),
RaisedButton(
onPressed: () {
NetUtil.request('/api/v1/rec/featured?page=1', params: null,
onError: (msg) {
print('onERROR = ${msg?.toString() ?? 'onError'}');
}, onSuccess: (json) {
print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
}, onCache: (json) {
print('onCache = ${json?.toString() ?? 'onCache'}');
});
},
child: Text('网络异步请求(带缓存)'),
),
RaisedButton(
onPressed: () {
netPost();
},
child: Text('网络同步请求(无缓存)'),
),
RaisedButton(
onPressed: () {
// LogUtil.test();
},
child: Text('显示日志'),
),
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return Logger();
}));
},
child: Text('打开日志视图'),
),
RaisedButton(
onPressed: () {
return Scaffold(
appBar: AppBar(
title: const Text('智莺-基础库'),
),
body: SingleChildScrollView(
child: Center(
child: Wrap(
spacing: 10,
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
// return DeviceInfoPage();
}));
},
child: Text('设备信息'),
),
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
// return PackageInfoPage();
}));
},
child: Text('应用信息'),
),
RaisedButton(
onPressed: () {
NetUtil.post('/siteapi/v1/ucenter/login/', params: {
'username': 'xiangguohui',
'password': 'fnuo123com'
});
},
child: Text('登录请求'),
),
RaisedButton(
onPressed: () {
NetUtil.request('/api/v1/rec/featured?page=1', params: null,
onError: (msg) {
print('onERROR = ${msg?.toString() ?? 'onError'}');
}, onSuccess: (json) {
print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
}, onCache: (json) {
print('onCache = ${json?.toString() ?? 'onCache'}');
});
},
child: Text('网络异步请求(带缓存)'),
),
RaisedButton(
onPressed: () {
netPost();
},
child: Text('网络同步请求(无缓存)'),
),
RaisedButton(
onPressed: () {
// LogUtil.test();
},
child: Text('显示日志'),
),
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return Logger();
}));
},
child: Text('打开日志视图'),
),
RaisedButton(
onPressed: () {
// NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
// onSuccess: (params){
// Logger.log("onSuccess#$params");
@@ -122,74 +125,75 @@ class HomePage extends StatelessWidget {
// Logger.log("onCache#$params");
// });

testPost();
},
child: Text('测试接口'),
),
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return TaobaoImageView();
}));
},
child: Text('抓淘宝图片'),
),
RaisedButton(
onPressed: () {
TaobaoAuth.auth(context);
},
child: Text('淘宝授权'),
),
RaisedButton(
onPressed: () {
testPost();
},
child: Text('测试接口'),
),
RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return TaobaoImageView();
}));
},
child: Text('抓淘宝图片'),
),
RaisedButton(
onPressed: () {
TaobaoAuth.auth(context);
},
child: Text('淘宝授权'),
),
RaisedButton(
onPressed: () {
//
Dio dio = Dio();
dio.get(
'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html')
.then((value) {
Logger.debug(value.realUri.toString());
});
},
child: Text('获取重定向地址'),
),
RaisedButton(
onPressed: () {
Jdsdk.openUrl(
url: 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html');
},
child: Text('打开京东详情'),
),
RaisedButton(
onPressed: () async {
String detailUrl = 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html';
String baseUrl = detailUrl.getBaseUrl();
if (!baseUrl.contains('jd.com')) {
Dio dio = Dio();
var responds = await dio.get(detailUrl);
detailUrl = responds.realUri.toString();
}
Logger.debug(detailUrl);
Jdsdk.openUrl(
url
:
detailUrl
);
},
child: Text('嗨如意转链打开京东'),
),
RaisedButton(
onPressed: () async {
const url = 'weixin://';
dio.get(
'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html')
.then((value) {
Logger.debug(value.realUri.toString());
});
},
child: Text('获取重定向地址'),
),
RaisedButton(
onPressed: () {
Jdsdk.openUrl(
url: 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html');
},
child: Text('打开京东详情'),
),
RaisedButton(
onPressed: () async {
String detailUrl = 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html';
String baseUrl = detailUrl.getBaseUrl();
if (!baseUrl.contains('jd.com')) {
Dio dio = Dio();
var responds = await dio.get(detailUrl);
detailUrl = responds.realUri.toString();
}
Logger.debug(detailUrl);
Jdsdk.openUrl(
url
:
detailUrl
);
},
child: Text('嗨如意转链打开京东'),
),
RaisedButton(
onPressed: () async {
const url = 'weixin://';

if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
},
child: Text('url scheme打开app'),
),
],
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
},
child: Text('url scheme打开app'),
),
],
),
),
),
);


+ 51
- 0
lib/models/base/base_setting_model.dart Ver ficheiro

@@ -0,0 +1,51 @@
import 'package:zhiying_comm/util/net_util.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class BaseSettingModel {
String fileProvider;
String fileBucketHost;
String fileBucketHostProtocol;
Map<String, dynamic> tab;

static BaseSettingModel _setting;

static BaseSettingModel get setting {
if (_setting == null) {
Logger.error('暂未初始化');
}
return _setting;
}

BaseSettingModel(
{this.fileProvider, this.fileBucketHost, this.fileBucketHostProtocol});

BaseSettingModel.fromJson(Map<String, dynamic> json) {
fileProvider = json['file_provider'];
fileBucketHost = json['file_bucket_host'];
fileBucketHostProtocol = json['file_bucket_host_protocol'];
tab = Map<String, dynamic>.from(json['bottom_nav']);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['file_provider'] = this.fileProvider;
data['file_bucket_host'] = this.fileBucketHost;
data['file_bucket_host_protocol'] = this.fileBucketHostProtocol;
data['bottom_nav'] = this.tab;
return data;
}

static Future<BaseSettingModel> init() async {
Map result =
await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET);
try {
var data = result['data'];
_setting = BaseSettingModel.fromJson(Map<String, dynamic>.from(data));
Logger.debug('基础设置初始化');
return _setting;
} catch (err) {
Logger.error(err);
}
return null;
}
}

+ 50
- 0
lib/models/base/base_tab_model.dart Ver ficheiro

@@ -0,0 +1,50 @@
import 'package:zhiying_comm/models/base/skip_model.dart';

class BaseTabModel extends SkipModel {
String name;
String isShow;
String icon;
String chooseColor;
String chooseIcon;
String cateTag;
String bgColor;
String fontColor;

BaseTabModel(
{this.name,
this.isShow,
this.icon,
this.chooseColor,
this.chooseIcon,
this.cateTag,
this.bgColor,
this.fontColor});

BaseTabModel.fromJson(Map<String, dynamic> json) {
super.fromJson(json);
name = json['name'];
isShow = json['is_show'];
icon = json['icon'];
chooseColor = json['choose_color'];
chooseIcon = json['choose_icon'];
cateTag = json['cate_tag'];
skipIdentifier = json['skip_identifier'];
requiredLogin = json['required_login'];
requiredTaobaoAuth = json['required_taobao_auth'];
bgColor = json['bg_color'];
fontColor = json['font_color'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = super.toJson();
data['name'] = this.name;
data['is_show'] = this.isShow;
data['icon'] = this.icon;
data['choose_color'] = this.chooseColor;
data['choose_icon'] = this.chooseIcon;
data['cate_tag'] = this.cateTag;
data['bg_color'] = this.bgColor;
data['font_color'] = this.fontColor;
return data;
}
}

+ 4
- 0
lib/register.dart Ver ficheiro

@@ -0,0 +1,4 @@
class BaseWidgetRegister {
/// 初始化方法
static void init() {}
}

+ 18
- 0
lib/util/application.dart Ver ficheiro

@@ -0,0 +1,18 @@
typedef Future InitMethod();

class Application {
// 初始化方法
static List<InitMethod> _initMethods = List();

static Future init() async {
for (InitMethod method in _initMethods) {
await method();
}

return Future.delayed(Duration.zero);
}

static addMethod(InitMethod method) {
_initMethods.add(method);
}
}

+ 16
- 0
lib/util/image_util.dart Ver ficheiro

@@ -0,0 +1,16 @@
import 'package:zhiying_comm/models/base/base_setting_model.dart';

class ImageUtil {
// 拼接链接
static String getUrl(String originUrl) {
if (originUrl.startsWith('http://') || originUrl.startsWith('https://')) {
return originUrl;
}
BaseSettingModel setting = BaseSettingModel.setting;
return (setting?.fileBucketHostProtocol ?? '') +
'://' +
(setting?.fileBucketHost ?? '') +
'/' +
originUrl;
}
}

+ 3
- 0
lib/zhiying_comm.dart Ver ficheiro

@@ -3,6 +3,7 @@ library zhiying_comm;
// pages
export 'package:flutter_screenutil/flutter_screenutil.dart';

export 'models/base/base_setting_model.dart';
export 'models/base/skip_model.dart';
export 'models/base/widget_model.dart';
export 'models/user/user_info_model.dart';
@@ -11,6 +12,7 @@ export 'models/user/user_info_model_notifier.dart';
export 'models/user/user_info_model_notifier.dart';
export 'native/native_router.dart';
export 'pages/empty_page.dart';
export 'util/application.dart';
export 'util/defalut_widget_creater.dart';
export 'util/empty_util.dart';
export 'util/encode_util.dart';
@@ -18,6 +20,7 @@ export 'util/enum_util.dart';
export 'util/extension/color.dart';
export 'util/extension/string.dart';
export 'util/global_config.dart';
export 'util/image_util.dart';
export 'util/log/let_log.dart';
export 'util/native_util.dart';
export 'util/navigator_observer.dart';


Carregando…
Cancelar
Guardar