From 08afb5d1da997621c2849cc5e9f4f6c37caf4a7a Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 4 Feb 2021 13:54:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E9=A2=98=E5=8D=A1?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 2 + lib/model/community/event_item_model.dart | 147 ++++++++++++++++++ .../topic/topic_detail_page.dart | 67 ++++++-- .../community_views/widgets/chat_card.dart | 84 +++++++++- lib/utils/bee_date_util.dart | 29 ++++ 5 files changed, 312 insertions(+), 17 deletions(-) create mode 100644 lib/model/community/event_item_model.dart create mode 100644 lib/utils/bee_date_util.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 49184be1..c7091cb0 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -162,6 +162,8 @@ class _Community { ///社区话题:查询最新的所有主题信息 String get topicList => '/user/gambit/list'; + + String get eventByTopicId => '/user/gambit/listByGambitId'; } class _Upload { diff --git a/lib/model/community/event_item_model.dart b/lib/model/community/event_item_model.dart new file mode 100644 index 00000000..cc917799 --- /dev/null +++ b/lib/model/community/event_item_model.dart @@ -0,0 +1,147 @@ +import 'package:akuCommunity/model/common/img_model.dart'; +import 'package:common_utils/common_utils.dart'; + +class EventItemModel { + int id; + int createId; + int isComment; + int isLike; + String createName; + String content; + String gambitTitle; + String createDate; + List likeNames; + List imgUrls; + List headSculptureImgUrl; + List gambitThemeCommentVoList; + DateTime get date => DateUtil.getDateTime(createDate); + EventItemModel( + {this.id, + this.createId, + this.isComment, + this.isLike, + this.createName, + this.content, + this.gambitTitle, + this.createDate, + this.likeNames, + this.imgUrls, + this.headSculptureImgUrl, + this.gambitThemeCommentVoList}); + + EventItemModel.fromJson(Map json) { + id = json['id']; + createId = json['createId']; + isComment = json['isComment']; + isLike = json['isLike']; + createName = json['createName']; + content = json['content']; + gambitTitle = json['gambitTitle']; + createDate = json['createDate']; + if (json['likeNames'] != null) { + likeNames = new List(); + json['likeNames'].forEach((v) { + likeNames.add(new LikeNames.fromJson(v)); + }); + } + if (json['imgUrls'] != null) { + imgUrls = new List(); + json['imgUrls'].forEach((v) { + imgUrls.add(new ImgModel.fromJson(v)); + }); + } else + imgUrls = []; + if (json['headSculptureImgUrl'] != null) { + headSculptureImgUrl = new List(); + json['headSculptureImgUrl'].forEach((v) { + headSculptureImgUrl.add(new ImgModel.fromJson(v)); + }); + } else + headSculptureImgUrl = []; + if (json['gambitThemeCommentVoList'] != null) { + gambitThemeCommentVoList = new List(); + json['gambitThemeCommentVoList'].forEach((v) { + gambitThemeCommentVoList.add(new GambitThemeCommentVoList.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['createId'] = this.createId; + data['isComment'] = this.isComment; + data['isLike'] = this.isLike; + data['createName'] = this.createName; + data['content'] = this.content; + data['gambitTitle'] = this.gambitTitle; + data['createDate'] = this.createDate; + if (this.likeNames != null) { + data['likeNames'] = this.likeNames.map((v) => v.toJson()).toList(); + } + if (this.imgUrls != null) { + data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList(); + } + if (this.headSculptureImgUrl != null) { + data['headSculptureImgUrl'] = + this.headSculptureImgUrl.map((v) => v.toJson()).toList(); + } + if (this.gambitThemeCommentVoList != null) { + data['gambitThemeCommentVoList'] = + this.gambitThemeCommentVoList.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class LikeNames { + int id; + String name; + + LikeNames({this.id, this.name}); + + LikeNames.fromJson(Map json) { + id = json['id']; + name = json['name']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['name'] = this.name; + return data; + } +} + +class GambitThemeCommentVoList { + int id; + String parentName; + String content; + String createName; + String createDate; + + GambitThemeCommentVoList( + {this.id, + this.parentName, + this.content, + this.createName, + this.createDate}); + + GambitThemeCommentVoList.fromJson(Map json) { + id = json['id']; + parentName = json['parentName']; + content = json['content']; + createName = json['createName']; + createDate = json['createDate']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['parentName'] = this.parentName; + data['content'] = this.content; + data['createName'] = this.createName; + data['createDate'] = this.createDate; + return data; + } +} diff --git a/lib/ui/community/community_views/topic/topic_detail_page.dart b/lib/ui/community/community_views/topic/topic_detail_page.dart index 32dd8457..704d41a6 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -1,7 +1,12 @@ +import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/model/community/community_topic_model.dart'; +import 'package:akuCommunity/model/community/event_item_model.dart'; +import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart'; import 'package:akuCommunity/ui/community/community_views/topic/topic_sliver_header.dart'; +import 'package:akuCommunity/ui/community/community_views/widgets/chat_card.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; class TopicDetailPage extends StatefulWidget { final CommunityTopicModel model; @@ -13,24 +18,56 @@ class TopicDetailPage extends StatefulWidget { } class _TopicDetailPageState extends State { + EasyRefreshController _refreshController = EasyRefreshController(); + @override + void dispose() { + _refreshController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( - body: CustomScrollView( - slivers: [ - SliverPersistentHeader( - delegate: TopicSliverHeader( - id: widget.model.id, - title: 'TEST', - imgPath: widget.model.firstImg, - subTitle: widget.model.content, - ), - pinned: true, - ), - SliverToBoxAdapter( - child: 40000.hb, - ), - ], + body: BeeListView( + convert: (model) { + return model.tableList + .map((e) => EventItemModel.fromJson(e)) + .toList(); + }, + path: API.community.eventByTopicId, + extraParams: {'gambitId': widget.model.id}, + controller: _refreshController, + builder: (items) { + return CustomScrollView( + slivers: [ + SliverPersistentHeader( + delegate: TopicSliverHeader( + id: widget.model.id, + title: 'TEST', + imgPath: widget.model.firstImg, + subTitle: widget.model.content, + ), + pinned: true, + floating: true, + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (context, index) { + final item = items[index] as EventItemModel; + return ChatCard( + name: item.createName, + title: item.gambitTitle, + headImg: item.headSculptureImgUrl, + contentImg: item.imgUrls, + date: item.date, + ); + }, + childCount: items.length, + ), + ), + ], + ); + }, ), ); } diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index f22fa476..4d0e6fbd 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -1,17 +1,97 @@ +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/common/img_model.dart'; +import 'package:akuCommunity/utils/bee_date_util.dart'; +import 'package:akuCommunity/utils/headers.dart'; import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; class ChatCard extends StatefulWidget { final String name; final String title; - ChatCard({Key key, this.name, this.title}) : super(key: key); + final List headImg; + final List contentImg; + final DateTime date; + final bool canDelete; + ChatCard({ + Key key, + this.name, + this.title, + this.headImg, + this.contentImg, + @required this.date, + this.canDelete, + }) : super(key: key); @override _ChatCardState createState() => _ChatCardState(); } class _ChatCardState extends State { + String get firstHead { + if (widget.headImg == null || widget.headImg.isEmpty) + return ''; + else + return widget.headImg.first.url; + } + + _renderImage() { + if (widget.contentImg.isEmpty) return SizedBox(); + if (widget.contentImg.length == 1) + return ConstrainedBox( + constraints: BoxConstraints( + maxHeight: 300.w, + minWidth: 300.w, + ), + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image(widget.contentImg.first.url), + ), + ); + } + @override Widget build(BuildContext context) { - return Container(); + return DecoratedBox( + decoration: BoxDecoration( + color: Colors.white, + border: Border( + bottom: BorderSide( + color: Color(0xFFE5E5E5), + ), + ), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Material( + color: Color(0xFFF5F5F5), + borderRadius: BorderRadius.circular(6.w), + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image(firstHead), + height: 86.w, + width: 86.w, + ), + ), + 24.wb, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.name.text.size(36.sp).make(), + 6.hb, + widget.title.text.make(), + 20.hb, + _renderImage(), + Row( + children: [ + BeeDateUtil(widget.date).timeAgo.text.make(), + Spacer(), + ], + ), + ], + ).expand(), + ], + ).p(20.w), + ); } } diff --git a/lib/utils/bee_date_util.dart b/lib/utils/bee_date_util.dart new file mode 100644 index 00000000..2f16b4ad --- /dev/null +++ b/lib/utils/bee_date_util.dart @@ -0,0 +1,29 @@ +import 'package:common_utils/common_utils.dart'; + +class BeeDateUtil { + DateTime date; + BeeDateUtil(this.date); + DateTime get _now => DateTime.now(); + bool get sameYear => _now.year == this.date.year; + bool get sameMonth => sameYear && _now.month == this.date.month; + bool get sameDay => sameMonth && _now.day == this.date.day; + bool get isYesterday => (DateTime(_now.year, _now.month, _now.day - 1) + .compareTo(DateTime(this.date.year)) == + 0); + bool get isDoubleYesterday => (DateTime(_now.year, _now.month, _now.day - 2) + .compareTo(DateTime(this.date.year)) == + 0); + + String get timeAgo { + Duration duration = _now.difference(date); + if (duration.inSeconds <= 60) return '${duration.inSeconds}秒前'; + if (duration.inMinutes <= 60) return '${duration.inMinutes}分钟前'; + if (duration.inHours <= 12) return '${duration.inHours}小时前'; + if (isYesterday) return '昨天'; + if (isDoubleYesterday) return '前天'; + if (duration.inDays <= 30) + return '${duration.inDays}天前'; + else + return DateUtil.formatDate(date, format: 'yyyy-MM-dd'); + } +}