File tree Expand file tree Collapse file tree 12 files changed +68
-87
lines changed
pro-components/chat/chat-message
tdesign-miniprogram-chat/site/docs Expand file tree Collapse file tree 12 files changed +68
-87
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,4 @@ longpress | `(detail: { id: string })` | \-
2929
3030name | \-
3131avatar | \-
32- datetime | \-
32+ content | \-
Original file line number Diff line number Diff line change @@ -30,12 +30,12 @@ isComponent: true
3030{{ base }}
3131
3232#### 可配置昵称、头像、对齐方式
33-
33+ 支持 ` avatar ` , ` name ` 插槽自定义
3434{{ configure }}
3535
3636#### 配置消息属性
3737
38- 支持` avatar ` , ` name ` , ` datetime ` , ` content ` 插槽自定义, ` content ` 插槽使用建议:渲染聊天消息统一用 ` t-chat-content ` ;仅在需要“单独使用 Markdown 组件”时使用 ` t-chat-markdown ` 。也支持别的 markdown 渲染组件,选择其他 markdown 渲染库由用户自行安装。
38+ 支持` content ` 插槽自定义, ` content ` 插槽使用建议:渲染聊天消息统一用 ` t-chat-content ` ;仅在需要“单独使用 Markdown 组件”时使用 ` t-chat-markdown ` 。也支持别的 markdown 渲染组件,选择其他 markdown 渲染库由用户自行安装。
3939
4040{{ content }}
4141
@@ -86,5 +86,5 @@ longpress | `(detail: { id: string })` | \-
8686名称 | 描述
8787-- | --
8888avatar | 自定义 ` avatar ` 显示内容
89- datetime | 自定义 ` datetime ` 显示内容
89+ content | 自定义消息内容
9090name | 自定义 ` name ` 显示内容
Original file line number Diff line number Diff line change 2121 placement="right"
2222 ></t-chat-message>
2323 </view>
24+ <view class="chat-example-block">
25+ <t-chat-message content="{{message.content}}" role="{{message.role}}" datetime="16:38">
26+ <view slot="name" class="name-block">
27+ <image src="https://tdesign.gtimg.com/site/chat-avatar.png" />
28+ <view>Canxuan</view>
29+ </view>
30+ </t-chat-message>
31+ </view>
2432</view>
Original file line number Diff line number Diff line change 88 background-color: var(--td-bg-color-container);
99 padding: 32rpx 32rpx 0 32rpx;
1010}
11+
12+ .name-block {
13+ display: flex;
14+ align-items: center;
15+ margin-right: 16rpx;
16+ }
17+
18+ .name-block image {
19+ margin-right: 16rpx;
20+ width: 40rpx;
21+ height: 40rpx;
22+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ Component({
1919 } ,
2020 pic1 : {
2121 role : 'user' ,
22+ name : '张三' ,
23+ avatar : 'https://tdesign.gtimg.com/site/avatar.jpg' ,
2224 content : [
2325 {
2426 type : 'attachment' ,
Original file line number Diff line number Diff line change 22 "component" : true ,
33 "usingComponents" : {
44 "t-chat-message" : " tdesign-miniprogram/chat-message/chat-message" ,
5- "t-chat-actionbar" : " tdesign-miniprogram/chat-actionbar/chat-actionbar"
5+ "t-chat-actionbar" : " tdesign-miniprogram/chat-actionbar/chat-actionbar" ,
6+ "t-avatar" : " tdesign-miniprogram/avatar/avatar"
67 }
7- }
8+ }
Original file line number Diff line number Diff line change 11<view class="chat-example">
22 <!-- 附件消息 -->
3- <view class="chat-example-block">
4- <t-chat-message
5- content="{{pic1.content}}"
6- role="{{pic1.role}}"
7- chatContentProps="{{chatContentProps}}"
8- ></t-chat-message>
9- </view>
103 <view class="chat-example-block">
114 <t-chat-message
125 content="{{pic2.content}}"
Original file line number Diff line number Diff line change 1818}
1919
2020.@{attachments} + .@{chat-content} :not (:empty ),
21- .@{chat-thinking} + .@{chat-content} :not (:empty ){
21+ .@{chat-thinking} + .@{chat-content} :not (:empty ) {
2222 margin-top : 24 rpx;
2323}
2424
5454 &__header {
5555 .@{chat-message} __avatar {
5656 padding-top : calc (@chat-message-height + @spacer );
57+
58+ & :empty {
59+ padding-top : 0 ;
60+ }
5761 }
5862 }
5963
115119 .@{chat-message} __avatar {
116120 margin-left : @spacer-1 ;
117121 margin-right : 0 ;
122+
123+ & :empty {
124+ margin-left : 0 ;
125+ }
118126 }
119127 }
120128
126134 margin-right : @spacer-1 ;
127135 padding-top : calc (@chat-message-height + @spacer );
128136
137+ & :empty {
138+ padding-top : 0 ;
139+ margin-right : 0 ;
140+ }
141+
129142 &-image {
130143 width : @spacer-4 ;
131144 height : @spacer-4 ;
157170 color : @text-color-placeholder ;
158171 // padding-left: @spacer-2;
159172 margin-bottom : @spacer ;
173+
174+ & :empty {
175+ height : 0 ;
176+ margin-bottom : 0 ;
177+ }
160178 }
161179
162180 // 名称样式
Original file line number Diff line number Diff line change 11<wxs src="../../../components/common/utils.wxs" module="_" />
22
33<view class="class {{chatItemClass}}" style="{{_._style([style, customStyle])}}" bindlongpress="handleLongPress">
4- <view wx:if="{{showAvatar}}" class="{{classPrefix}}__avatar">
4+ <view class="{{classPrefix}}__avatar">
5+ <!-- 头像插槽 -->
6+ <slot name="avatar" />
57 <block wx:if="{{avatar}}">
68 <image src="{{avatar}}" class="{{classPrefix}}__avatar-image"></image>
79 </block>
810 </view>
911 <view class="{{contentClasses}}">
10- <view wx:if="{{showName || showDateTime}}" class="{{classPrefix}}__base">
12+ <view class="{{classPrefix}}__base">
13+ <!-- 昵称插槽 -->
14+ <slot name="name" />
1115 <text wx:if="{{showName}}" class="{{classPrefix}}__name">{{name}}</text>
1216 <text wx:if="{{datetime}}" class="{{classPrefix}}__time">{{datetime}}</text>
1317 </view>
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ const props: TdChatMessageProps = {
3131 /** 对话单元的时间配置 */
3232 datetime : {
3333 type : String ,
34+ value : '' ,
3435 } ,
3536 /** 自定义的昵称 */
3637 name : {
You can’t perform that action at this time.
0 commit comments