组件/ChatComposer 消息输入
通用组件

ChatComposer 消息输入

用于 AI 消息输入、发送。

该页面由 AI 迁移生成,请谨慎使用

内容已迁移完成,但仍建议结合源码和人工评审结果使用。

ChatComposer 消息输入

用于 AI 消息输入、发送。

import { ref } from 'vue' const text = ref('') const sent = ref<string[]>([]) function onSend(payload: { text: string }) { sent.value.unshift(payload.text) text.value = '' }

基础用法

ChatComposer

示例即将加载...
<template>
  <TxChatComposer v-model="text" @send="onSend" />
</template>

API

Props

属性类型默认值说明
modelValuestring''textarea 的 v-model
placeholderstring'Message…'textarea 占位文本
disabledbooleanfalse禁用输入、发送与附件操作
submittingbooleanfalse提交中状态,阻断发送
allowAttachmentWhileSubmittingbooleanfalse提交中仍允许附件操作
minRowsnumber3textarea 行数
maxRowsnumber6预留给使用方的最大行数
sendOnEnterbooleantrue启用键盘发送行为
sendOnMetaEnterbooleantrue键盘发送是否需要 Meta/Ctrl+Enter
allowEmptySendbooleanfalse文本为空时允许仅凭附件发送
sendButtonTextstring'Send'默认发送按钮文本
showAttachmentButtonbooleanfalse显示默认附件按钮
attachmentButtonTextstring'Attach'默认附件按钮文本
attachmentsChatComposerAttachment[][]textarea 上方的附件 chips

Events

事件参数说明
update:modelValuestringtextarea 输入时触发
send{ text: string }允许发送时触发,文本已 trim
attachmentClick-允许附件操作时触发
pasteClipboardEvent透传 textarea paste
focusFocusEvent透传 textarea focus
blurFocusEvent透传 textarea blur

Slots

插槽作用域说明
attachments{ attachments }替换默认附件 chips
toolbar{ send, disabled, attachmentClick }替换默认操作行
toolbar-left{ disabled }添加到默认操作行左侧
actions{ send, disabled }添加到默认发送按钮前
footer-渲染在操作行下方

交互契约

  • send payload 的 text 会先 trim。
  • 文本为空时默认阻断发送;只有 allowEmptySend=true 且存在附件时才允许仅附件发送。
  • disabledsubmitting 会阻断发送;disabled 也会阻断附件操作。
  • 提交中默认阻断附件操作,除非 allowAttachmentWhileSubmitting=true
  • sendOnMetaEnter=true 时键盘发送需要 Meta/Ctrl+Enter;关闭后 Enter 发送,Shift+Enter 保留换行。
  • 自定义 toolbar 会收到可调用的 send / attachmentClick,并替换默认操作行。