@@ -5,6 +5,8 @@ import 'package:jdsdk/jdsdk.dart'; | |||||
import 'package:url_launcher/url_launcher.dart'; | import 'package:url_launcher/url_launcher.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
import 'taobao_image_viewer.dart'; | |||||
void main() => runApp(MyApp()); | void main() => runApp(MyApp()); | ||||
class MyApp extends StatefulWidget { | class MyApp extends StatefulWidget { | ||||
@@ -145,14 +147,8 @@ class HomePage extends StatelessWidget { | |||||
RaisedButton( | RaisedButton( | ||||
onPressed: () { | onPressed: () { | ||||
Navigator.push(context, MaterialPageRoute(builder: (_) { | Navigator.push(context, MaterialPageRoute(builder: (_) { | ||||
return TaobaoImageLoader( | |||||
'https://h5.m.taobao.com/app/detail/desc.html?_isH5Des=true#!id=592787622422&type=1&f=&sellerType=B', | |||||
onImagesLoad: (images) { | |||||
Logger.debug(images.toString()); | |||||
}, | |||||
); | |||||
return TaobaoImageView(); | |||||
})); | })); | ||||
// TaobaoUtil.getImage(); | |||||
}, | }, | ||||
child: Text('抓淘宝图片'), | child: Text('抓淘宝图片'), | ||||
), | ), | ||||
@@ -0,0 +1,40 @@ | |||||
import 'package:cached_network_image/cached_network_image.dart'; | |||||
import 'package:flutter/material.dart'; | |||||
import 'package:zhiying_comm/zhiying_comm.dart'; | |||||
class TaobaoImageView extends StatefulWidget { | |||||
@override | |||||
_TaobaoImageViewState createState() => _TaobaoImageViewState(); | |||||
} | |||||
class _TaobaoImageViewState extends State<TaobaoImageView> { | |||||
List<String> _images = List(); | |||||
@override | |||||
void initState() { | |||||
TaobaoLoader.loadImages('592787622422').then((images) { | |||||
_images = images; | |||||
setState(() {}); | |||||
}); | |||||
super.initState(); | |||||
} | |||||
@override | |||||
Widget build(BuildContext context) { | |||||
return Scaffold( | |||||
appBar: AppBar( | |||||
title: Text('淘宝图片加载'), | |||||
), | |||||
body: SingleChildScrollView( | |||||
child: Column( | |||||
children: _images.map((imageUrl) { | |||||
return CachedNetworkImage( | |||||
imageUrl: imageUrl ?? '', | |||||
fit: BoxFit.fitWidth, | |||||
); | |||||
}).toList(), | |||||
), | |||||
), | |||||
); | |||||
} | |||||
} |
@@ -5,12 +5,12 @@ import 'package:webview_flutter/webview_flutter.dart'; | |||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
// 淘宝详情图加载 | // 淘宝详情图加载 | ||||
class TaobaoImageLoader extends StatefulWidget { | |||||
class TaobaoImageWebviewLoader extends StatefulWidget { | |||||
final String url; | final String url; | ||||
String script; | String script; | ||||
final ValueChanged<List<String>> onImagesLoad; | final ValueChanged<List<String>> onImagesLoad; | ||||
TaobaoImageLoader(this.url, {Key key, this.script, this.onImagesLoad}) | |||||
TaobaoImageWebviewLoader(this.url, {Key key, this.script, this.onImagesLoad}) | |||||
: super(key: key) { | : super(key: key) { | ||||
this.script = script; | this.script = script; | ||||
if (EmptyUtil.isEmpty(this.script)) { | if (EmptyUtil.isEmpty(this.script)) { | ||||
@@ -20,10 +20,11 @@ class TaobaoImageLoader extends StatefulWidget { | |||||
} | } | ||||
@override | @override | ||||
_TaobaoImageLoaderState createState() => _TaobaoImageLoaderState(); | |||||
_TaobaoImageWebviewLoaderState createState() => | |||||
_TaobaoImageWebviewLoaderState(); | |||||
} | } | ||||
class _TaobaoImageLoaderState extends State<TaobaoImageLoader> { | |||||
class _TaobaoImageWebviewLoaderState extends State<TaobaoImageWebviewLoader> { | |||||
WebViewController _webViewController; | WebViewController _webViewController; | ||||
List<String> _images = []; | List<String> _images = []; |
@@ -0,0 +1,25 @@ | |||||
import 'package:dio/dio.dart'; | |||||
class TaobaoLoader { | |||||
static Future<List<String>> loadImages(String id) async { | |||||
String url = | |||||
'http://h5api.m.taobao.com/h5/mtop.taobao.detail.getdesc/6.0/?api=mtop.taobao.detail.getdesc&appkey=12574478&data={"type":"0","f":"TB1AsvbfnqWBKNjSZFx8qwpLpla","id":"${id.toString()}"}&dataType=json&jsv=2.4.11&sign=e93a97b7e9a9a459297f4e689051c895&t=1538180732308&type=json'; | |||||
Dio dio = Dio(); | |||||
Response response = await dio.get(url); | |||||
// Logger.debug(response.data.toString()); | |||||
Map<String, dynamic> json = Map<String, dynamic>.from(response.data); | |||||
List list = json['data']['wdescContent']['pages']; | |||||
List<String> images = List(); | |||||
for (var item in list) { | |||||
RegExp exp = new RegExp("(?<=<img(.*?)>)(.*?)(?=</img>)"); | |||||
String image = exp.stringMatch(item.toString()); | |||||
if (image.startsWith('//')) { | |||||
images.add('http:' + image); | |||||
} else if (image.startsWith('https://') || image.startsWith('http://')) { | |||||
images.add(image); | |||||
} | |||||
} | |||||
return images; | |||||
} | |||||
} |
@@ -26,6 +26,7 @@ export 'util/net_util.dart'; | |||||
export 'util/page_factory.dart'; | export 'util/page_factory.dart'; | ||||
export 'util/router_util.dart'; | export 'util/router_util.dart'; | ||||
export 'util/taobao/taobao_auth.dart'; | export 'util/taobao/taobao_auth.dart'; | ||||
export 'util/taobao/taobao_image_loader.dart'; | |||||
export 'util/taobao/taobao_image_webview_loader.dart'; | |||||
export 'util/taobao/taobao_loader.dart'; | |||||
export 'util/widget_creater.dart'; | export 'util/widget_creater.dart'; | ||||
export 'util/widget_factory.dart'; | export 'util/widget_factory.dart'; |