diff --git a/lib/community/community_view/community_dynamic.dart b/lib/community/community_view/community_dynamic.dart index d026201e..b55d6a9c 100644 --- a/lib/community/community_view/community_dynamic.dart +++ b/lib/community/community_view/community_dynamic.dart @@ -174,6 +174,7 @@ class _CommunityDynamic extends State { "memberId": (widget.article.author == widget.userId) ? "0" : widget.article.author, + "inletType":0 }); widget.exitFull(); } diff --git a/lib/im/SocketClient.dart b/lib/im/SocketClient.dart index 157b6281..de946e28 100644 --- a/lib/im/SocketClient.dart +++ b/lib/im/SocketClient.dart @@ -19,7 +19,8 @@ class SocketClient { connect() async { shared = await SharedPreferences.getInstance(); - await Socket.connect('192.168.10.129', 9090).then((value) { + //47.93.216.24:9090 线上 192.168.10.129:9090 测试 + await Socket.connect('47.93.216.24', 9090).then((value) { debugPrint("socket-connect"); _socket = value; _socket.listen((data) { @@ -38,6 +39,7 @@ class SocketClient { }, onError: (Object error, StackTrace stackTrace) { debugPrint("socket-listen-error: $error, stackTrace: $stackTrace"); + reconnect(); }, onDone: () { debugPrint("socket-listen-down: down"); }); diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index e8e2ab45..5c1c4987 100644 --- a/lib/im/chat_details_page.dart +++ b/lib/im/chat_details_page.dart @@ -97,19 +97,20 @@ class _ChatDetailsPage extends State } Future refresh() async { - List messagePage = await hxDatabase.queryUList(_toUser.mid, page: page + 1, pageSize: 10); - if (messagePage.isEmpty) { - refreshController.loadNoData(); - return; - } else { - refreshController.loadComplete(); - } + List messagePage = + await hxDatabase.queryUList(_toUser.mid, page: page + 1, pageSize: 10); page += 1; if (page == 1) { messages = messagePage; } else { messages.addAll(messagePage); } + if (messagePage.isEmpty) { + refreshController.loadNoData(); + return; + } else { + refreshController.loadComplete(); + } return Future.value(); } @@ -155,7 +156,8 @@ class _ChatDetailsPage extends State void jumpToBottom() { Future.delayed(const Duration(milliseconds: 100), () { - scrollController.position.jumpTo(scrollController.position.maxScrollExtent); + scrollController.position + .jumpTo(scrollController.position.maxScrollExtent); }); } @@ -326,11 +328,16 @@ class _ChatDetailsPage extends State leadingColor: Colors.black, action: GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - setState(() { - Navigator.of(context).pushNamed('/router/chat_setting',arguments: {"userId": _toUser.mid}); - copyIndex = 0; + onTap: () async { + await Navigator.of(context).pushNamed('/router/chat_setting', + arguments: {"userId": _toUser.mid}); + page = 0; + refresh().then((value) { + refreshState(); }); + // setState(() { + // copyIndex = 0; + // }); }, child: Container( alignment: Alignment.center, @@ -355,9 +362,10 @@ class _ChatDetailsPage extends State footer: CustomFooter( loadStyle: LoadStyle.ShowWhenLoading, builder: (BuildContext context, LoadStatus mode) { - return (messages.length == 0) - ? Container() - : MyFooter(mode); + // return (messages.length == 0) + // ? Container() + // : MyFooter(mode); + return SizedBox(); }, ), controller: refreshController, @@ -367,10 +375,9 @@ class _ChatDetailsPage extends State }); }, child: SingleChildScrollView( - physics: BouncingScrollPhysics(), - controller: scrollController, - child: chatDetailsList() - ), + physics: BouncingScrollPhysics(), + controller: scrollController, + child: chatDetailsList()), ), flex: 1, ), @@ -378,8 +385,7 @@ class _ChatDetailsPage extends State ], ), ), - ) - ); + )); } ///聊天列表 @@ -397,18 +403,19 @@ class _ChatDetailsPage extends State onTap: () { setState(() { copyIndex = 0; + FocusScope.of(context).requestFocus(FocusNode()); }); }, - child: chatDetailsItem(messages[position]), + child: chatDetailsItem(position), ); }, ), ); } - Widget chatDetailsItem(Message message) { - bool isSelf = message.fromId == selfUserId; - bool isText = message.msgType == 1; + Widget chatDetailsItem(position) { + bool isSelf = messages[position].fromId == selfUserId; + bool isText = messages[position].msgType == 1; return Container( padding: EdgeInsets.only( top: 32.h, @@ -416,8 +423,16 @@ class _ChatDetailsPage extends State child: Column( children: [ Text( - AppUtils.timeFormatter( - DateTime.fromMillisecondsSinceEpoch(int.parse(message.time))), + // position == messages.length-1 + // ? + AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch( + int.parse(messages[position].time))) + // : AppUtils.getTimeDisplay( + // DateTime.fromMillisecondsSinceEpoch( + // int.parse(messages[position].time)), + // DateTime.fromMillisecondsSinceEpoch( + // int.parse(messages[position+1].time))) + , textAlign: TextAlign.center, style: TextStyle( color: Color(0xFFA29E9E), @@ -537,15 +552,24 @@ class _ChatDetailsPage extends State padding: EdgeInsets.only(left: 17.w, right: 39.w), child: Row( children: [ - MImage( - _toUser.avatar, - isCircle: true, - height: 44.h, - width: 44.h, - fit: BoxFit.cover, - errorSrc: "assets/image/default_1.webp", - fadeSrc: "assets/image/default_1.webp", - ), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + Navigator.of(context).pushNamed('/router/personal_page', + arguments: { + "memberId": _toUser?.mid ?? "", + "inletType": 1 + }); + }, + child: MImage( + _toUser.avatar, + isCircle: true, + height: 44.h, + width: 44.h, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", + )), SizedBox( width: 12.w, ), @@ -576,7 +600,7 @@ class _ChatDetailsPage extends State }); }, child: Text( - tex = message.content, + tex = messages[position].content, textAlign: TextAlign.left, style: TextStyle( height: 1.2.h, @@ -686,7 +710,7 @@ class _ChatDetailsPage extends State padding: EdgeInsets.only(left: 36.w, right: 16.w), child: Row( children: [ - if (message.state == 3) + if (messages[position].state == 3) Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), @@ -705,7 +729,7 @@ class _ChatDetailsPage extends State ), ), ), - if (message.state == 3) + if (messages[position].state == 3) SizedBox( width: 12.w, ), @@ -736,7 +760,7 @@ class _ChatDetailsPage extends State }); }, child: Text( - tex = message.content, + tex = messages[position].content, textAlign: TextAlign.left, style: TextStyle( height: 1.2.h, @@ -752,20 +776,21 @@ class _ChatDetailsPage extends State SizedBox( width: 12.w, ), - MImage( - userInfo?.headimg ?? "", - isCircle: true, - height: 44.h, - width: 44.h, - fit: BoxFit.cover, - errorSrc: "assets/image/default_1.webp", - fadeSrc: "assets/image/default_1.webp", - ), - // Image.asset( - // "assets/image/fuka_zj.webp", - // height: 44, - // width: 44, - // ), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + Navigator.of(context).pushNamed('/router/personal_page', + arguments: {"memberId": "0", "inletType": 1}); + }, + child: MImage( + userInfo?.headimg ?? "", + isCircle: true, + height: 44.h, + width: 44.h, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", + )), ], ), ), diff --git a/lib/im/chat_setting.dart b/lib/im/chat_setting.dart index 1b175a05..603efc46 100644 --- a/lib/im/chat_setting.dart +++ b/lib/im/chat_setting.dart @@ -11,6 +11,7 @@ import 'package:flutter/cupertino.dart'; import '../../generated/l10n.dart'; import '../../utils/font_weight.dart'; import '../main.dart'; +import '../retrofit/data/im_user.dart'; class ChatSetting extends StatefulWidget { final Map arguments; @@ -23,13 +24,20 @@ class ChatSetting extends StatefulWidget { } } -class _ChatSetting extends State{ - ApiService apiService; - bool topSetting = false; +class _ChatSetting extends State { + ImUser imUser; @override void initState() { super.initState(); + initData(); + } + + void initData() async { + imUser = await hxDatabase.queryImUserById(widget.arguments["userId"]); + setState(() { + + }); } @override @@ -37,7 +45,7 @@ class _ChatSetting extends State{ return Scaffold( backgroundColor: Color(0xFFF9FAF7), appBar: MyAppBar( - title:"聊天设置", + title: "聊天设置", titleColor: Colors.black, titleSize: 18.sp, background: Colors.white, @@ -50,7 +58,7 @@ class _ChatSetting extends State{ Container( color: Colors.white, margin: EdgeInsets.symmetric(vertical: 14.h), - padding: EdgeInsets.symmetric(horizontal: 16.w,vertical: 14.h), + padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 14.h), child: Column( children: [ Row( @@ -61,52 +69,60 @@ class _ChatSetting extends State{ "置顶聊天", style: TextStyle( color: Color(0xFF353535), - fontSize:15.sp, + fontSize: 15.sp, fontWeight: MyFontWeight.semi_bold, ), ), CupertinoSwitch( - value: (topSetting), + value: ((imUser?.isTop ?? 0) == 1), activeColor: Color(0xFF32A060), - onChanged: (bool value) { - setState((){ - topSetting = !topSetting; - }); + onChanged: (bool value) async { + if (imUser == null) return; + imUser.isTop = value ? 1 : 0; + await hxDatabase + .insertOrUpdateImUser(imUser.toJson()); + setState(() {}); }, ), ], ), - SizedBox(height:31.h,), - GestureDetector(child: - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Text( - "清空聊天记录", - style: TextStyle( - color: Color(0xFF353535), - fontSize:15.sp, - fontWeight: MyFontWeight.semi_bold, + SizedBox( + height: 31.h, + ), + GestureDetector( + behavior: HitTestBehavior.opaque, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + "清空聊天记录", + style: TextStyle( + color: Color(0xFF353535), + fontSize: 15.sp, + fontWeight: MyFontWeight.semi_bold, + ), ), - ), - Image.asset( - "assets/image/icon_right_z.webp", - height:16, - width:16, - color: Colors.black, - ), - ], - ),onTap: ()async{ - // await hxDatabase.deleteByUser(widget.arguments["userId"]??""); - // SmartDialog.showToast("删除成功", - // alignment: Alignment.center); - },) + Image.asset( + "assets/image/icon_right_z.webp", + height: 16, + width: 16, + color: Colors.black, + ), + ], + ), + onTap: () async { + await hxDatabase + .deleteByUser(widget.arguments["userId"] ?? ""); + SmartDialog.showToast("删除成功", + alignment: Alignment.center); + }, + ) ], ), ), - Expanded(child: - Container( + Expanded( + child: Container( color: Colors.white, )) ], diff --git a/lib/im/database/hx_database.dart b/lib/im/database/hx_database.dart index ec2b78af..812cb451 100644 --- a/lib/im/database/hx_database.dart +++ b/lib/im/database/hx_database.dart @@ -27,6 +27,10 @@ class HxDatabase { 'CREATE TABLE IF NOT EXISTS `ImUser` (`id` INTEGER, `mid` VARCHAR(20), `nickname` VARCHAR(20), `avatar` VARCHAR(200), `phone` VARCHAR(200), `isDelete` INTEGER, PRIMARY KEY (`id`))'); }, onConfigure: (database) async { await database.execute('PRAGMA foreign_keys = ON'); + try { + await database.execute( + 'ALTER TABLE ImUser ADD COLUMN isTop INTEGER DEFAULT 0'); + }catch (e){} }, onUpgrade: (database, startVersion, endVersion) async { await runMigrations(database, startVersion, endVersion, _migrations); }, onOpen: (Database db) { diff --git a/lib/im/im_search.dart b/lib/im/im_search.dart index 833df735..d966c641 100644 --- a/lib/im/im_search.dart +++ b/lib/im/im_search.dart @@ -7,6 +7,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../generated/l10n.dart'; import '../retrofit/data/base_data.dart'; import '../retrofit/data/im_user.dart'; import '../retrofit/retrofit_api.dart'; @@ -30,10 +31,14 @@ class _ImSearch extends State { int searchState = 0; int textType = 0; int searchUserIndex = 0; + String selfUserId = ""; @override void initState() { super.initState(); + SharedPreferences.getInstance().then((value) { + selfUserId = value.getString("userId"); + }); } ///离开页面记着销毁和清除 @@ -81,8 +86,7 @@ class _ImSearch extends State { backgroundColor: Color(0xFFFFFFFF), resizeToAvoidBottomInset: false, appBar: MyAppBar( - title: "", - leading: true, + title: "搜索", leadingColor: Colors.black, background: Color(0xFFFFFFFF), ), @@ -90,7 +94,33 @@ class _ImSearch extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - imSearch(), + Row( + crossAxisAlignment:CrossAxisAlignment.center, + mainAxisAlignment:MainAxisAlignment.center, + children: [ + Expanded(child: imSearch()), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap:(){ + Navigator.of(context).pop(); + }, + child: Container( + margin: EdgeInsets.only(top:8.h,bottom:29.h), + alignment: Alignment.center, + padding: EdgeInsets.only(right: 16.w), + child: Text( + S.of(context).quxiao, + textAlign: TextAlign.center, + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize:14.sp, + fontWeight: MyFontWeight.medium, + ), + ) + ), + ) + ], + ), searchState == 2 ? Center( child: Text( @@ -130,8 +160,10 @@ class _ImSearch extends State { searchUserIndex = position; }); Navigator.of(context).pushNamed('/router/personal_page', arguments: { - "memberId":searchUser[searchUserIndex].mid ?? "", + "memberId":(searchUser[searchUserIndex].mid ?? "") == selfUserId ? "0":searchUser[searchUserIndex].mid, + "inletType":0 }); + FocusScope.of(context).requestFocus(FocusNode()); }, child: imSearchItem(searchUser[position]), ); diff --git a/lib/im/im_view/im_page.dart b/lib/im/im_view/im_page.dart index f7def394..617b8fbf 100644 --- a/lib/im/im_view/im_page.dart +++ b/lib/im/im_view/im_page.dart @@ -1,5 +1,6 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/constant.dart'; import 'package:huixiang/generated/l10n.dart'; @@ -46,6 +47,8 @@ class _IMPage extends State implements OnChatMessage { Map lastMessageMap = {}; Map unreadCountMap = {}; Map contactMap = {}; + int slIndex = 0; + int insertIndex = 0; @override void onMessage(txt) { @@ -80,7 +83,7 @@ class _IMPage extends State implements OnChatMessage { if (userIds.contains(message.fromId)) { userIds.remove(message.fromId); } - userIds.insert(0, message.fromId); + userIds.insert(insertIndex, message.fromId); lastMessageMap[message.fromId] = message; @@ -161,6 +164,15 @@ class _IMPage extends State implements OnChatMessage { } } contactMap = contacts.lGroupBy((p0) => p0.mid).mGroupItem(); + List topUserIds = [],notTopUserIds = []; + contactMap.forEach((key, value) { + if(value.isTop == 1) + topUserIds.add(key); + else + notTopUserIds.add(key); + }); + insertIndex = topUserIds.length; + this.userIds = topUserIds..addAll(notTopUserIds); } /// update one conversation last message ,and update conversation sort @@ -385,7 +397,9 @@ class _IMPage extends State implements OnChatMessage { return GestureDetector( behavior: HitTestBehavior.opaque, onTap:(){ - Navigator.of(context).pushNamed('/router/im_search'); + Navigator.of(context).pushNamed('/router/im_search').then((value) { + _refresh(); + }); }, child: Container( margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), @@ -429,24 +443,24 @@ class _IMPage extends State implements OnChatMessage { physics: NeverScrollableScrollPhysics(), itemBuilder: (context, position) { return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - if (userIds[position] == sharedPreferences.getString("userId")) { - SmartDialog.showToast("不能跟自己聊天", alignment: Alignment.center); - return; - } - Navigator.of(context).pushNamed( - '/router/chat_details_page', - arguments: { - "toUser": contactMap[userIds[position]], - }, - ).then((value) { - unreadCountMap[userIds[position]] = 0; - updateLastMessage(userIds[position]); - }); - }, - child: chatItem(userIds[position]), - ); + behavior: HitTestBehavior.opaque, + onTap: () { + if (userIds[position] == sharedPreferences.getString("userId")) { + SmartDialog.showToast("不能跟自己聊天", alignment: Alignment.center); + return; + } + Navigator.of(context).pushNamed( + '/router/chat_details_page', + arguments: { + "toUser": contactMap[userIds[position]], + }, + ).then((value) { + unreadCountMap[userIds[position]] = 0; + updateLastMessage(userIds[position]); + _refresh(); + }); + }, + child: chatItem(userIds[position])); }, ), ); diff --git a/lib/main.dart b/lib/main.dart index a58e20d9..bb72c565 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -517,7 +517,7 @@ Map routers = { '/router/chat_details_page': (context, {arguments}) => ChatDetailsPage(arguments: arguments), '/router/chat_setting': (context, {arguments}) => - ChatSetting(), + ChatSetting(arguments:arguments), '/router/chat_friend_group': (context, {arguments}) => ChatFriendGroup(), '/router/add_friend': (context, {arguments}) => diff --git a/lib/mine/fans_page.dart b/lib/mine/fans_page.dart index 27fd6a8d..1d2c4c18 100644 --- a/lib/mine/fans_page.dart +++ b/lib/mine/fans_page.dart @@ -154,6 +154,7 @@ class _FansPage extends State Navigator.of(context) .pushNamed('/router/personal_page', arguments: { "memberId": list.mid ?? "", + "inletType":0 });}, child: Padding( padding: EdgeInsets.only(right: 8.w), diff --git a/lib/mine/follow_page.dart b/lib/mine/follow_page.dart index 7608a692..b6a53b78 100644 --- a/lib/mine/follow_page.dart +++ b/lib/mine/follow_page.dart @@ -148,6 +148,7 @@ class _FollowPage extends State with SingleTickerProviderStateMixin, Navigator.of(context) .pushNamed('/router/personal_page', arguments: { "memberId": list.mid ?? "", + "inletType":0 });}, child: Padding( padding: EdgeInsets.only(right: 8.w), diff --git a/lib/mine/mine_page.dart b/lib/mine/mine_page.dart index 73c7e73b..c439664a 100644 --- a/lib/mine/mine_page.dart +++ b/lib/mine/mine_page.dart @@ -65,6 +65,7 @@ class MinePageState extends State with AutomaticKeepAliveClientMixin { : await Navigator.of(context) .pushNamed('/router/personal_page', arguments: { "memberId": "0", + "inletType":0 }); setState(() {}); } diff --git a/lib/mine/personal_page.dart b/lib/mine/personal_page.dart index 09fdb547..af905b6c 100644 --- a/lib/mine/personal_page.dart +++ b/lib/mine/personal_page.dart @@ -1307,14 +1307,18 @@ class _PersonalPage extends State with WidgetsBindingObserver,Sing SmartDialog.showToast("不能跟自己聊天", alignment: Alignment.center); return; } - Navigator.of(context) - .pushNamed('/router/chat_details_page', arguments: { - "toUser": ImUser( - avatar: memberInfor?.headimg, - mid: memberInfor?.id, - nickname: memberInfor?.nickname) - },); - + if(widget.arguments["inletType"] == 1){ + //聊天框跳转到该页面inletType = 1,别的页面都是0,为了避免打开多个聊天框bug; + Navigator.of(context).pop(); + }else{ + Navigator.of(context) + .pushNamed('/router/chat_details_page', arguments: { + "toUser": ImUser( + avatar: memberInfor?.headimg, + mid: memberInfor?.id, + nickname: memberInfor?.nickname) + },); + } }, child: Container( width:110.w, diff --git a/lib/retrofit/data/im_user.dart b/lib/retrofit/data/im_user.dart index a57953bb..80d15e33 100644 --- a/lib/retrofit/data/im_user.dart +++ b/lib/retrofit/data/im_user.dart @@ -10,11 +10,13 @@ class ImUser { String mid, String nickname, num isDelete, + num isTop, String avatar, String phone, }){ _mid = mid; _nickname = nickname; _isDelete = isDelete; + _isTop = isTop; _avatar = avatar; _phone = phone; } @@ -23,36 +25,46 @@ class ImUser { _mid = json['mid']; _nickname = json['nickname']; _isDelete = json['isDelete']; + _isTop = json['isTop']; _avatar = json['avatar']; _phone = json['phone']; } String _mid; String _nickname; num _isDelete; + num _isTop; String _avatar; String _phone; ImUser copyWith({ String mid, String nickname, num isDelete, + num isTop, String avatar, String phone, }) => ImUser( mid: mid ?? _mid, nickname: nickname ?? _nickname, isDelete: isDelete ?? _isDelete, + isTop: isTop ?? _isTop, avatar: avatar ?? _avatar, phone: phone ?? _phone, ); String get mid => _mid; String get nickname => _nickname; num get isDelete => _isDelete; + num get isTop => _isTop; String get avatar => _avatar; String get phone => _phone; + set isTop(num value) { + _isTop = value; + } + Map toJson() { final map = {}; map['mid'] = _mid; map['nickname'] = _nickname; map['isDelete'] = _isDelete; + map['isTop'] = _isTop; map['avatar'] = _avatar; map['phone'] = _phone; return map; diff --git a/lib/union/union_list.dart b/lib/union/union_list.dart index 2d70861b..4805f14c 100644 --- a/lib/union/union_list.dart +++ b/lib/union/union_list.dart @@ -129,6 +129,7 @@ class _UnionList extends State with AutomaticKeepAliveClientMixin { behavior: HitTestBehavior.opaque, onTap: () { { + //一心回乡商城版ui,因需求,暂未显示该板块(ui仿商城模式) // if (storeList[position].storeName == "一心回乡商城") { // Navigator.of(context).pushNamed( // '/router/shopping_mall_home', diff --git a/lib/utils/flutter_utils.dart b/lib/utils/flutter_utils.dart index e39eac84..6174d8b8 100644 --- a/lib/utils/flutter_utils.dart +++ b/lib/utils/flutter_utils.dart @@ -293,17 +293,64 @@ class AppUtils { static String timeFormatter(DateTime time) { final now = DateTime.now(); final diff = now.difference(time).inHours; + final diff2 = now.difference(time).inDays; if (diff < 24) { - return '刚刚'; // 24小时内显示为“刚刚” + return DateFormat('HH:mm').format(time); // 24小时内显示为今天发送信息的时间点 } else if (diff < 48) { - return '昨天'; // 昨天 - } else if (diff < 72) { - return '前天'; // 前天 + return '昨天 ${DateFormat('HH:mm').format(time)}'; // 昨天+时间点 + } else if (diff < 72 && diff2<7) { + return DateFormat('${DateFormat('EEEE').format(time)}').format(time);// 超过72小时显示为星期几 } else if (time.year == now.year) { return DateFormat('MM月dd日').format(time); // 今年内的日期 } else { return DateFormat('yyyy年MM月dd日').format(time); // 其他年份的日期 } } + + ///聊天框显示时间 + static String milliTimeFormatter(DateTime time) { + final now = DateTime.now(); + final diff = now.difference(time).inHours; + + if (diff < 24) { + return DateFormat('HH:mm').format(time); // 24小时内显示为今天发送信息的时间点 + } else if (diff < 48) { + return '昨天 ${DateFormat('HH:mm').format(time)}'; // 昨天+时间点 + } else if (diff < 72) { + return DateFormat('${DateFormat('EEEE').format(time)}').format(time) + " ${DateFormat('HH:mm').format(time)}";// 超过72小时显示为星期几+时间点 + } else if (time.year == now.year) { + return DateFormat('MM月dd日').format(time) + " ${DateFormat('HH:mm').format(time)}"; // 今年内的日期+时间点 + } else { + return DateFormat('yyyy年MM月dd日').format(time) + " ${DateFormat('HH:mm').format(time)}"; // 其他年份的日期+时间点 + } + } + + ///聊天框时间间隔显示 + static String getTimeDisplay(DateTime previousTime, DateTime currentTime) { + final diffInMinutes = (currentTime.difference(previousTime)).inMinutes; + + if (diffInMinutes < 5) { + // 时间间隔小于5分钟,不显示时间 + return ''; + } else if (currentTime.year == DateTime.now().year) { + // 同一年内 + if (currentTime.day == DateTime.now().day) { + // 当天 + return DateFormat('HH:mm').format(currentTime); + } else if (currentTime.day == DateTime.now().day - 1) { + // 昨天 + return '昨天 ${DateFormat('HH:mm').format(currentTime)}'; + } else if ((currentTime.day - DateTime.now().day).abs() < 7) { + // 最近七天 + return '${DateFormat('EEEE').format(currentTime)} ${DateFormat('HH:mm').format(currentTime)}'; + } else { + // 超过一周 + return DateFormat('MM/dd').format(currentTime); + } + } else { + // 不同年份 + return DateFormat('yyyy/MM/dd').format(currentTime); + } + } } diff --git a/lib/web/web_view/comment_list.dart b/lib/web/web_view/comment_list.dart index 6a5481a6..fc31663d 100644 --- a/lib/web/web_view/comment_list.dart +++ b/lib/web/web_view/comment_list.dart @@ -259,6 +259,7 @@ class CommentListState extends State { Navigator.of(context) .pushNamed('/router/personal_page', arguments: { "memberId": memberList.createUser, + "inletType":0 }); }); },