更新记录
v1.0.0(2026-04-21)
下载此版本
- 提供通用聊天 UI 组件
vm-openai-chat
- 支持顶部标题、消息区、底部输入框布局
- 支持空状态插槽与顶部菜单插槽
- 默认内置清空消息菜单
- 支持外部控制消息数据、输入内容与流式状态
- 可搭配
vm-openai 使用,也支持自定义数据源
平台兼容性
uni-app(3.8.0)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| √ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
其他
vm-openai-ui
vm-openai-ui 是一个通用聊天 UI 插件,只负责界面和交互,不内置任何具体请求实现。
你可以把它和 vm-openai 搭配使用,也可以接入你自己的流式接口。
组件
| 组件名 |
说明 |
vm-openai-chat |
通用聊天页面容器,消息展示、输入区、菜单、滚动逻辑都已封装 |
基础用法
<template>
<vm-openai-chat
title="My AI Chat"
:messages="messages"
:model-value="inputText"
:selected-key="selectedKey"
:is-streaming="isStreaming"
:error-message="errorMessage"
@update:modelValue="inputText = $event"
@submit="handleSubmit"
@cancel="handleCancel"
@change-selection="selectedKey = $event"
@menu-select="handleMenuSelect"
>
<template #menu="{ selectedKey, selectKey, selectMenuItem }">
<view class="custom-menu-item" @click="selectKey('custom')">切换到自定义模式</view>
<view class="custom-menu-item" @click="selectMenuItem({ key: 'clear', label: '清空消息' })">清空消息</view>
</template>
<template #empty="{ selectedKey }">
<view class="custom-empty">
<text class="custom-empty-title">开始一段新对话</text>
<text class="custom-empty-subtitle">当前选择:{{ selectedKey }}</text>
</view>
</template>
</vm-openai-chat>
</template>
Props
| Prop |
类型 |
必填 |
说明 |
messages |
Array |
是 |
当前消息列表,元素结构为 { id, role, content } |
modelValue |
String |
否 |
输入框内容,支持 v-model |
selectedKey |
String |
否 |
当前选中项 key |
isStreaming |
Boolean |
否 |
是否处于流式输出中 |
errorMessage |
String |
否 |
底部错误提示 |
title |
String |
否 |
顶部标题,默认 AI Assistant |
canSend |
Boolean |
否 |
是否允许发送,不传时由 modelValue 和 isStreaming 自动计算 |
Events
| 事件 |
参数 |
说明 |
update:modelValue |
string |
输入框内容变化 |
submit |
string |
点击发送,返回当前输入内容 |
cancel |
- |
点击停止 |
change-selection |
string |
自定义菜单里调用 selectKey 时触发 |
clear-messages |
- |
点击默认清空菜单项时触发 |
menu-select |
Object |
点击自定义菜单项 |
Slots
| 插槽名 |
作用域参数 |
说明 |
empty |
{ selectedKey, messages } |
自定义空状态内容;不传时使用组件内置默认空状态 |
menu |
{ selectedKey, selectKey, selectMenuItem } |
自定义顶部菜单内容;不传时使用组件内置菜单。默认内置菜单只有“清空消息” |