From 2dfb2e03161b64aa9e870c77951935c22ff0ef58 Mon Sep 17 00:00:00 2001
From: ZF sun <34314687@qq.com>
Date: Mon, 3 Nov 2025 16:31:53 +0800
Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0AI=E8=81=8A=E5=A4=A9?=
=?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/ai-chat-float/README.md | 238 +++
components/ai-chat-float/ai-chat-float.json | 6 +
components/ai-chat-float/ai-chat-float.vue | 546 +++++++
components/ai-chat-message/README.md | 271 ++++
.../ai-chat-message/ai-chat-message.json | 6 +
.../ai-chat-message/ai-chat-message.vue | 1424 +++++++++++++++++
components/ai-chat-message/demo.vue | 288 ++++
7 files changed, 2779 insertions(+)
create mode 100644 components/ai-chat-float/README.md
create mode 100644 components/ai-chat-float/ai-chat-float.json
create mode 100644 components/ai-chat-float/ai-chat-float.vue
create mode 100644 components/ai-chat-message/README.md
create mode 100644 components/ai-chat-message/ai-chat-message.json
create mode 100644 components/ai-chat-message/ai-chat-message.vue
create mode 100644 components/ai-chat-message/demo.vue
diff --git a/components/ai-chat-float/README.md b/components/ai-chat-float/README.md
new file mode 100644
index 0000000..2f1e15c
--- /dev/null
+++ b/components/ai-chat-float/README.md
@@ -0,0 +1,238 @@
+# AI智能客服浮动按钮组件
+
+## 组件介绍
+
+AI智能客服浮动按钮组件是一个可以在任何页面中使用的浮动AI客服按钮,点击按钮可以弹出完整的AI智能客服聊天界面。该组件基于现有的AI聊天消息组件,提供了丰富的交互功能和配置选项。
+
+## 功能特性
+
+- ✅ **浮动按钮** - 可自定义位置的浮动AI客服按钮
+- ✅ **聊天弹窗** - 点击按钮弹出完整的AI聊天界面
+- ✅ **全屏模式** - 支持全屏/窗口模式切换
+- ✅ **未读消息** - 显示未读消息数量小红点
+- ✅ **多种消息类型** - 支持文本、文件、图片、音频、视频、链接等
+- ✅ **流式对话** - 支持流式AI回复效果
+- ✅ **响应式设计** - 适配不同屏幕尺寸
+- ✅ **自定义配置** - 丰富的配置选项
+
+## 安装使用
+
+### 1. 引入组件
+
+在需要使用AI客服浮动按钮的页面中引入组件:
+
+```json
+// 页面配置文件 pages/xxx/xxx.json
+{
+ "usingComponents": {
+ "ai-chat-float": "@/components/ai-chat-float/ai-chat-float"
+ }
+}
+```
+
+### 2. 在页面中使用
+
+```vue
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+## 组件属性
+
+| 属性名 | 类型 | 默认值 | 说明 |
+|--------|------|--------|------|
+| position | String | 'bottom-right' | 按钮位置,可选值:'bottom-right', 'bottom-left', 'top-right', 'top-left' |
+| offset | Object | { bottom: '100rpx', right: '40rpx', top: '100rpx', left: '40rpx' } | 按钮距离边缘的距离 |
+| userAvatar | String | '/static/images/default-avatar.png' | 用户头像 |
+| aiAvatar | String | '/static/images/ai-avatar.png' | AI头像 |
+| initialMessages | Array | [] | 初始聊天消息 |
+| showFloatButton | Boolean | true | 是否显示浮动按钮 |
+| autoOpen | Boolean | false | 是否自动打开聊天窗口 |
+
+## 事件监听
+
+| 事件名 | 参数 | 说明 |
+|--------|------|------|
+| chat-open | - | 聊天窗口打开事件 |
+| chat-close | - | 聊天窗口关闭事件 |
+| message-sent | message | 用户发送消息事件 |
+| ai-response | message | AI回复消息事件 |
+| unread-update | count | 未读消息数量更新事件 |
+| history-loaded | messages | 历史消息加载完成事件 |
+| file-preview | message | 文件预览事件 |
+| audio-play | message | 音频播放事件 |
+| video-play | message | 视频播放事件 |
+| link-open | message | 链接打开事件 |
+| product-view | message | 商品查看事件 |
+| action-click | {action, message} | 操作按钮点击事件 |
+| input-change | value | 输入内容变化事件 |
+
+## 方法调用
+
+通过组件引用可以调用以下方法:
+
+```javascript
+// 获取组件引用
+const aiChatFloat = this.$refs.aiChatFloat
+
+// 打开聊天窗口
+aiChatFloat.openChat()
+
+// 关闭聊天窗口
+aiChatFloat.closeChat()
+
+// 添加消息
+aiChatFloat.addMessage({
+ role: 'ai',
+ type: 'text',
+ content: '这是一条新消息',
+ read: false
+})
+
+// 清空聊天记录
+aiChatFloat.clearMessages()
+
+// 标记所有消息为已读
+aiChatFloat.markAllAsRead()
+```
+
+## 配置示例
+
+### 基本配置
+
+```vue
+
+```
+
+### 自定义位置
+
+```vue
+
+```
+
+### 自定义头像
+
+```vue
+
+```
+
+### 初始消息
+
+```vue
+
+```
+
+## 样式定制
+
+组件支持通过CSS变量进行样式定制:
+
+```css
+/* 自定义主题色 */
+.ai-float-button {
+ --primary-color: #ff4544;
+ --primary-gradient: linear-gradient(135deg, #ff4544, #ff6b6b);
+}
+
+/* 自定义尺寸 */
+.ai-float-button {
+ --button-size: 120rpx;
+ --icon-size: 48rpx;
+}
+```
+
+## 注意事项
+
+1. **依赖组件**:本组件依赖 `ai-chat-message` 组件,请确保该组件已正确安装
+2. **图标字体**:组件使用了 iconfont 图标,请确保项目中已引入相应的图标字体
+3. **响应式设计**:组件已适配移动端和PC端,但在特殊场景下可能需要额外调整
+4. **性能优化**:在大量消息时建议启用消息数量限制
+
+## 演示页面
+
+访问 `/pages/ai-chat-float/index` 查看完整的演示效果,包含所有配置选项的实时预览。
+
+## 更新日志
+
+### v1.0.0 (2024-11-03)
+- ✨ 初始版本发布
+- ✨ 支持浮动按钮和聊天弹窗
+- ✨ 支持多种消息类型
+- ✨ 支持流式对话
+- ✨ 支持全屏模式
+- ✨ 支持未读消息提示
+
+## 技术支持
+
+如有问题或建议,请联系开发团队。
\ No newline at end of file
diff --git a/components/ai-chat-float/ai-chat-float.json b/components/ai-chat-float/ai-chat-float.json
new file mode 100644
index 0000000..ceb093a
--- /dev/null
+++ b/components/ai-chat-float/ai-chat-float.json
@@ -0,0 +1,6 @@
+{
+ "component": true,
+ "usingComponents": {
+ "ai-chat-message": "../ai-chat-message/ai-chat-message"
+ }
+}
\ No newline at end of file
diff --git a/components/ai-chat-float/ai-chat-float.vue b/components/ai-chat-float/ai-chat-float.vue
new file mode 100644
index 0000000..353575f
--- /dev/null
+++ b/components/ai-chat-float/ai-chat-float.vue
@@ -0,0 +1,546 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ unreadCount > 99 ? '99+' : unreadCount }}
+
+
+
+ AI客服
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/ai-chat-message/README.md b/components/ai-chat-message/README.md
new file mode 100644
index 0000000..0f999a8
--- /dev/null
+++ b/components/ai-chat-message/README.md
@@ -0,0 +1,271 @@
+# AI智能客服组件
+
+一个功能完整的AI智能客服对话组件,支持多种消息类型和交互功能。
+
+## 功能特性
+
+- ✅ 支持对话上下文管理
+- ✅ 支持多种消息类型:文本、Markdown、文件、音频、视频、链接、商品卡片
+- ✅ 支持语音输入和录音
+- ✅ 支持图片、文件、位置等附件发送
+- ✅ 支持消息操作按钮(点赞、踩等)
+- ✅ 支持历史消息加载
+- ✅ 响应式设计,适配多端
+
+## 安装使用
+
+### 1. 引入组件
+
+在 `pages.json` 中注册组件:
+
+```json
+{
+ "usingComponents": {
+ "ai-chat-message": "/components/ai-chat-message/ai-chat-message"
+ }
+}
+```
+
+### 2. 在页面中使用
+
+```vue
+
+
+
+
+
+
+
+```
+
+## Props 配置
+
+| 参数 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| initialMessages | Array | [] | 初始消息列表 |
+| userAvatar | String | '/static/images/default-avatar.png' | 用户头像 |
+| aiAvatar | String | '/static/images/ai-avatar.png' | AI头像 |
+| showLoadMore | Boolean | true | 是否显示加载更多 |
+| maxMessages | Number | 100 | 最大消息数量 |
+
+## Events 事件
+
+| 事件名 | 参数 | 说明 |
+|--------|------|------|
+| message-sent | message | 用户发送消息 |
+| ai-response | message | AI回复消息 |
+| action-click | {action, message} | 操作按钮点击 |
+| history-loaded | messages | 历史消息加载完成 |
+| file-preview | message | 文件预览 |
+| audio-play | message | 音频播放 |
+| audio-pause | message | 音频暂停 |
+| video-play | message | 视频播放 |
+| video-pause | message | 视频暂停 |
+| link-open | message | 链接打开 |
+| product-view | message | 商品查看 |
+| input-change | value | 输入内容变化 |
+
+## 消息类型格式
+
+### 文本消息
+```javascript
+{
+ id: 1,
+ role: 'user', // 或 'ai'
+ type: 'text',
+ content: '消息内容',
+ timestamp: Date.now()
+}
+```
+
+### Markdown消息
+```javascript
+{
+ id: 2,
+ role: 'ai',
+ type: 'markdown',
+ content: '# 标题\n**粗体** *斜体* `代码`',
+ timestamp: Date.now()
+}
+```
+
+### 文件消息
+```javascript
+{
+ id: 3,
+ role: 'ai',
+ type: 'file',
+ fileName: '文档.pdf',
+ fileSize: 1024000,
+ url: '文件地址',
+ timestamp: Date.now()
+}
+```
+
+### 音频消息
+```javascript
+{
+ id: 4,
+ role: 'ai',
+ type: 'audio',
+ title: '语音消息',
+ duration: 60, // 秒
+ url: '音频地址',
+ timestamp: Date.now()
+}
+```
+
+### 视频消息
+```javascript
+{
+ id: 5,
+ role: 'ai',
+ type: 'video',
+ title: '产品介绍',
+ duration: 120, // 秒
+ url: '视频地址',
+ cover: '封面图',
+ timestamp: Date.now()
+}
+```
+
+### 链接消息
+```javascript
+{
+ id: 6,
+ role: 'ai',
+ type: 'link',
+ title: '帮助文档',
+ description: '详细的使用说明',
+ url: 'https://example.com',
+ image: '缩略图',
+ timestamp: Date.now()
+}
+```
+
+### 商品卡片
+```javascript
+{
+ id: 7,
+ role: 'ai',
+ type: 'product',
+ title: '商品名称',
+ price: 299,
+ description: '商品描述',
+ image: '商品图片',
+ timestamp: Date.now()
+}
+```
+
+## 方法
+
+通过 ref 调用组件方法:
+
+```javascript
+// 添加消息
+this.$refs.chat.addMessage(message)
+
+// 清空消息
+this.$refs.chat.clearMessages()
+
+// 滚动到底部
+this.$refs.chat.scrollToBottom()
+```
+
+## 样式定制
+
+组件使用 SCSS 编写,可以通过 CSS 变量进行主题定制:
+
+```css
+.ai-chat-container {
+ --primary-color: #ff4544;
+ --bg-color: #f8f8f8;
+ --text-color: #333;
+}
+```
+
+## 方法
+
+通过 ref 调用组件方法:
+
+```javascript
+// 添加消息
+this.$refs.chat.addMessage(message)
+
+// 清空消息
+this.$refs.chat.clearMessages()
+
+// 滚动到底部
+this.$refs.chat.scrollToBottom()
+
+// 开始语音输入
+this.$refs.chat.startVoiceInput()
+
+// 停止语音输入
+this.$refs.chat.stopVoiceInput()
+```
+
+## 样式定制
+
+组件使用 SCSS 编写,可以通过 CSS 变量进行主题定制:
+
+```css
+.ai-chat-container {
+ --primary-color: #ff4544;
+ --bg-color: #f8f8f8;
+ --text-color: #333;
+ --border-color: #eeeeee;
+ --user-bg: #e6f7ff;
+ --ai-bg: #f6f6f6;
+}
+```
+
+## 图标字体
+
+组件使用自定义图标字体,需要在页面中引入:
+
+```html
+
+```
+
+## 注意事项
+
+1. 组件已适配项目中已有的 `ns-loading` 组件
+2. 需要配置对应的图标字体文件
+3. 音频播放功能在 H5 和 APP 端支持较好
+4. 文件预览功能依赖平台能力
+5. 语音输入功能需要用户授权麦克风权限
\ No newline at end of file
diff --git a/components/ai-chat-message/ai-chat-message.json b/components/ai-chat-message/ai-chat-message.json
new file mode 100644
index 0000000..d806736
--- /dev/null
+++ b/components/ai-chat-message/ai-chat-message.json
@@ -0,0 +1,6 @@
+{
+ "component": true,
+ "usingComponents": {
+ "ns-loading": "../ns-loading/ns-loading"
+ }
+}
\ No newline at end of file
diff --git a/components/ai-chat-message/ai-chat-message.vue b/components/ai-chat-message/ai-chat-message.vue
new file mode 100644
index 0000000..444afcf
--- /dev/null
+++ b/components/ai-chat-message/ai-chat-message.vue
@@ -0,0 +1,1424 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.content }}
+
+ {{ formatTime(message.timestamp) }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.fileName }}
+ {{ formatFileSize(message.fileSize) }}
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.title || '语音消息' }}
+ {{ formatDuration(message.duration) }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.title || '视频消息' }}
+ {{ formatDuration(message.duration) }}
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.title }}
+ {{ message.description }}
+ {{ message.url }}
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.title }}
+ ¥{{ message.price }}
+ {{ message.description }}
+
+
+
+
+
+
+
+
+
+
+
+ AI正在思考中...
+
+
+
+
+
+
+
+ {{ formatTime(message.timestamp) }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/ai-chat-message/demo.vue b/components/ai-chat-message/demo.vue
new file mode 100644
index 0000000..dad9d5f
--- /dev/null
+++ b/components/ai-chat-message/demo.vue
@@ -0,0 +1,288 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file