From 319ed953a758646f9f464bfa9e615d057b756d22 Mon Sep 17 00:00:00 2001 From: Zeew Date: Thu, 7 Aug 2025 10:27:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BC=9A=E8=AF=9D=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E6=9C=80=E8=BF=91=E6=B6=88=E6=81=AF=E9=A1=B9?= =?UTF-8?q?=E6=9C=AA=E5=AF=B9=E9=BD=90=EF=BC=9B=E4=BF=AE=E6=94=B9=E7=BE=A4?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=E6=A0=BC=E5=BC=8F=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tim_uikit_conversation_item.dart | 1 + .../tim_uikit_conversation_last_msg.dart | 149 ++++++++++++------ .../widgets/tim_uikit_group_name_card.dart | 44 +++++- 3 files changed, 143 insertions(+), 51 deletions(-) diff --git a/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_item.dart b/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_item.dart index 95c232f..229ec84 100644 --- a/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_item.dart +++ b/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_item.dart @@ -173,6 +173,7 @@ class TIMUIKitConversationItem extends TIMUIKitStatelessWidget { height: 6, ), Row( + crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded(child: _getShowMsgWidget(context)), if (isDisturb) diff --git a/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_last_msg.dart b/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_last_msg.dart index 8105555..e1080f4 100644 --- a/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_last_msg.dart +++ b/lib/ui/views/TIMUIKitConversation/tim_uikit_conversation_last_msg.dart @@ -90,15 +90,20 @@ class _TIMUIKitLastMsgState extends TIMUIKitState { final isAdminRevoke = revokeStatus.$2; if (isRevokedMessage) { final isSelf = widget.lastMsg!.isSelf ?? true; - final option1 = - isAdminRevoke ? TIM_t("管理员") : (isSelf ? TIM_t("您") : widget.lastMsg!.nickName ?? widget.lastMsg?.sender); + final option1 = isAdminRevoke + ? TIM_t("管理员") + : (isSelf + ? TIM_t("您") + : widget.lastMsg!.nickName ?? widget.lastMsg?.sender); if (mounted) { setState(() { - groupTipsAbstractText = TIM_t_para("{{option1}}撤回了一条消息", "$option1撤回了一条消息")(option1: option1); + groupTipsAbstractText = TIM_t_para( + "{{option1}}撤回了一条消息", "$option1撤回了一条消息")(option1: option1); }); } } else { - String msgShowText = await _getLastMsgShowText(widget.lastMsg, widget.context) ?? ""; + String msgShowText = + await _getLastMsgShowText(widget.lastMsg, widget.context) ?? ""; if (mounted) { setState(() { groupTipsAbstractText = msgShowText; @@ -110,14 +115,16 @@ class _TIMUIKitLastMsgState extends TIMUIKitState { String _getDisturbUnreadCountInfo() { if (widget.isDisturb && widget.unreadCount > 0) { final option1 = widget.unreadCount.toString(); - String unreadCountText = TIM_t_para("[{{option1}} 条]", "[$option1 条]")(option1: option1); + String unreadCountText = + TIM_t_para("[{{option1}}条] ", "[$option1 条]")(option1: option1); return unreadCountText; } return ""; } - Future _getLastMsgShowText(V2TimMessage? message, BuildContext context) async { + Future _getLastMsgShowText( + V2TimMessage? message, BuildContext context) async { final msgType = message!.elemType; switch (msgType) { case MessageElemType.V2TIM_ELEM_TYPE_CUSTOM: @@ -130,9 +137,11 @@ class _TIMUIKitLastMsgState extends TIMUIKitState { return TIM_t("[表情]"); case MessageElemType.V2TIM_ELEM_TYPE_FILE: final option1 = widget.lastMsg!.fileElem!.fileName; - return TIM_t_para("[文件] {{option1}}", "[文件] $option1")(option1: option1); + return TIM_t_para("[文件] {{option1}}", "[文件] $option1")( + option1: option1); case MessageElemType.V2TIM_ELEM_TYPE_GROUP_TIPS: - return await MessageUtils.groupTipsMessageAbstract(widget.lastMsg!.groupTipsElem!, []); + return await MessageUtils.groupTipsMessageAbstract( + widget.lastMsg!.groupTipsElem!, []); case MessageElemType.V2TIM_ELEM_TYPE_IMAGE: return TIM_t("[图片]"); case MessageElemType.V2TIM_ELEM_TYPE_VIDEO: @@ -194,49 +203,91 @@ class _TIMUIKitLastMsgState extends TIMUIKitState { @override Widget tuiBuild(BuildContext context, TUIKitBuildValue value) { - final isDesktopScreen = TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; + final isDesktopScreen = + TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; final TUITheme theme = value.theme; final icon = _getIconByMsgStatus(context); String disturbUnreadCountInfo = _getDisturbUnreadCountInfo(); - return Row(children: [ - if (icon != null) - Container( - margin: const EdgeInsets.only(right: 2), - child: icon, - ), - if (widget.groupAtInfoList.isNotEmpty) - Text(_getAtMessage(), style: TextStyle(color: theme.cautionColor, fontSize: widget.fontSize)), - if (widget.draftText != null && widget.draftText != "") - Text(_getDraftShowText(), - style: TextStyle(color: theme.conversationItemDraftTextColor, fontSize: widget.fontSize)), - if (disturbUnreadCountInfo != "") - Text(disturbUnreadCountInfo, style: TextStyle(color: theme.weakTextColor, fontSize: widget.fontSize)), - if (widget.draftText != null && widget.draftText != "") - Expanded( - child: ExtendedText(groupTipsAbstractText, - softWrap: true, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle(height: 1, color: theme.weakTextColor, fontSize: widget.fontSize), - specialTextSpanBuilder: DefaultSpecialTextSpanBuilder( - isUseQQPackage: true, - isUseTencentCloudChatPackage: true, - showAtBackground: true, - )), - ), - if (widget.draftText == null || widget.draftText == "" && TencentUtils.checkString(groupTipsAbstractText) != null) - Expanded( - child: ExtendedText(groupTipsAbstractText, - softWrap: true, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle(height: 1, color: theme.weakTextColor, fontSize: widget.fontSize), - specialTextSpanBuilder: DefaultSpecialTextSpanBuilder( - isUseQQPackage: true, - isUseTencentCloudChatPackage: true, - showAtBackground: true, - )), - ) - ]); + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (icon != null) + Container( + margin: const EdgeInsets.only(right: 2), + child: icon, + ), + if (widget.groupAtInfoList.isNotEmpty) + Baseline( + baseline: widget.fontSize, + baselineType: TextBaseline.alphabetic, + child: Text(_getAtMessage(), + style: TextStyle( + color: theme.cautionColor, + fontSize: widget.fontSize, + height: 1.0)), + ), + if (widget.draftText != null && widget.draftText != "") + Baseline( + baseline: widget.fontSize, + baselineType: TextBaseline.alphabetic, + child: Text(_getDraftShowText(), + style: TextStyle( + color: theme.conversationItemDraftTextColor, + fontSize: widget.fontSize, + height: 1.0)), + ), + if (disturbUnreadCountInfo != "") + Baseline( + baseline: widget.fontSize, + baselineType: TextBaseline.alphabetic, + child: Text(disturbUnreadCountInfo, + style: TextStyle( + color: theme.weakTextColor, + fontSize: widget.fontSize, + height: 1.0)), + ), + if (widget.draftText != null && widget.draftText != "") + Expanded( + child: Baseline( + baseline: widget.fontSize, + baselineType: TextBaseline.alphabetic, + child: ExtendedText(groupTipsAbstractText, + softWrap: true, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: theme.weakTextColor, + fontSize: widget.fontSize, + height: 1.0), + specialTextSpanBuilder: DefaultSpecialTextSpanBuilder( + isUseQQPackage: true, + isUseTencentCloudChatPackage: true, + showAtBackground: true, + )), + ), + ), + if (widget.draftText == null || + widget.draftText == "" && + TencentUtils.checkString(groupTipsAbstractText) != null) + Expanded( + child: Baseline( + baseline: widget.fontSize, + baselineType: TextBaseline.alphabetic, + child: ExtendedText(groupTipsAbstractText, + softWrap: true, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: theme.weakTextColor, + fontSize: widget.fontSize, + height: 1.0), + specialTextSpanBuilder: DefaultSpecialTextSpanBuilder( + isUseQQPackage: true, + isUseTencentCloudChatPackage: true, + showAtBackground: true, + )), + ), + ) + ]); } } diff --git a/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_name_card.dart b/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_name_card.dart index 7bb8a91..a701560 100644 --- a/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_name_card.dart +++ b/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_name_card.dart @@ -52,7 +52,18 @@ class GroupProfileNameCardState extends TIMUIKitState{ tips: TIM_t("仅限中文、字母、数字和下划线,2-20个字"), onSubmitted: (String nameCard) async { final text = nameCard.trim(); - model.setNameCard(text); + // 验证输入格式 + if (_validateNameCard(text)) { + model.setNameCard(text); + } else { + // 显示错误提示 + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(TIM_t("仅限中文、字母、数字和下划线,2-20个字")), + backgroundColor: Colors.red, + ), + ); + } }, theme: theme); } @@ -104,7 +115,19 @@ class GroupProfileNameCardState extends TIMUIKitState{ controller: controller, maxLines: 1, onSubmitted: (text) { - model.setNameCard(text.trim()); + final trimmedText = text.trim(); + // 验证输入格式 + if (_validateNameCard(trimmedText)) { + model.setNameCard(trimmedText); + } else { + // 显示错误提示 + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(TIM_t("仅限中文、字母、数字和下划线,2-20个字")), + backgroundColor: Colors.red, + ), + ); + } }, keyboardType: TextInputType.multiline, autofocus: true, @@ -142,4 +165,21 @@ class GroupProfileNameCardState extends TIMUIKitState{ ), ); } + + /// 验证群昵称格式 + /// 仅限中文、字母、数字和下划线,2-20个字 + bool _validateNameCard(String text) { + if (text.isEmpty) { + return false; + } + + // 检查长度:2-20个字符 + if (text.length < 2 || text.length > 20) { + return false; + } + + // 检查字符类型:仅限中文、字母、数字和下划线 + final RegExp regex = RegExp(r'^[\u4e00-\u9fa5a-zA-Z0-9_]+$'); + return regex.hasMatch(text); + } }