File tree Expand file tree Collapse file tree 14 files changed +78
-17
lines changed
packages/pro-components/chat Expand file tree Collapse file tree 14 files changed +78
-17
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ isComponent: true
4949-- | -- | -- | -- | --
5050content | Object | {} | 聊天内容对象,包含type和data字段 | Y
5151role | String | '' | 消息角色,用于区分用户和助手的消息样式 | N
52-
52+ status | String | '' | 消息角色,用于区分用户和助手的消息样式 | N
53+ markdownProps | Object | 详见chat-markdown | marked 解析器的配置选项 | N
5354### Content 对象结构
5455
5556``` typescript
Original file line number Diff line number Diff line change 44
55@chat-content-user-text-color : var (--td-chat-content-user-text-color , @text-color-primary);
66@chat-content-assistant-text-color : var (--td-chat-content-assistant-text-color , @text-color-primary);
7+ @chat-content-error-text-color : var (--td-chat-content-error-text-color , @error-color);
78
89.@{chat-content} {
910 font-size : 32 rpx;
4142 border-radius : @radius-small ;
4243 }
4344 }
45+ // 错误状态样式
46+ &__error {
47+ color : @chat-content-error-text-color ;
48+ }
4449}
Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ export default class ChatContent extends SuperComponent {
1919 type : String ,
2020 value : '' ,
2121 } ,
22+ status : {
23+ type : String ,
24+ value : '' ,
25+ } ,
26+ markdownProps : {
27+ type : Object ,
28+ value : { } ,
29+ } ,
2230 } ;
2331
2432 data = {
@@ -59,7 +67,8 @@ export default class ChatContent extends SuperComponent {
5967 } ,
6068
6169 setTextInfo ( ) {
62- if ( this . properties . content . type === 'text' ) {
70+ // error 状态下统一按纯文本处理,避免走 markdown 渲染
71+ if ( this . properties . content . type === 'text' || this . properties . status === 'error' ) {
6372 this . setData ( {
6473 textInfo : this . escape ( this . properties . content . data || '' ) ,
6574 } ) ;
@@ -78,10 +87,6 @@ export default class ChatContent extends SuperComponent {
7887 } ,
7988 attached ( ) {
8089 this . setTextInfo ( ) ;
81-
82- // TODO: __anonymous ??
83- const mountedFn = function __anonymous ( ) { } ;
84- mountedFn . call ( this ) ;
8590 } ,
8691
8792 detached ( ) { } ,
Original file line number Diff line number Diff line change 11<wxs src="../../../components/common/utils.wxs" module="_" />
22
33<view class="class {{classPrefix}}" style="{{_._style([style, customStyle])}}">
4- <block wx:if="{{content.type === 'text'}}">
5- <view class="{{classPrefix}}__{{role}}">
4+ <block wx:if="{{status === 'error' || content.type === 'text'}}">
5+ <view class="{{classPrefix}}__{{role}} {{classPrefix}}__{{status}} ">
66 <view class="_pre">
77 <rich-text nodes="{{textInfo}}" />
88 </view>
99 </view>
1010 </block>
1111 <block wx:else>
1212 <view class="{{classPrefix}}__assistant">
13- <t-chat-markdown content="{{textInfo}}"></t-chat-markdown>
13+ <t-chat-markdown content="{{textInfo}}" options="{{markdownProps && markdownProps.options}}" ></t-chat-markdown>
1414 </view>
1515 </block>
1616</view>
Original file line number Diff line number Diff line change @@ -55,9 +55,9 @@ isComponent: true
5555-- | -- | -- | -- | --
5656content | String | '' | Markdown 格式的文本内容 | N
5757isMarkdown | Boolean | true | 是否启用 Markdown 解析,false 时作为普通文本显示 | N
58- markedOptions | Object | 见下方说明 | marked 解析器的配置选项 | N
58+ options | Object | 见下方说明 | marked 解析器的配置选项 | N
5959
60- ### markedOptions 配置
60+ ### options 配置
6161
6262``` javascript
6363{
@@ -147,7 +147,7 @@ t-class-link | 链接样式类
147147``` html
148148<t-chat-markdown
149149 content =" {{markdownText}}"
150- marked- options =" {{{
150+ options =" {{{
151151 gfm: true,
152152 pedantic: false,
153153 smartLists: true,
Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ export default class ChatMarkdown extends SuperComponent {
2525 type : Boolean ,
2626 value : true ,
2727 } ,
28- // 新增:marked配置选项
29- markedOptions : {
28+ // 新增:marked配置选项(原 markedOptions 重命名为 options)
29+ options : {
3030 type : Object ,
3131 value : {
3232 gfm : true ,
@@ -58,7 +58,7 @@ export default class ChatMarkdown extends SuperComponent {
5858 // 解析markdown文本
5959 parseMarkdown ( markdown : string ) {
6060 try {
61- const lexer = new Lexer ( this . data . markedOptions ) ;
61+ const lexer = new Lexer ( this . data . options ) ;
6262 const tokens = lexer . lex ( markdown ) ;
6363
6464 this . setData ( { nodes : tokens } ) ;
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ isComponent: true
3939
4040{{ status }}
4141
42+ ### 错误状态
43+
44+ {{ error }}
45+
4246### 03 组件样式
4347
4448#### 气泡样式
Original file line number Diff line number Diff line change 66 "style-component" : " ./style" ,
77 "configure" : " ./configure" ,
88 "status" : " ./status" ,
9- "content" : " ./content"
9+ "content" : " ./content" ,
10+ "error" : " ./error"
1011 }
1112}
Original file line number Diff line number Diff line change 1717 <t-demo title="02 组件状态" desc="加载状态">
1818 <status />
1919 </t-demo>
20+ <t-demo desc="错误状态">
21+ <error />
22+ </t-demo>
2023 <t-demo title="03 组件样式" desc="气泡样式">
2124 <style-component />
2225 </t-demo>
Original file line number Diff line number Diff line change 1+ Component ( {
2+ data : {
3+ message : {
4+ role : 'assistant' ,
5+ status : 'error' ,
6+ content : [
7+ {
8+ type : 'text' ,
9+ data : '!!!请求出错' ,
10+ } ,
11+ ] ,
12+ } ,
13+ } ,
14+ } ) ;
You can’t perform that action at this time.
0 commit comments