diff --git a/lib/controller/home/home_controller.dart b/lib/controller/home/home_controller.dart index 04e837b..43978f7 100644 --- a/lib/controller/home/home_controller.dart +++ b/lib/controller/home/home_controller.dart @@ -1,3 +1,4 @@ +import 'package:dating_touchme_app/model/home/banner_data.dart'; import 'package:get/get.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import '../../network/home_api.dart'; @@ -6,6 +7,8 @@ import '../../model/home/marriage_data.dart'; class HomeController extends GetxController { // 推荐列表数据 final recommendFeed = [].obs; + // 推荐列表数据 + final bannerLint = [].obs; // 同城列表数据 final nearbyFeed = [].obs; @@ -39,6 +42,28 @@ class HomeController extends GetxController { _homeApi = Get.find(); // 初始化时加载数据 loadInitialData(); + getBannerList(); + } + + + + getBannerList() async { + try{ + final response = await _homeApi.userPageBannerByCustomer(); + if (response.data.isSuccess && response.data.data != null) { + final data = response.data.data?.records ?? []; + + bannerLint.addAll(data.toList()); + } else { + + // 响应失败,抛出异常 + throw Exception(response.data.message ?? '获取数据失败'); + } + } catch(e) { + print('玫瑰记录获取失败: $e'); + SmartDialog.showToast('玫瑰记录获取失败'); + rethrow; + } } /// 加载初始数据(同时加载两个标签页的数据) diff --git a/lib/model/home/banner_data.dart b/lib/model/home/banner_data.dart new file mode 100644 index 0000000..b482067 --- /dev/null +++ b/lib/model/home/banner_data.dart @@ -0,0 +1,87 @@ +class BannerData { + List? records; + int? total; + int? size; + int? current; + int? pages; + + BannerData({this.records, this.total, this.size, this.current, this.pages}); + + BannerData.fromJson(Map json) { + if (json['records'] != null) { + records = []; + json['records'].forEach((v) { + records!.add(new Records.fromJson(v)); + }); + } + total = json['total']; + size = json['size']; + current = json['current']; + pages = json['pages']; + } + + Map toJson() { + final Map data = new Map(); + if (this.records != null) { + data['records'] = this.records!.map((v) => v.toJson()).toList(); + } + data['total'] = this.total; + data['size'] = this.size; + data['current'] = this.current; + data['pages'] = this.pages; + return data; + } +} + +class Records { + String? id; + String? appId; + int? noticeType; + String? image; + int? jumpType; + String? jumpValue; + String? startTime; + String? endTime; + bool? enable; + Null? remark; + + Records( + {this.id, + this.appId, + this.noticeType, + this.image, + this.jumpType, + this.jumpValue, + this.startTime, + this.endTime, + this.enable, + this.remark}); + + Records.fromJson(Map json) { + id = json['id']; + appId = json['appId']; + noticeType = json['noticeType']; + image = json['image']; + jumpType = json['jumpType']; + jumpValue = json['jumpValue']; + startTime = json['startTime']; + endTime = json['endTime']; + enable = json['enable']; + remark = json['remark']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['appId'] = this.appId; + data['noticeType'] = this.noticeType; + data['image'] = this.image; + data['jumpType'] = this.jumpType; + data['jumpValue'] = this.jumpValue; + data['startTime'] = this.startTime; + data['endTime'] = this.endTime; + data['enable'] = this.enable; + data['remark'] = this.remark; + return data; + } +} diff --git a/lib/network/api_urls.dart b/lib/network/api_urls.dart index af5cddb..72dd05b 100644 --- a/lib/network/api_urls.dart +++ b/lib/network/api_urls.dart @@ -146,6 +146,9 @@ class ApiUrls { static const String userQuitSiteActivity = 'dating-agency-service/user/quit/site/activity'; + static const String userPageBannerByCustomer = + 'dating-agency-service/user/page/banner/by/customer'; + // 后续可以在此添加更多API端点 static const String listMatchmakerProduct = 'dating-agency-mall/user/page/product/by/matchmaker'; diff --git a/lib/network/home_api.dart b/lib/network/home_api.dart index 54c1793..0e1a11b 100644 --- a/lib/network/home_api.dart +++ b/lib/network/home_api.dart @@ -1,3 +1,4 @@ +import 'package:dating_touchme_app/model/home/banner_data.dart' hide Records; import 'package:dating_touchme_app/model/home/event_data.dart'; import 'package:dating_touchme_app/model/home/event_list_data.dart' hide Records; import 'package:dating_touchme_app/model/home/post_comment_data.dart' hide Records; @@ -91,4 +92,8 @@ abstract class HomeApi { Future>> userQuitSiteActivity( @Body() Map data, ); + + @GET(ApiUrls.userPageBannerByCustomer) + Future>> userPageBannerByCustomer(); + } \ No newline at end of file diff --git a/lib/network/home_api.g.dart b/lib/network/home_api.g.dart index ad29ef8..57dc8cd 100644 --- a/lib/network/home_api.g.dart +++ b/lib/network/home_api.g.dart @@ -490,6 +490,38 @@ class _HomeApi implements HomeApi { return httpResponse; } + @override + Future>> + userPageBannerByCustomer() async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + const Map? _data = null; + final _options = _setStreamType>>( + Options(method: 'GET', headers: _headers, extra: _extra) + .compose( + _dio.options, + 'dating-agency-service/user/page/banner/by/customer', + queryParameters: queryParameters, + data: _data, + ) + .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), + ); + final _result = await _dio.fetch>(_options); + late BaseResponse _value; + try { + _value = BaseResponse.fromJson( + _result.data!, + (json) => BannerData.fromJson(json as Map), + ); + } on Object catch (e, s) { + errorLogger?.logError(e, s, _options); + rethrow; + } + final httpResponse = HttpResponse(_value, _result); + return httpResponse; + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes || diff --git a/lib/pages/home/event_list.dart b/lib/pages/home/event_list.dart index 38538a3..4bb86c7 100644 --- a/lib/pages/home/event_list.dart +++ b/lib/pages/home/event_list.dart @@ -9,7 +9,8 @@ import 'package:easy_refresh/easy_refresh.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; -import 'package:tdesign_flutter/tdesign_flutter.dart';import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart'; +import 'package:tdesign_flutter/tdesign_flutter.dart'; +import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart'; class EventList extends StatelessWidget { const EventList({super.key}); diff --git a/lib/pages/home/recommend_tab.dart b/lib/pages/home/recommend_tab.dart index c5388a0..41bbeff 100644 --- a/lib/pages/home/recommend_tab.dart +++ b/lib/pages/home/recommend_tab.dart @@ -12,6 +12,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:dating_touchme_app/controller/home/home_controller.dart'; import 'package:dating_touchme_app/pages/home/content_card.dart'; +import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart'; +import 'package:tdesign_flutter/tdesign_flutter.dart'; /// 推荐列表 Tab class RecommendTab extends StatefulWidget { @@ -255,13 +257,44 @@ class _RecommendTabState extends State ), Container( padding: EdgeInsets.symmetric(horizontal: 12), - child: Image.asset( - Assets.imagesBanner, - width: 375.w - 24, + height: 90.w, + child: Swiper( + autoplay: true, + itemCount: controller.bannerLint.length, + loop: true, + onTap: (int index){ + print(index); + if(controller.bannerLint[index].jumpType == 2){ + Get.to(() => OpenWebView(url: controller.bannerLint[index].jumpValue ?? "")); + } else if(controller.bannerLint[index].jumpType == 3){ + TDImageViewer.showImageViewer(context: context, images: [controller.bannerLint[index].jumpValue ?? ""]); + } + }, + itemBuilder: (BuildContext context, int index) { + return CachedNetworkImage( + imageUrl: controller.bannerLint[index].image ?? "", + height: 90.w, + fit: BoxFit.cover, + + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ), + ), + ), + errorWidget: (context, url, error) => Image.asset( + Assets.imagesUserAvatar, + width: 165.w, + height: 165.w, + fit: BoxFit.cover, + ), + ); + }, ), - ).onTap((){ - Get.to(() => OpenWebView(url: "https://www.quzhaoqin.com/")); - }), + ), ListView.separated( shrinkWrap: true, // ⭐ 关键 1:高度由内容决定 physics: const NeverScrollableScrollPhysics(), // ⭐ 关键 2:禁用自身滚动