From 7cc566fe79270d5826d943a9c31278d40551bb61 Mon Sep 17 00:00:00 2001 From: ZHR007 Date: Tue, 9 Dec 2025 10:22:56 +0800 Subject: [PATCH] no message --- .../discover/visitor_controller.dart | 40 ++--- lib/pages/discover/visitor_list_page.dart | 167 +++++++++--------- 2 files changed, 98 insertions(+), 109 deletions(-) diff --git a/lib/controller/discover/visitor_controller.dart b/lib/controller/discover/visitor_controller.dart index e3283cd..6547892 100644 --- a/lib/controller/discover/visitor_controller.dart +++ b/lib/controller/discover/visitor_controller.dart @@ -16,8 +16,9 @@ class VisitorController extends GetxController { // 分页参数 var currentPage = 1.obs; - final int pageSize = 15; + final int pageSize = 10; var hasMore = true.obs; + var total = 0.obs; var isLoading = false.obs; late final UserApi _userApi; @@ -81,30 +82,16 @@ class VisitorController extends GetxController { Get.snackbar('成功', '已删除访客记录'); } - // 获取今日访客数量 - int get todayVisitorsCount { - return visitors.length; - } - - // 获取在线访客数量 - int get onlineVisitorsCount { - return visitors.length; - } - Future> _fetchVisitorData({required int pageNum}) async { try { - print('_fetchVisitorData - pageNum: $pageNum, pageSize: $pageSize'); // 调用API获取数据 - var response = await _userApi.getVisitorList( - pageNum: pageNum, - pageSize: pageSize, - ); + var response = await _userApi.getVisitorList(pageNum: pageNum, pageSize: pageSize); if (response.data.isSuccess) { - final paginatedData = response.data.data; + final data = response.data.data; // 检查data是否为空 - if (paginatedData == null) { + if (data == null) { return { 'records': [], 'current': pageNum, @@ -113,18 +100,13 @@ class VisitorController extends GetxController { 'size': pageSize, }; } - - // data 是 PaginatedResponse,直接使用其属性 - // records 中的每个项是 dynamic,需要转换为 MarriageData - final records = paginatedData.records - .map((item) => MarriageData.fromJson(item as Map)) - .toList(); + total.value = data.total; return { - 'records': records, - 'current': paginatedData.current, - 'pages': paginatedData.pages, - 'total': paginatedData.total, - 'size': paginatedData.size, + 'records': data.records, + 'current': data.current, + 'pages': data.pages, + 'total': data.total, + 'size': data.size, }; } else { // 响应失败,抛出异常 diff --git a/lib/pages/discover/visitor_list_page.dart b/lib/pages/discover/visitor_list_page.dart index 056f25f..30cbea1 100644 --- a/lib/pages/discover/visitor_list_page.dart +++ b/lib/pages/discover/visitor_list_page.dart @@ -7,7 +7,10 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../controller/discover/visitor_controller.dart'; +import '../../controller/global.dart'; +import '../../generated/assets.dart'; import '../../model/home/marriage_data.dart'; +import '../home/user_information_page.dart'; class VisitorListPage extends StatefulWidget { const VisitorListPage({super.key}); @@ -26,7 +29,7 @@ class _VisitorListPagePageState extends State { backgroundColor: Color(0xffF5F5F5), appBar: AppBar( title: Obx(() => Text( - '最近访客 (${visitorController.todayVisitorsCount})', + '最近访客 (${visitorController.total.value})', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), )), centerTitle: true, @@ -90,19 +93,18 @@ class _VisitorListPagePageState extends State { noMoreText: '没有更多数据', showMessage: false, ), - child: ListView.separated( - padding: const EdgeInsets.only(top: 10, right: 10, left: 10), + child: GridView.builder( + padding: EdgeInsets.only(top: 8.w, left: 10.w, right: 8.w, bottom: 0.w), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, // 每行2个 + crossAxisSpacing: 4.w, // 左右间距 + mainAxisSpacing: 4.w, // 上下间距 + childAspectRatio: 1, // 宽高比 + ), itemCount: visitorController.visitors.length, itemBuilder: (context, index) { final visitor = visitorController.visitors[index]; - return VisitorListItem(visitor: visitor); - }, - separatorBuilder: (context, index) { - // 空状态或加载状态时不显示分隔符 - if (visitorController.visitors.isEmpty) { - return const SizedBox.shrink(); - } - return const SizedBox(height: 10); + return VisitorItem(visitor: visitor); }, ), ); @@ -112,96 +114,101 @@ class _VisitorListPagePageState extends State { } -class VisitorListItem extends StatelessWidget { +class VisitorItem extends StatelessWidget { final MarriageData visitor; - const VisitorListItem({Key? key, required this.visitor}) : super(key: key); + const VisitorItem({Key? key, required this.visitor}) : super(key: key); @override Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(12), - ), - padding: const EdgeInsets.all(12), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, + return Stack( children: [ - // 左侧图片 - Container( - width: 50, - height: 50, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: Colors.blue[100], - image: DecorationImage( - image: NetworkImage(visitor.profilePhoto), - fit: BoxFit.cover, + ClipRRect( + borderRadius: BorderRadius.all(Radius.circular(10.w)), + child: CachedNetworkImage( + imageUrl: "${visitor.profilePhoto}?x-oss-process=image/format,webp/resize,w_240", + width: 173.w, + height: 173.w, + fit: BoxFit.cover, + placeholder: (context, url) => Container( + color: Colors.white38, + child: Center( + child: CircularProgressIndicator( + strokeWidth: 1.w, + color: Colors.grey, + ), + ), ), + errorWidget: (context, url, error) => + Image.asset( + Assets.imagesUserAvatar, + width: 173.w, + height: 173.w, + fit: BoxFit.cover, + ), ), ), - SizedBox(width: 12), - Expanded( + Positioned( + left: 8.w, + bottom: 12.w, child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - Text( - visitor.nickName, - style: TextStyle( - fontSize: 14, - ), - ), - Spacer(), - // Text( - // _formatTime(visitor.visitTime!), - // style: TextStyle( - // color: Colors.grey[500], - // fontSize: 13, - // ), - // ), - ], - ), - SizedBox(height: 4), - SizedBox( - // height: 20, // 固定高度20 - child: Text( - visitor.describeInfo, + if(visitor.describeInfo.isNotEmpty)SizedBox( + width: 156.w, + child: Text(visitor.describeInfo, + maxLines: 1, + overflow: TextOverflow.ellipsis, style: TextStyle( - fontSize: 13, - color: Color.fromRGBO(51, 51, 51, 0.6), + fontSize: 12.w, + color: Colors.white, + fontWeight: FontWeight.w500, ), - overflow: TextOverflow.ellipsis, // 文本超出显示... - maxLines: 1, // 限制为单行 ), ), + SizedBox(height: 2.w), + SizedBox( + width: 156.w, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "${visitor.cityName.isNotEmpty ? '${visitor.cityName} | ' : ''}${visitor.age}岁", + style: TextStyle( + fontSize: 14.w, + color: Colors.white, + fontWeight: FontWeight.w500, + ), + ), + Text('访问1次', style: TextStyle(color: Color(0xffA799FF), fontSize: 12.w)) + ], + ), + ) ], - ) + ), ) ], - ), ).onTap((){ - // _showVisitorDetail(visitor); + Get.to(() => UserInformationPage(miId: visitor.miId, userId: GlobalData().userId!)); }); } - String _formatTime(String timestamp) { - var time = DateTime.parse(timestamp); - final now = DateTime.now(); - final difference = now.difference(time); - - if (difference.inMinutes < 1) { - return '刚刚'; - } else if (difference.inHours < 1) { - return '${difference.inMinutes}分钟前'; - } else if (difference.inDays < 1) { - return '${difference.inHours}小时前'; - } else if (difference.inDays < 7) { - return '${difference.inDays}天前'; - } else { - return '${time.month}/${time.day}'; - } - } + // String _formatTime(String timestamp) { + // var time = DateTime.parse(timestamp); + // final now = DateTime.now(); + // final difference = now.difference(time); + // + // if (difference.inMinutes < 1) { + // return '刚刚'; + // } else if (difference.inHours < 1) { + // return '${difference.inMinutes}分钟前'; + // } else if (difference.inDays < 1) { + // return '${difference.inHours}小时前'; + // } else if (difference.inDays < 7) { + // return '${difference.inDays}天前'; + // } else { + // return '${time.month}/${time.day}'; + // } + // } } \ No newline at end of file