From a47fd28cbe4f04d4bb49c81bbad3e7daa8e85e67 Mon Sep 17 00:00:00 2001 From: huixiang_app <953969641@qq.com> Date: Mon, 28 Aug 2023 11:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E6=8E=A8=E5=B9=BFbanner=E6=9B=B4=E6=94=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/home/home_page.dart | 28 +--------- lib/mine/mine_page.dart | 110 ++++++++++++++++++++++++++++++++-------- 2 files changed, 90 insertions(+), 48 deletions(-) diff --git a/lib/home/home_page.dart b/lib/home/home_page.dart index c6bf0ad8..b18eeb24 100644 --- a/lib/home/home_page.dart +++ b/lib/home/home_page.dart @@ -656,7 +656,7 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { width: double.infinity, // margin: EdgeInsets.symmetric(horizontal:14.w), height: 85.h, - child: bannerData != null && bannerData.isNotEmpty + child: activityBannerData != null && activityBannerData.isNotEmpty ? Swiper( pagination: SwiperPagination( alignment: Alignment.bottomCenter, @@ -688,27 +688,6 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { ), ), ); - // GestureDetector( - // onTap: () { - // if (position == 0) { - // Navigator.of(context).pushNamed('/router/invite_friends'); - // } else if (position == 1) { - // Navigator.of(context).pushNamed('/router/trading_card_page'); - // } - // }, - // child: Container( - // margin: EdgeInsets.symmetric(horizontal: 14.w), - // child: ClipRRect( - // child: Image.asset( - // spreadItem[position], - // width: double.infinity, - // fit: BoxFit.fill, - // height: double.infinity, - // ), - // borderRadius: BorderRadius.circular(6.w), - // ), - // ), - // ); }, itemCount: activityBannerData.length, ) @@ -766,11 +745,6 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { } } - final List spreadItem = [ - "assets/image/welfare_spread.webp", - "assets/image/welfare_yz.webp", - ]; - ///扫码 toScan() async { if (await Permission.camera.isPermanentlyDenied) { diff --git a/lib/mine/mine_page.dart b/lib/mine/mine_page.dart index 98a91778..b6a7bf09 100644 --- a/lib/mine/mine_page.dart +++ b/lib/mine/mine_page.dart @@ -26,9 +26,11 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:dio/dio.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import '../retrofit/data/banner.dart'; import '../retrofit/data/coupon.dart'; import '../retrofit/data/page.dart'; import '../utils/flutter_utils.dart'; +import '../view_widget/custom_image.dart'; import 'mine_view/mine_item.dart'; import 'mine_view/mine_view.dart'; @@ -49,6 +51,7 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { final RefreshController _refreshController = RefreshController(); int totalMsg = 0; String couponNum; + List activityBannerData = []; _toUserInfo() async { SharedPreferences shared = await SharedPreferences.getInstance(); @@ -78,6 +81,7 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { querySocialInfo(); queryMsgStats(); queryCoupon(); + queryActivityBanner(); // queryCard(); eventBus.on().listen((event) { @@ -136,6 +140,23 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { // EasyLoading.dismiss(); } + ///宣传banner + queryActivityBanner() async { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService( + Dio(), + context: context, + token: value.getString("token"), + showLoading: false, + ); + BaseData> baseData = await apiService.queryBanner({ + "model": {"type": "HOME_STORE_PAGE"}, + }).catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + activityBannerData = baseData.data.records; + } + } + queryCoupon() async { SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( @@ -166,6 +187,7 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { queryCoupon(); querySocialInfo(); queryMsgStats(); + queryActivityBanner(); } ///个人社交信息(粉丝/关注数量/成就数量) @@ -427,10 +449,11 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { ///推广图 Widget spreadImage() { return Container( - margin: EdgeInsets.only(bottom: 30.h,), width: double.infinity, + // margin: EdgeInsets.symmetric(horizontal:14.w), height: 85.h, - child: Swiper( + child: activityBannerData != null && activityBannerData.isNotEmpty + ? Swiper( pagination: SwiperPagination( alignment: Alignment.bottomCenter, margin: EdgeInsets.only(top: 5.h), @@ -442,37 +465,82 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { color: Colors.white.withAlpha(76), ), ), - autoplay:true, + autoplay: true, duration: 1000, autoplayDelay: 2000, itemBuilder: (context, position) { - return GestureDetector( - onTap: (){ - if(position == 0){ - Navigator.of(context).pushNamed('/router/invite_friends'); - }else if(position == 1){ - Navigator.of(context).pushNamed('/router/trading_card_page'); - } + return InkWell( + onTap: () { + spreadBannerClick(activityBannerData[position]); }, - child:Container( - margin: EdgeInsets.symmetric(horizontal:14.w), - child: ClipRRect( - child:Image.asset( - spreadItem[position], - width:double.infinity, - fit: BoxFit.fill, - height:double.infinity, - ), - borderRadius: BorderRadius.circular(6.w), + child: Container( + margin: EdgeInsets.symmetric(horizontal: 14.w), + child: MImage( + activityBannerData[position].imgUrl, + fit: BoxFit.cover, + radius: BorderRadius.circular(6), + errorSrc: "assets/image/default_2_1.webp", + fadeSrc: "assets/image/default_2_1.webp", ), ), ); }, - itemCount:2, + itemCount: activityBannerData.length, + ) + : Image.asset( + "assets/image/default_2_1.webp", + fit: BoxFit.cover, ), ); } + /// contentType 跳转类型(0:不跳转,1:积分商品,2:活动,3:文章,4:页面跳转,5:课程,7:门店跳转) + spreadBannerClick(BannerData activityBannerData) async { + switch (activityBannerData.contentType) { + case 1: + Navigator.of(context).pushNamed('/router/integral_store_page', + arguments: {"goodsId": activityBannerData.content}); + break; + case 2: + Navigator.of(context).pushNamed('/router/web_page', arguments: { + "activityId": activityBannerData.content, + }); + break; + case 3: + Navigator.of(context).pushNamed('/router/web_page', arguments: { + "articleId": activityBannerData.content, + }); + break; + case 4: + String router = activityBannerData.content; + // String router = "/router/store_order?{\"id\":\"1512378184161558528\",\"tenant\":\"1188\",\"storeName\":\"农场煮意\"}"; + if (router.contains("?")) { + String params = router.substring(router.indexOf("?") + 1); + Map map = jsonDecode(params); + Navigator.of(context).pushNamed( + router.substring(0, router.indexOf("?")), + arguments: map); + } else { + Navigator.of(context).pushNamed(router); + } + break; + case 5: + Navigator.of(context).pushNamed('/router/class_details', arguments: { + "id": activityBannerData.content, + }); + break; + case 7: + String params = activityBannerData.content + .substring(activityBannerData.content.indexOf("?") + 1); + Map map = jsonDecode(params); + Navigator.of(context).pushNamed( + activityBannerData.content + .substring(0, activityBannerData.content.indexOf("?")), + arguments: map); + break; + } + } + final List spreadItem = [ "assets/image/welfare_spread.webp", "assets/image/welfare_yz.webp",