Kaynağa Gözat

添加新淘宝详情图加载

tags/0.0.1
Weller 4 yıl önce
ebeveyn
işleme
c97e52bfa5
5 değiştirilmiş dosya ile 75 ekleme ve 12 silme
  1. +3
    -7
      example/lib/main.dart
  2. +40
    -0
      example/lib/taobao_image_viewer.dart
  3. +5
    -4
      lib/util/taobao/taobao_image_webview_loader.dart
  4. +25
    -0
      lib/util/taobao/taobao_loader.dart
  5. +2
    -1
      lib/zhiying_comm.dart

+ 3
- 7
example/lib/main.dart Dosyayı Görüntüle

@@ -5,6 +5,8 @@ import 'package:jdsdk/jdsdk.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

import 'taobao_image_viewer.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
@@ -145,14 +147,8 @@ class HomePage extends StatelessWidget {
RaisedButton(
onPressed: () {
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('抓淘宝图片'),
),


+ 40
- 0
example/lib/taobao_image_viewer.dart Dosyayı Görüntüle

@@ -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(),
),
),
);
}
}

lib/util/taobao/taobao_image_loader.dart → lib/util/taobao/taobao_image_webview_loader.dart Dosyayı Görüntüle

@@ -5,12 +5,12 @@ import 'package:webview_flutter/webview_flutter.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

// 淘宝详情图加载
class TaobaoImageLoader extends StatefulWidget {
class TaobaoImageWebviewLoader extends StatefulWidget {
final String url;
String script;
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) {
this.script = script;
if (EmptyUtil.isEmpty(this.script)) {
@@ -20,10 +20,11 @@ class TaobaoImageLoader extends StatefulWidget {
}

@override
_TaobaoImageLoaderState createState() => _TaobaoImageLoaderState();
_TaobaoImageWebviewLoaderState createState() =>
_TaobaoImageWebviewLoaderState();
}

class _TaobaoImageLoaderState extends State<TaobaoImageLoader> {
class _TaobaoImageWebviewLoaderState extends State<TaobaoImageWebviewLoader> {
WebViewController _webViewController;

List<String> _images = [];

+ 25
- 0
lib/util/taobao/taobao_loader.dart Dosyayı Görüntüle

@@ -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;
}
}

+ 2
- 1
lib/zhiying_comm.dart Dosyayı Görüntüle

@@ -26,6 +26,7 @@ export 'util/net_util.dart';
export 'util/page_factory.dart';
export 'util/router_util.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_factory.dart';

Yükleniyor…
İptal
Kaydet