初始化项目:添加基础项目结构和配置
This commit is contained in:
commit
ce52a06ee7
|
@ -0,0 +1,2 @@
|
|||
VITE_APP_BASE_API=http://160.202.224.52:31002
|
||||
VITE_APP_ENV=default
|
|
@ -0,0 +1,2 @@
|
|||
VITE_APP_BASE_API=http://160.202.224.52:31002
|
||||
VITE_APP_ENV=development
|
|
@ -0,0 +1,2 @@
|
|||
VITE_APP_BASE_API=http://api.production.com
|
||||
VITE_APP_ENV=production
|
|
@ -0,0 +1,24 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"recommendations": ["Vue.volar"]
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
# Vue 3 + Vite 微信聊天项目
|
||||
|
||||
这是一个基于 Vue 3 和 Vite 构建的微信风格聊天应用。
|
||||
|
||||
## 技术栈
|
||||
|
||||
- Vue 3 - 渐进式 JavaScript 框架
|
||||
- Vite - 下一代前端构建工具
|
||||
- Vue Router - 官方路由管理器
|
||||
- Pinia - Vue 的官方状态管理库
|
||||
- TypeScript - JavaScript 的超集
|
||||
- Tailwind CSS - 实用优先的 CSS 框架
|
||||
|
||||
## 功能特性
|
||||
|
||||
- 实时消息通信
|
||||
- 好友列表管理
|
||||
- 群聊功能
|
||||
- 消息历史记录
|
||||
- 文件传输
|
||||
- 表情包支持
|
||||
|
||||
## 开始使用
|
||||
|
||||
### 环境要求
|
||||
|
||||
- Node.js 16.x 或更高版本
|
||||
- npm 7.x 或更高版本 或 yarn 1.22.x 或更高版本
|
||||
|
||||
### 安装依赖
|
||||
|
||||
使用 npm:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
使用 yarn:
|
||||
```bash
|
||||
yarn install
|
||||
```
|
||||
|
||||
### 开发环境运行
|
||||
|
||||
使用 npm:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
使用 yarn:
|
||||
```bash
|
||||
yarn dev
|
||||
```
|
||||
|
||||
### 生产环境构建
|
||||
|
||||
使用 npm:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
使用 yarn:
|
||||
```bash
|
||||
yarn build
|
||||
```
|
||||
|
||||
### 代码检查
|
||||
|
||||
使用 npm:
|
||||
```bash
|
||||
npm run lint
|
||||
```
|
||||
|
||||
使用 yarn:
|
||||
```bash
|
||||
yarn lint
|
||||
```
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
src/
|
||||
├── api/ # 接口函数
|
||||
├── assets/ # 静态资源
|
||||
├── components/ # 公共组件
|
||||
├── layoyts/ # 布局组件
|
||||
├── views/ # 页面组件
|
||||
├── router/ # 路由配置
|
||||
├── store/ # 状态管理
|
||||
├── utils/ # 工具函数
|
||||
└── App.vue # 根组件
|
||||
```
|
||||
|
||||
## 开发指南
|
||||
|
||||
1. 克隆项目到本地
|
||||
2. 安装依赖(选择 npm 或 yarn)
|
||||
3. 运行开发服务器
|
||||
4. 开始开发
|
||||
|
||||
## 贡献指南
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
||||
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
||||
5. 创建 Pull Request
|
||||
|
||||
## 许可证
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
## 联系方式
|
||||
|
||||
如有任何问题或建议,请通过以下方式联系我们:
|
||||
|
||||
- 提交 Issue
|
||||
- 发送邮件至 [your-email@example.com]
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Vue</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "wx-chat",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --mode development",
|
||||
"dev:test": "vite --mode test",
|
||||
"build": "vite build",
|
||||
"build:test": "vite build --mode test",
|
||||
"build:prod": "vite build --mode production",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"axios": "^1.8.4",
|
||||
"echarts": "^5.6.0",
|
||||
"element-plus": "^2.9.7",
|
||||
"marked": "^15.0.8",
|
||||
"pinia": "^3.0.2",
|
||||
"pinia-plugin-persistedstate": "^4.2.0",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"sass-embedded": "^1.86.3",
|
||||
"vite": "^6.2.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,22 @@
|
|||
<script setup>
|
||||
import { RouterView } from "vue-router";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view></router-view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.vue:hover {
|
||||
filter: drop-shadow(0 0 2em #42b883aa);
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,11 @@
|
|||
import { sseRequest } from '@/utils/request'
|
||||
|
||||
export function sendMessage(data, token) {
|
||||
return sseRequest({
|
||||
url: '/api/v1/chat-messages',
|
||||
params: data,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
After Width: | Height: | Size: 496 B |
|
@ -0,0 +1,43 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps({
|
||||
msg: String,
|
||||
})
|
||||
|
||||
const count = ref(0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>{{ msg }}</h1>
|
||||
|
||||
<div class="card">
|
||||
<button type="button" @click="count++">count is {{ count }}</button>
|
||||
<p>
|
||||
Edit
|
||||
<code>components/HelloWorld.vue</code> to test HMR
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Check out
|
||||
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
|
||||
>create-vue</a
|
||||
>, the official Vue + Vite starter
|
||||
</p>
|
||||
<p>
|
||||
Learn more about IDE Support for Vue in the
|
||||
<a
|
||||
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
|
||||
target="_blank"
|
||||
>Vue Docs Scaling up Guide</a
|
||||
>.
|
||||
</p>
|
||||
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,78 @@
|
|||
<template>
|
||||
<aside class="sidebar">
|
||||
<ul>
|
||||
<li v-for="route in routes" :key="route.path" @click="navigateTo(route.path)">
|
||||
<component
|
||||
class="icon"
|
||||
:class="{ active: routeStore.currentRoute === route.path }"
|
||||
:is="route.meta?.icon"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { computed } from 'vue'
|
||||
import { useRouteStore } from '@/store/route'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const routeStore = useRouteStore()
|
||||
|
||||
// 获取所有路由配置
|
||||
const routes = computed(() => {
|
||||
return router.getRoutes().filter(route => !route.meta?.hidden && !route.children?.length)
|
||||
})
|
||||
|
||||
// 导航方法
|
||||
const navigateTo = (path) => {
|
||||
routeStore.updateCurrentRoute(path)
|
||||
router.push(path)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.sidebar {
|
||||
width: 60px;
|
||||
height: inherit;
|
||||
background-color: #f0f0f0;
|
||||
border-right: 1px solid #e0e0e0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 10px 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.sidebar ul {
|
||||
height: inherit;
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sidebar li {
|
||||
height: 60px;
|
||||
width: 60px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.sidebar li .icon {
|
||||
margin: 8px;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.sidebar li .icon:hover {
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
.sidebar li .icon.active {
|
||||
color: #07c160;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,47 @@
|
|||
<template>
|
||||
<div class="main-layout">
|
||||
<Sidebar />
|
||||
<main class="content-area">
|
||||
<!-- 路由视图将渲染在这里 -->
|
||||
<router-view />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Sidebar from '../components/Sidebar.vue'
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.main-layout {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
min-width: 640px;
|
||||
overflow: hidden; /* 防止内部滚动影响布局 */
|
||||
}
|
||||
|
||||
.content-area {
|
||||
flex-grow: 1;
|
||||
/* display: flex; /* 如果内容区内部还需要左右布局,可以打开 */
|
||||
/* flex-direction: row; /* 配合上面 */
|
||||
overflow-y: auto; /* 如果内容区需要滚动 */
|
||||
background-color: #ffffff; /* 示例背景色 */
|
||||
}
|
||||
|
||||
/* 简单的侧边栏列表样式 */
|
||||
.sidebar ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sidebar li {
|
||||
padding: 15px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.sidebar li:hover {
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1 @@
|
|||
<template></template>
|
|
@ -0,0 +1,22 @@
|
|||
import { createApp } from "vue";
|
||||
import "./style.css";
|
||||
import App from "./App.vue";
|
||||
import {router} from "@/router/index";
|
||||
import { createPinia } from "pinia";
|
||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
|
||||
// 引入 Element Plus
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
|
||||
|
||||
const pinia = createPinia();
|
||||
pinia.use(piniaPluginPersistedstate)
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
app.use(ElementPlus, {
|
||||
locale: zhCn,
|
||||
})
|
||||
app.mount("#app");
|
|
@ -0,0 +1,38 @@
|
|||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import { ChatRound } from '@element-plus/icons-vue'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
component: () => import("@/layouts/MainLayout.vue"),
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "blank",
|
||||
meta: {
|
||||
hidden: true,
|
||||
},
|
||||
component: () => import("@/layouts/blank.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/chat",
|
||||
component: () => import("@/layouts/MainLayout.vue"),
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "chat",
|
||||
meta: {
|
||||
icon: ChatRound
|
||||
},
|
||||
component: () => import("@/views/chat/index.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
});
|
|
@ -0,0 +1,315 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { sendMessage } from '@/api/chat'
|
||||
|
||||
const chatModes = {
|
||||
training: {
|
||||
name: '寿险代理人AI陪练',
|
||||
icon: 'fas fa-user-tie',
|
||||
token: 'app-88ae2GN49aUyNO6qGg7tbTfX'
|
||||
},
|
||||
quote_objection: {
|
||||
name: '报价中异议',
|
||||
icon: 'fas fa-comments',
|
||||
token: 'app-88ae2GN49aUyNO6qGg7tbTfX'
|
||||
},
|
||||
post_quote_objection: {
|
||||
name: '报价后异议',
|
||||
icon: 'fas fa-comment-dollar',
|
||||
token: 'app-88ae2GN49aUyNO6qGg7tbTfX'
|
||||
}
|
||||
}
|
||||
// 返回示例
|
||||
/*
|
||||
data: {"event": "message", "conversation_id": "fac9e3e7-2b2e-4fc2-bf19-0a6d4cfcf529", "message_id": "e8f42230-205c-4f31-b068-86b37a18c2ee", "created_at": 1744881805, "task_id": "ec521a05-6068-427a-ac5d-d349f0d05874", "id": "e8f42230-205c-4f31-b068-86b37a18c2ee", "answer": "\u7684\u65b9\u5411", "from_variable_selector": ["17441814078920", "text"]}
|
||||
data: {"event": "message", "conversation_id": "fac9e3e7-2b2e-4fc2-bf19-0a6d4cfcf529", "message_id": "e8f42230-205c-4f31-b068-86b37a18c2ee", "created_at": 1744881805, "task_id": "ec521a05-6068-427a-ac5d-d349f0d05874", "id": "e8f42230-205c-4f31-b068-86b37a18c2ee", "answer": "\u3002", "from_variable_selector": ["17441814078920", "text"]}
|
||||
data: {"event": "message_end", "conversation_id": "fac9e3e7-2b2e-4fc2-bf19-0a6d4cfcf529", "message_id": "e8f42230-205c-4f31-b068-86b37a18c2ee", "created_at": 1744881805, "task_id": "ec521a05-6068-427a-ac5d-d349f0d05874", "id": "e8f42230-205c-4f31-b068-86b37a18c2ee", "metadata": {"usage": {"prompt_tokens": 2483, "prompt_unit_price": "4.13", "prompt_price_unit": "0.000001", "prompt_price": "0.0102548", "completion_tokens": 142, "completion_unit_price": "4.13", "completion_price_unit": "0.000001", "completion_price": "0.0005865", "total_tokens": 2625, "total_price": "0.0108413", "currency": "RMB", "latency": 13.045417829882354}}, "files": []}
|
||||
*/
|
||||
|
||||
|
||||
const tagList = ['kehu', 'pingfen', 'zongjie', 'dafen']
|
||||
|
||||
// 处理标签内容的辅助函数
|
||||
const processTagContent = (answerCache, tagName, cachedMessage) => {
|
||||
// 检查是否包含完整的开始标签
|
||||
const startTag = `<${tagName}>`
|
||||
const endTag = `</${tagName}>`
|
||||
|
||||
// 如果正在处理该标签
|
||||
if (cachedMessage.respondingType === tagName) {
|
||||
// 检查是否包含结束标签
|
||||
if (answerCache.includes(endTag)) {
|
||||
// 提取结束标签前的内容
|
||||
const content = answerCache.split(endTag)[0]
|
||||
cachedMessage[tagName] += content
|
||||
cachedMessage.respondingType = ''
|
||||
return answerCache.split(endTag)[1] || ''
|
||||
} else {
|
||||
// 继续累积内容
|
||||
cachedMessage[tagName] += answerCache
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否包含开始标签
|
||||
if (answerCache.includes(startTag)) {
|
||||
cachedMessage.respondingType = tagName
|
||||
const tagContent = answerCache.split(startTag)[1] || ''
|
||||
|
||||
// 检查开始标签后是否立即包含结束标签
|
||||
if (tagContent.includes(endTag)) {
|
||||
const content = tagContent.split(endTag)[0]
|
||||
cachedMessage[tagName] = content
|
||||
cachedMessage.respondingType = ''
|
||||
return answerCache.split(endTag)[1] || ''
|
||||
} else {
|
||||
// 只有开始标签,累积内容
|
||||
cachedMessage[tagName] = tagContent
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
return answerCache
|
||||
}
|
||||
|
||||
export const useChatStore = defineStore('chat', {
|
||||
state: () => ({
|
||||
messages: {},
|
||||
currentMode: 'training',
|
||||
conversationId: null,
|
||||
messageCache: {},
|
||||
}),
|
||||
|
||||
getters: {
|
||||
chatModes: () => chatModes,
|
||||
currentToken: (state) => chatModes[state.currentMode].token,
|
||||
currentConversation: (state) => {
|
||||
return state.conversationId ? state.messages[state.conversationId] : null
|
||||
},
|
||||
currentMessages: (state) => {
|
||||
// 根据conversationId和currentMode找到对应的messageCache的messageId
|
||||
const cache = Object.values(state.messageCache).find(message =>
|
||||
message.mode === state.currentMode && message.conversationId === state.conversationId
|
||||
)
|
||||
|
||||
// 获取当前会话的消息
|
||||
const currentConversation = state.conversationId ? state.messages[state.conversationId] : null
|
||||
const conversationMessages = currentConversation ? currentConversation.chatMessages : []
|
||||
|
||||
return conversationMessages.filter(message =>
|
||||
message.mode === state.currentMode &&
|
||||
(message.conversationId === state.conversationId || !state.conversationId) &&
|
||||
(!cache || message.messageId !== cache.messageId)
|
||||
).concat(cache ? [cache] : [])
|
||||
},
|
||||
// 获取所有会话列表
|
||||
conversations: (state) => {
|
||||
return Object.entries(state.messages).map(([conversationId, conversation]) => ({
|
||||
conversationId,
|
||||
mode: conversation.chatModes,
|
||||
messages: conversation.chatMessages,
|
||||
status: conversation.conversationStatus,
|
||||
summary: conversation.summary,
|
||||
// 使用第一条消息的时间作为会话创建时间
|
||||
createdAt: conversation.chatMessages[0]?.createdAt || 0
|
||||
})).sort((a, b) => b.createdAt - a.createdAt) // 按时间倒序排序
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
setCurrentMode(mode) {
|
||||
this.currentMode = mode
|
||||
|
||||
// 找到当前模式的最后一条会话
|
||||
const lastConversation = this.conversations
|
||||
.filter(conv => conv.mode === mode)
|
||||
.sort((a, b) => b.createdAt - a.createdAt)[0]
|
||||
|
||||
// 设置当前会话ID
|
||||
this.conversationId = lastConversation?.conversationId || null
|
||||
|
||||
console.log('%c currentConversation:', 'color: #2196F3; font-weight: bold', {
|
||||
mode,
|
||||
lastConversation,
|
||||
currentConversation: this.currentConversation
|
||||
})
|
||||
},
|
||||
|
||||
// 切换到指定会话
|
||||
switchConversation(conversationId) {
|
||||
if (this.messages[conversationId]) {
|
||||
this.conversationId = conversationId
|
||||
// 清除当前的消息缓存
|
||||
Object.keys(this.messageCache).forEach(messageId => {
|
||||
if (this.messageCache[messageId].conversationId === conversationId) {
|
||||
delete this.messageCache[messageId]
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async sendMessage(question) {
|
||||
if (!question.trim()) return
|
||||
|
||||
// 设置会话状态为正在输入
|
||||
if (this.conversationId && this.messages[this.conversationId]) {
|
||||
this.messages[this.conversationId].conversationStatus = 'typing'
|
||||
}
|
||||
|
||||
this.hasStartedResponse = false
|
||||
|
||||
try {
|
||||
const messageStream = await sendMessage({
|
||||
inputs: {},
|
||||
query: question,
|
||||
response_mode: 'streaming',
|
||||
conversation_id: this.conversationId,
|
||||
user: 'sys123'
|
||||
}, this.currentToken)
|
||||
|
||||
let answerCache = ''
|
||||
for await (const message of messageStream) {
|
||||
if (!message || !message.event) {
|
||||
continue
|
||||
}
|
||||
switch (message.event) {
|
||||
case 'workflow_started':
|
||||
console.log('%c workflow_started:message:', 'color: #2196F3; font-weight: bold', message)
|
||||
// 创建新消息对象
|
||||
const currentMessage = {
|
||||
mode: this.currentMode,
|
||||
conversationId: message.conversation_id,
|
||||
messageId: message.message_id,
|
||||
createdAt: message.created_at,
|
||||
question: question,
|
||||
answerBuffer: '',
|
||||
showEvaluation: true,
|
||||
respondingType: '',
|
||||
kehu: '',
|
||||
pingfen: '',
|
||||
zongjie: '',
|
||||
dafen: '',
|
||||
}
|
||||
this.conversationId = message.conversation_id
|
||||
this.messageCache[message.message_id] = currentMessage
|
||||
|
||||
// 初始化会话消息结构
|
||||
if (!this.messages[currentMessage.conversationId]) {
|
||||
this.messages[currentMessage.conversationId] = {
|
||||
chatModes: currentMessage.mode,
|
||||
chatMessages: [],
|
||||
conversationStatus: 'typing', // 会话状态 active 活跃,finished 已完成, typing 正在输入
|
||||
//总结
|
||||
summary: '',
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'message':
|
||||
if (message.answer) {
|
||||
console.log('%c message:answer:', 'color: #2196F3; font-weight: bold', message.answer)
|
||||
answerCache += message.answer
|
||||
const cachedMessage = this.messageCache[message.message_id]
|
||||
if (cachedMessage) {
|
||||
// 依次处理每个标签
|
||||
for (const tag of tagList) {
|
||||
answerCache = processTagContent(answerCache, tag, cachedMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'workflow_finished':
|
||||
console.log('%c workflow_finished:message:', 'color: #2196F3; font-weight: bold', message)
|
||||
if (this.messageCache[message.message_id]) {
|
||||
const cachedMessage = this.messageCache[message.message_id]
|
||||
if (cachedMessage) {
|
||||
cachedMessage.respondingType = ''
|
||||
cachedMessage.answerBuffer = message.data.outputs.answer
|
||||
|
||||
|
||||
this.messages[cachedMessage.conversationId].chatMessages.push(cachedMessage)
|
||||
|
||||
// 如果包含dafen标签,将会话标记为完成并将打分内容归档到summary
|
||||
if (cachedMessage.dafen) {
|
||||
this.messages[cachedMessage.conversationId].conversationStatus = 'finished'
|
||||
this.messages[cachedMessage.conversationId].summary = cachedMessage.dafen
|
||||
} else {
|
||||
// 恢复会话状态为活跃
|
||||
this.messages[cachedMessage.conversationId].conversationStatus = 'active'
|
||||
}
|
||||
|
||||
console.log('%c workflow_finished:cachedMessage:', 'color: #ff0000; font-weight: bold', cachedMessage)
|
||||
}
|
||||
delete this.messageCache[message.message_id]
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('发送消息失败:', error)
|
||||
throw error
|
||||
}
|
||||
},
|
||||
toggleEvaluation(messageId) {
|
||||
console.log('%c toggleEvaluation:messageId:', 'color: #2196F3; font-weight: bold', messageId)
|
||||
const cache = Object.values(this.messageCache).find(message =>
|
||||
message.mode === this.currentMode && message.messageId === messageId
|
||||
)
|
||||
if (cache) {
|
||||
cache.showEvaluation = !cache.showEvaluation
|
||||
} else {
|
||||
// 遍历所有会话查找消息
|
||||
for (const conversationId in this.messages) {
|
||||
const conversation = this.messages[conversationId]
|
||||
const message = conversation.chatMessages.find(msg => msg.messageId === messageId)
|
||||
if (message) {
|
||||
message.showEvaluation = !message.showEvaluation
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
startNewChat() {
|
||||
// 如果当前有活跃会话,将其标记为完成
|
||||
if (this.conversationId && this.messages[this.conversationId]) {
|
||||
this.messages[this.conversationId].conversationStatus = 'finished'
|
||||
}
|
||||
|
||||
// 只清除当前会话相关的消息缓存
|
||||
if (this.conversationId) {
|
||||
// 从messageCache中删除当前会话的消息
|
||||
Object.keys(this.messageCache).forEach(messageId => {
|
||||
if (this.messageCache[messageId].conversationId === this.conversationId) {
|
||||
delete this.messageCache[messageId]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 清除当前会话ID
|
||||
this.conversationId = null
|
||||
},
|
||||
|
||||
// 删除指定会话
|
||||
deleteConversation(conversationId) {
|
||||
// 如果要删除的是当前会话,先清除相关缓存
|
||||
if (this.conversationId === conversationId) {
|
||||
Object.keys(this.messageCache).forEach(messageId => {
|
||||
if (this.messageCache[messageId].conversationId === conversationId) {
|
||||
delete this.messageCache[messageId]
|
||||
}
|
||||
})
|
||||
this.conversationId = null
|
||||
}
|
||||
|
||||
// 从messages中删除会话
|
||||
if (this.messages[conversationId]) {
|
||||
delete this.messages[conversationId]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
persist: {
|
||||
key: 'chatStore',
|
||||
storage: sessionStorage,
|
||||
paths: ['messages', 'currentMode', 'conversationId']
|
||||
}
|
||||
})
|
|
@ -0,0 +1,12 @@
|
|||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useRouteStore = defineStore('route', {
|
||||
state: () => ({
|
||||
currentRoute: '/'
|
||||
}),
|
||||
actions: {
|
||||
updateCurrentRoute(path) {
|
||||
this.currentRoute = path
|
||||
}
|
||||
}
|
||||
})
|
|
@ -0,0 +1,82 @@
|
|||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
/* display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px; */
|
||||
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
/* max-width: 100vh; */
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
import axios from 'axios'
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: process.env.VITE_APP_BASE_API,
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
// 如果配置中已经包含了 Authorization header,则使用配置中的值
|
||||
if (!config.headers['Authorization']) {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers['Authorization'] = `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
config.headers['Content-Type'] = 'application/json'
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
return response.data
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// SSE 请求方法
|
||||
export const sseRequest = (config) => {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const url = new URL(`${config.url}`, window.location.origin)
|
||||
const ctrl = new AbortController()
|
||||
let messageQueue = []
|
||||
let resolveQueue = null
|
||||
|
||||
const messageGenerator = async function* () {
|
||||
const source = new fetchEventSource(url.toString(), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': config.headers?.Authorization || `Bearer ${localStorage.getItem('token')}`,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'text/event-stream'
|
||||
},
|
||||
body: JSON.stringify(config.params),
|
||||
signal: ctrl.signal,
|
||||
openWhenHidden: true,
|
||||
onmessage: (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data)
|
||||
if (resolveQueue) {
|
||||
resolveQueue(data)
|
||||
resolveQueue = null
|
||||
} else {
|
||||
messageQueue.push(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing SSE message:', error)
|
||||
}
|
||||
},
|
||||
onerror: (error) => {
|
||||
console.error('EventSource failed:', error)
|
||||
ctrl.abort()
|
||||
if (resolveQueue) {
|
||||
resolveQueue(null)
|
||||
resolveQueue = null
|
||||
}
|
||||
},
|
||||
onclose: () => {
|
||||
console.log('Connection closed')
|
||||
if (resolveQueue) {
|
||||
resolveQueue(null)
|
||||
resolveQueue = null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
if (messageQueue.length > 0) {
|
||||
yield messageQueue.shift()
|
||||
} else {
|
||||
const message = await new Promise(resolve => {
|
||||
resolveQueue = resolve
|
||||
})
|
||||
if (message === null) {
|
||||
break
|
||||
}
|
||||
yield message
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ctrl.abort()
|
||||
}
|
||||
}
|
||||
|
||||
resolve(messageGenerator())
|
||||
} catch (error) {
|
||||
console.error('SSE request setup failed:', error)
|
||||
resolve((async function* () {})())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default service
|
|
@ -0,0 +1,15 @@
|
|||
<template>
|
||||
<div class="home">
|
||||
<h1>欢迎使用微信聊天助手</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
// 首页组件逻辑
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.home {
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,25 @@
|
|||
<template>
|
||||
<div class="settings">
|
||||
<h1>设置</h1>
|
||||
<div class="settings-container">
|
||||
<!-- 设置选项将在这里显示 -->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
// 设置组件逻辑
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.settings {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
margin-top: 20px;
|
||||
padding: 20px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,876 @@
|
|||
<template>
|
||||
<div class="chat-container">
|
||||
<div class="chat-messages" ref="chatContainer">
|
||||
<!-- 历史缓存 -->
|
||||
<div v-for="(message, index) in currentMessages" :key="message.messageId" class="message-group">
|
||||
<!-- 用户消息 -->
|
||||
<div class="message">
|
||||
<div class="message-wrapper user">
|
||||
<div class="avatar"><span class="emoji">👤</span></div>
|
||||
<div class="message-content">
|
||||
<div class="message-text-wrapper">
|
||||
<div class="message-text">{{ message.question }}</div>
|
||||
</div>
|
||||
<!-- 改进建议部分 -->
|
||||
<div class="evaluation-toggle" @click="chatStore.toggleEvaluation(message.messageId)">
|
||||
<span class="evaluation-btn">改进建议</span>
|
||||
<span v-if="['pingfen', 'zongjie'].includes(message.respondingType)" class="typing-indicator evaluation-icon">
|
||||
<span></span><span></span><span></span>
|
||||
</span>
|
||||
<span v-else class="evaluation-icon">{{ message.showEvaluation ? '▼' : '▶' }}</span>
|
||||
</div>
|
||||
<!-- 评价总结内容 -->
|
||||
<div v-if="message.showEvaluation && (message.pingfen || message.zongjie)" class="evaluation-section">
|
||||
<div class="evaluation-content">
|
||||
<div class="evaluation-text pingfen" v-html="formatMarkdown(message.pingfen, 'pingfen')"></div>
|
||||
<div class="evaluation-text zongjie" v-html="formatMarkdown(message.zongjie, 'zongjie')"></div>
|
||||
<div v-if="['pingfen', 'zongjie'].includes(message.respondingType)" class="typing-indicator">
|
||||
<span></span><span></span><span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 回答 -->
|
||||
<div class="message">
|
||||
<div class="message-wrapper assistant">
|
||||
<div class="avatar"><span class="emoji">🤖</span></div>
|
||||
<div class="message-content">
|
||||
<div class="message-text-wrapper">
|
||||
<div class="message-text" v-html="message.kehu"></div>
|
||||
<div v-if="message.respondingType === 'kehu'" class="typing-indicator">
|
||||
<span></span><span></span><span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-area">
|
||||
<button class="new-chat-btn" @click="chatStore.startNewChat" :disabled="newChatButtonsDisabled">
|
||||
<span class="new-chat-icon">+</span>
|
||||
新会话
|
||||
</button>
|
||||
<textarea
|
||||
v-model="messageInput"
|
||||
@keyup.enter.exact="sendMessage"
|
||||
@keydown.enter.exact.prevent
|
||||
placeholder="请输入消息..."
|
||||
rows="1"
|
||||
ref="messageInputRef"
|
||||
@input="adjustTextareaHeight"
|
||||
></textarea>
|
||||
<button class="send-btn" @click="sendMessage" :disabled="sendButtonsDisabled">发送</button>
|
||||
</div>
|
||||
<!-- 添加总结弹窗 -->
|
||||
<div v-if="lastMessageWithDafen" class="summary-panel" :class="{ 'summary-panel-collapsed': isSummaryCollapsed }">
|
||||
<div class="summary-header" @click="toggleSummary">
|
||||
<span class="summary-title">会话总结</span>
|
||||
<span class="summary-toggle-icon">{{ isSummaryCollapsed ? '▼' : '▲' }}</span>
|
||||
</div>
|
||||
<div class="summary-content" v-html="formatMarkdown(lastMessageWithDafen.dafen)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted, nextTick, watch, computed, defineOptions } from 'vue'
|
||||
import { marked } from 'marked'
|
||||
import * as echarts from 'echarts'
|
||||
import { useChatStore } from '@/store/chat'
|
||||
|
||||
defineOptions({
|
||||
name: 'ChatInterface'
|
||||
})
|
||||
|
||||
const chatStore = useChatStore()
|
||||
const messageInput = ref('')
|
||||
const messageInputRef = ref(null)
|
||||
const chatContainer = ref(null)
|
||||
const scoreChart = ref(null)
|
||||
const maxRows = 6
|
||||
const isUserScrolling = ref(false)
|
||||
const shouldAutoScroll = ref(true)
|
||||
const lastScrollTop = ref(0)
|
||||
const lastScrollHeight = ref(0)
|
||||
const isSummaryCollapsed = ref(false)
|
||||
|
||||
// 使用计算属性获取当前会话的消息
|
||||
const currentMessages = computed(() => {
|
||||
return chatStore.currentMessages
|
||||
})
|
||||
const sendButtonsDisabled = computed(() => {
|
||||
if (!chatStore.currentConversation) return false
|
||||
const currentConversation = chatStore.currentConversation
|
||||
if (!currentConversation.conversationStatus) return false
|
||||
return ['finished', 'typing'].includes(currentConversation.conversationStatus)
|
||||
})
|
||||
const newChatButtonsDisabled = computed(() => {
|
||||
if (!chatStore.currentConversation) return false
|
||||
const currentConversation = chatStore.currentConversation
|
||||
if (!currentConversation.conversationStatus) return false
|
||||
return ['typing'].includes(currentConversation.conversationStatus)
|
||||
})
|
||||
|
||||
// 获取最后一条包含dafen字段的消息
|
||||
const lastMessageWithDafen = computed(() => {
|
||||
if (!chatStore.currentMessages.length) return null
|
||||
// 从后往前查找第一条包含dafen字段的消息
|
||||
for (let i = chatStore.currentMessages.length - 1; i >= 0; i--) {
|
||||
if (chatStore.currentMessages[i].dafen) {
|
||||
return chatStore.currentMessages[i]
|
||||
}
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
// 配置marked选项
|
||||
marked.setOptions({
|
||||
breaks: true,
|
||||
gfm: true,
|
||||
sanitize: false,
|
||||
headerIds: false,
|
||||
mangle: false
|
||||
})
|
||||
|
||||
// 检查是否接近底部
|
||||
const isNearBottom = (threshold = 100) => {
|
||||
const container = chatContainer.value
|
||||
if (!container) return false
|
||||
return container.scrollHeight - container.scrollTop - container.clientHeight < threshold
|
||||
}
|
||||
|
||||
// 监听滚动事件
|
||||
const handleScroll = () => {
|
||||
const container = chatContainer.value
|
||||
if (!container) return
|
||||
|
||||
// 检测是否是用户主动滚动
|
||||
if (Math.abs(container.scrollTop - lastScrollTop.value) > 10) {
|
||||
isUserScrolling.value = true
|
||||
// 根据是否接近底部来决定是否恢复自动滚动
|
||||
shouldAutoScroll.value = isNearBottom(50)
|
||||
}
|
||||
|
||||
lastScrollTop.value = container.scrollTop
|
||||
lastScrollHeight.value = container.scrollHeight
|
||||
}
|
||||
|
||||
// 滚动到底部的方法
|
||||
const scrollToBottom = (force = false) => {
|
||||
nextTick(() => {
|
||||
const container = chatContainer.value
|
||||
if (!container) return
|
||||
|
||||
// 在以下情况下滚动到底部:
|
||||
// 1. 强制滚动
|
||||
// 2. 允许自动滚动且没有用户滚动操作
|
||||
// 3. 用户已经接近底部
|
||||
if (force || (shouldAutoScroll.value && !isUserScrolling.value) || isNearBottom(50)) {
|
||||
container.scrollTop = container.scrollHeight
|
||||
lastScrollTop.value = container.scrollTop
|
||||
lastScrollHeight.value = container.scrollHeight
|
||||
isUserScrolling.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 监听消息缓存变化
|
||||
watch(() => chatStore.messageCache, (newCache, oldCache) => {
|
||||
if (!oldCache || Object.keys(newCache).length > Object.keys(oldCache).length) {
|
||||
scrollToBottom(shouldAutoScroll.value)
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
// 监听当前会话的消息
|
||||
watch(() => currentMessages.value, (newMessages, oldMessages) => {
|
||||
if (!oldMessages || newMessages.length > oldMessages.length) {
|
||||
scrollToBottom(shouldAutoScroll.value)
|
||||
return
|
||||
}
|
||||
|
||||
// 检查最后一条消息的respondingType
|
||||
const lastMessage = newMessages[newMessages.length - 1]
|
||||
if (lastMessage && ['kehu', 'pingfen', 'zongjie'].includes(lastMessage.respondingType)) {
|
||||
scrollToBottom(true) // 特定类型消息强制滚动
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
// 监听消息的respondingType变化
|
||||
watch(() => currentMessages.value?.map(msg => msg.respondingType), (newTypes, oldTypes) => {
|
||||
if (!newTypes || !oldTypes) return
|
||||
const lastType = newTypes[newTypes.length - 1]
|
||||
if (['kehu', 'pingfen', 'zongjie'].includes(lastType)) {
|
||||
scrollToBottom(true) // 特定类型消息强制滚动
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
// 发送消息时滚动到底部
|
||||
const sendMessage = () => {
|
||||
if (!messageInput.value.trim()) return
|
||||
chatStore.sendMessage(messageInput.value)
|
||||
messageInput.value = ''
|
||||
messageInputRef.value.style.height = 'auto'
|
||||
shouldAutoScroll.value = true // 发送消息时恢复自动滚动
|
||||
scrollToBottom(true)
|
||||
}
|
||||
|
||||
const initChart = () => {
|
||||
if (scoreChart.value) {
|
||||
const chart = echarts.init(scoreChart.value)
|
||||
|
||||
const scoreData = chatStore.score.split(',').map(item => {
|
||||
const [name, value] = item.split(':')
|
||||
return { name, value: parseFloat(value) }
|
||||
})
|
||||
|
||||
const option = {
|
||||
title: {
|
||||
text: '成绩维度分析',
|
||||
left: 'center'
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item'
|
||||
},
|
||||
radar: {
|
||||
indicator: scoreData.map(item => ({
|
||||
name: item.name,
|
||||
max: 100
|
||||
}))
|
||||
},
|
||||
series: [{
|
||||
type: 'radar',
|
||||
data: [{
|
||||
value: scoreData.map(item => item.value),
|
||||
name: '成绩',
|
||||
areaStyle: {
|
||||
color: 'rgba(76, 175, 80, 0.3)'
|
||||
},
|
||||
lineStyle: {
|
||||
color: '#4CAF50'
|
||||
},
|
||||
itemStyle: {
|
||||
color: '#4CAF50'
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
|
||||
chart.setOption(option)
|
||||
|
||||
const handleResize = () => {
|
||||
chart.resize()
|
||||
}
|
||||
|
||||
window.addEventListener('resize', handleResize)
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', handleResize)
|
||||
chart.dispose()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化聊天内容
|
||||
const formatMarkdown = (text, tagType) => {
|
||||
if (!text) return ''
|
||||
return marked.parse(text)
|
||||
}
|
||||
|
||||
const adjustTextareaHeight = () => {
|
||||
const textarea = messageInputRef.value
|
||||
textarea.style.height = 'auto'
|
||||
const newHeight = Math.min(textarea.scrollHeight, maxRows * 24)
|
||||
textarea.style.height = newHeight + 'px'
|
||||
}
|
||||
|
||||
const toggleSummary = () => {
|
||||
isSummaryCollapsed.value = !isSummaryCollapsed.value
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (chatContainer.value) {
|
||||
chatContainer.value.addEventListener('scroll', handleScroll)
|
||||
// 初始化时滚动到底部
|
||||
scrollToBottom(true)
|
||||
shouldAutoScroll.value = true
|
||||
}
|
||||
|
||||
if (chatStore.score && scoreChart.value) {
|
||||
initChart()
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// 移除滚动事件监听
|
||||
if (chatContainer.value) {
|
||||
chatContainer.value.removeEventListener('scroll', handleScroll)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.chat-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: #f5f5f5;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
overflow-y: scroll;
|
||||
padding: 20px;
|
||||
padding-bottom: 120px;
|
||||
padding-right: 24px;
|
||||
margin-right: -12px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
scroll-behavior: smooth;
|
||||
-webkit-overflow-scrolling: touch; // 添加iOS滚动优化
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 4px;
|
||||
border: 2px solid transparent;
|
||||
background-clip: padding-box;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.message-group {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-bottom: 16px;
|
||||
position: relative;
|
||||
|
||||
.message-wrapper {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
&.user {
|
||||
flex-direction: row-reverse;
|
||||
justify-content: flex-start;
|
||||
.message-text {
|
||||
background-color: #95ec69;
|
||||
}
|
||||
.message-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
&.assistant {
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
.message-text {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.message-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
border: 1px solid rgba(0, 0, 0, 0.05);
|
||||
|
||||
.emoji {
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.message-content {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
max-width: 70%;
|
||||
word-wrap: break-word;
|
||||
position: relative;
|
||||
|
||||
.message-text-wrapper {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
|
||||
.message-text {
|
||||
min-height: 36px;
|
||||
line-height: 1.5;
|
||||
font-size: 16px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
white-space: pre-wrap;
|
||||
position: relative;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
border: 1px solid rgba(0, 0, 0, 0.05);
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 6px solid transparent;
|
||||
top: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.evaluation-toggle {
|
||||
display: flex!important;
|
||||
cursor: pointer;
|
||||
color: #576b95;
|
||||
font-size: 13px;
|
||||
margin-top: 8px;
|
||||
padding: 6px 12px;
|
||||
display: block;
|
||||
width: fit-content;
|
||||
align-items: center;
|
||||
border-radius: 6px;
|
||||
background: rgba(87, 107, 149, 0.08);
|
||||
transition: all 0.3s ease;
|
||||
border: 1px solid rgba(87, 107, 149, 0.1);
|
||||
|
||||
&:hover {
|
||||
background: rgba(87, 107, 149, 0.15);
|
||||
border-color: rgba(87, 107, 149, 0.2);
|
||||
}
|
||||
|
||||
.evaluation-btn {
|
||||
padding-right: 4px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.evaluation-icon {
|
||||
font-size: 12px;
|
||||
transition: transform 0.3s ease;
|
||||
|
||||
&.typing-indicator {
|
||||
padding: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
|
||||
span {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
background: #576b95;
|
||||
border-radius: 50%;
|
||||
animation: bounce 1.4s infinite ease-in-out;
|
||||
|
||||
&:nth-child(1) { animation-delay: -0.32s; }
|
||||
&:nth-child(2) { animation-delay: -0.16s; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.evaluation-section {
|
||||
margin-top: 12px;
|
||||
font-size: 14px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
overflow: visible;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
max-width: 100%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.05);
|
||||
position: relative;
|
||||
|
||||
.evaluation-content {
|
||||
padding: 16px 24px 16px 16px;
|
||||
background: #f8f9fa;
|
||||
// max-height: 480px;
|
||||
overflow-y: scroll;
|
||||
position: relative;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 4px;
|
||||
border: 2px solid transparent;
|
||||
background-clip: padding-box;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
.evaluation-text {
|
||||
opacity: 0.9;
|
||||
color: #495057;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
padding: 0;
|
||||
margin-bottom: 12px;
|
||||
min-height: unset;
|
||||
line-height: 1.6;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
:deep(p) {
|
||||
margin: 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
:deep(ul), :deep(ol) {
|
||||
margin: 8px 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
:deep(strong) {
|
||||
color: #2c3e50;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(em) {
|
||||
color: #6c757d;
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input-area {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
background: #f5f5f5;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
align-items: flex-end;
|
||||
z-index: 101;
|
||||
|
||||
textarea {
|
||||
flex: 1;
|
||||
padding: 10px 16px;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 4px;
|
||||
outline: none;
|
||||
transition: all 0.3s;
|
||||
background: #fff;
|
||||
resize: none;
|
||||
min-height: 42px;
|
||||
max-height: calc(24px * 6);
|
||||
line-height: 1.5;
|
||||
|
||||
&:focus {
|
||||
border-color: #07c160;
|
||||
box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 0 24px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
height: 42px;
|
||||
transition: all 0.3s;
|
||||
line-height: 42px;
|
||||
border: 1px solid #ddd;
|
||||
white-space: nowrap;
|
||||
&:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.new-chat-btn {
|
||||
padding: 0 16px;
|
||||
background: #fff;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
|
||||
&:hover {
|
||||
background: #e8e8e8;
|
||||
border-color: #ccc;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
background: #f5f5f5;
|
||||
border-color: #ddd;
|
||||
color: #999;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.new-chat-icon {
|
||||
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
.send-btn {
|
||||
color: white;
|
||||
background: #07c160;
|
||||
&:hover {
|
||||
background: #06ae56;
|
||||
}
|
||||
}
|
||||
/* 统一的滚动条样式 */
|
||||
.chat-messages,
|
||||
.summary-content,
|
||||
.evaluation-content {
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 4px;
|
||||
border: 2px solid transparent;
|
||||
background-clip: padding-box;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 添加媒体查询以适应不同屏幕 */
|
||||
@media screen and (max-width: 768px) {
|
||||
.message-wrapper {
|
||||
max-width: 90%;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
.message-wrapper {
|
||||
max-width: 95%;
|
||||
}
|
||||
}
|
||||
|
||||
.user {
|
||||
.message-text {
|
||||
background-color: #95ec69;
|
||||
border-color: rgba(0, 0, 0, 0.08);
|
||||
|
||||
&::before {
|
||||
border-right-color: #95ec69;
|
||||
right: 100%;
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.assistant {
|
||||
.message-text {
|
||||
background-color: #ffffff;
|
||||
border-color: rgba(0, 0, 0, 0.08);
|
||||
|
||||
&::before {
|
||||
border-right-color: #ffffff;
|
||||
right: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.typing {
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.typing-indicator {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px 8px;
|
||||
height: 20px;
|
||||
|
||||
span {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
background: #999;
|
||||
border-radius: 50%;
|
||||
animation: bounce 1.4s infinite ease-in-out;
|
||||
|
||||
&:nth-child(1) { animation-delay: -0.32s; }
|
||||
&:nth-child(2) { animation-delay: -0.16s; }
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes bounce {
|
||||
0%, 80%, 100% { transform: scale(0); }
|
||||
40% { transform: scale(1); }
|
||||
}
|
||||
|
||||
.evaluation-toggle {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.evaluation-text {
|
||||
position: relative;
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.summary-panel {
|
||||
position: absolute;
|
||||
bottom: 80px;
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
max-height: 300px;
|
||||
|
||||
&.summary-panel-collapsed {
|
||||
max-height: 42px; // 标题栏的高度
|
||||
|
||||
.summary-content {
|
||||
opacity: 0;
|
||||
transform: translateY(-20px);
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.summary-header {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.summary-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 16px;
|
||||
background: #f8f9fa;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
transition: all 0.3s ease;
|
||||
flex-shrink: 0;
|
||||
height: 42px;
|
||||
|
||||
.summary-title {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.summary-toggle-icon {
|
||||
color: #6c757d;
|
||||
font-size: 14px;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.summary-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 250px;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
background: #fff;
|
||||
color: #495057;
|
||||
line-height: 1.6;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s ease;
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
visibility: visible;
|
||||
|
||||
:deep(p) {
|
||||
margin: 0 0 12px 0;
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(ul), :deep(ol) {
|
||||
margin: 8px 0;
|
||||
padding-left: 20px;
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(strong) {
|
||||
color: #2c3e50;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(em) {
|
||||
color: #6c757d;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
:deep(code) {
|
||||
background: #f8f9fa;
|
||||
padding: 2px 4px;
|
||||
border-radius: 4px;
|
||||
color: #e83e8c;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,297 @@
|
|||
<template>
|
||||
<div class="mode-selector">
|
||||
<div class="mode-header">
|
||||
<h3 class="mode-title">对话场景</h3>
|
||||
<el-dropdown trigger="hover" @command="handleHistorySelect">
|
||||
<el-button class="history-btn" :icon="Document" text bg>
|
||||
历史会话
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<template v-if="currentModeHistory.length">
|
||||
<el-dropdown-item
|
||||
v-for="chat in currentModeHistory"
|
||||
:key="chat.conversationId"
|
||||
:command="chat.conversationId"
|
||||
class="history-item"
|
||||
>
|
||||
<div class="history-content">
|
||||
<span class="history-title">{{ formatChatTitle(chat) }}</span>
|
||||
<el-button
|
||||
class="delete-btn"
|
||||
:icon="Delete"
|
||||
link
|
||||
@click.stop="handleDelete(chat.conversationId)"
|
||||
/>
|
||||
</div>
|
||||
</el-dropdown-item>
|
||||
</template>
|
||||
<el-dropdown-item v-else disabled>暂无历史会话</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
<div class="mode-list">
|
||||
<div
|
||||
v-for="mode in chatModes"
|
||||
:key="mode.id"
|
||||
:class="['mode-item', { active: chatStore.currentMode === mode.id }]"
|
||||
@click="selectMode(mode.id)"
|
||||
>
|
||||
<i :class="mode.icon"></i>
|
||||
<span>{{ mode.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useChatStore } from '@/store/chat'
|
||||
import { computed, ref } from 'vue'
|
||||
import { Document, Delete } from '@element-plus/icons-vue'
|
||||
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElButton, ElMessageBox } from 'element-plus'
|
||||
|
||||
const chatStore = useChatStore()
|
||||
|
||||
const chatModes = computed(() => {
|
||||
return Object.keys(chatStore.chatModes).map(key => ({
|
||||
id: key,
|
||||
name: chatStore.chatModes[key].name,
|
||||
icon: chatStore.chatModes[key].icon
|
||||
}))
|
||||
})
|
||||
|
||||
// 获取当前模式下的历史会话
|
||||
const currentModeHistory = computed(() => {
|
||||
return chatStore.conversations.filter(chat => chat.mode === chatStore.currentMode)
|
||||
})
|
||||
|
||||
// 格式化会话标题
|
||||
const formatChatTitle = (chat) => {
|
||||
// 使用第一条消息作为标题,如果没有则使用默认标题
|
||||
if (chat.messages && chat.messages.length > 0) {
|
||||
const firstMessage = chat.messages[0].question
|
||||
return firstMessage.length > 20 ? firstMessage.substring(0, 20) + '...' : firstMessage
|
||||
}
|
||||
return `会话 ${chat.conversationId.substring(0, 8)}`
|
||||
}
|
||||
|
||||
const selectMode = (modeId) => {
|
||||
chatStore.setCurrentMode(modeId)
|
||||
}
|
||||
|
||||
const handleHistorySelect = (conversationId) => {
|
||||
chatStore.switchConversation(conversationId)
|
||||
}
|
||||
|
||||
const handleDelete = async (conversationId) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'确定要删除这个会话吗?删除后无法恢复。',
|
||||
'删除确认',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}
|
||||
)
|
||||
chatStore.deleteConversation(conversationId)
|
||||
} catch {
|
||||
// 用户取消删除
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
$primary-color: #4CAF50;
|
||||
$text-color: #333;
|
||||
$text-color-dark: #fff;
|
||||
$background-color: #ffffff;
|
||||
$background-color-dark: #1e1e1e;
|
||||
$border-color: #e0e0e0;
|
||||
$border-color-dark: #333;
|
||||
$hover-color: #f5f5f5;
|
||||
$hover-color-dark: #2d2d2d;
|
||||
|
||||
.mode-selector {
|
||||
width: 240px;
|
||||
min-width: 240px;
|
||||
background: $background-color;
|
||||
border-right: 1px solid $border-color;
|
||||
height: 100%;
|
||||
padding: 20px 0;
|
||||
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
|
||||
|
||||
.mode-header {
|
||||
padding: 0 20px;
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
|
||||
.mode-title {
|
||||
color: $text-color;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.history-btn {
|
||||
font-size: 14px;
|
||||
height: 32px;
|
||||
padding: 4px 12px;
|
||||
color: $text-color;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
color: $primary-color;
|
||||
background: rgba($primary-color, 0.1);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
:deep(.el-icon) {
|
||||
font-size: 16px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mode-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.mode-item {
|
||||
padding: 15px 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
color: $text-color;
|
||||
|
||||
&:hover {
|
||||
background: $hover-color;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: $primary-color;
|
||||
color: white;
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 18px;
|
||||
width: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-dropdown-menu__item) {
|
||||
font-size: 13px;
|
||||
padding: 8px 16px;
|
||||
line-height: 1.4;
|
||||
max-width: 300px;
|
||||
overflow-x: hidden;
|
||||
|
||||
&:hover .delete-btn {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-dropdown-menu) {
|
||||
min-width: 200px;
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.history-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.history-title {
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-right: 24px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
position: absolute;
|
||||
right: -8px;
|
||||
opacity: 0;
|
||||
transform: translateX(10px);
|
||||
transition: all 0.3s ease;
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
padding: 0;
|
||||
color: #f56c6c;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
color: #f56c6c;
|
||||
background-color: rgba(245, 108, 108, 0.1);
|
||||
}
|
||||
|
||||
:deep(.el-icon) {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.mode-selector {
|
||||
background: $background-color-dark;
|
||||
border-right-color: $border-color-dark;
|
||||
|
||||
.mode-title {
|
||||
color: $text-color-dark;
|
||||
}
|
||||
|
||||
.mode-item {
|
||||
color: $text-color-dark;
|
||||
|
||||
&:hover {
|
||||
background: $hover-color-dark;
|
||||
}
|
||||
}
|
||||
|
||||
.history-btn {
|
||||
color: $text-color-dark;
|
||||
|
||||
&:hover {
|
||||
color: $primary-color;
|
||||
background: rgba($primary-color, 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
&:hover {
|
||||
background-color: rgba(245, 108, 108, 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,58 @@
|
|||
<template>
|
||||
<div class="chat">
|
||||
<div class="chat-container">
|
||||
<ChatModeSelector @mode-changed="handleModeChange" />
|
||||
<div class="chat-wrapper">
|
||||
<keep-alive>
|
||||
<ChatInterface :key="currentMode.id" :chatMode="currentMode" />
|
||||
</keep-alive>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import ChatInterface from './ChatInterface.vue'
|
||||
import ChatModeSelector from './ChatModeSelector.vue'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const currentMode = ref({
|
||||
id: 'training',
|
||||
token: 'app-88ae2GN49aUyNO6qGg7tbTfX'
|
||||
})
|
||||
|
||||
const handleModeChange = (mode) => {
|
||||
currentMode.value = mode
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
|
||||
}
|
||||
|
||||
.chat {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chat-wrapper {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background-color: #f5f5f5;
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,41 @@
|
|||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
// import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(({ command, mode }) => {
|
||||
const env = loadEnv(mode, process.cwd())
|
||||
console.log('env', env)
|
||||
// 将环境变量转换为 process.env 格式
|
||||
const processEnv = {}
|
||||
Object.keys(env).forEach(key => {
|
||||
processEnv[key] = JSON.stringify(env[key])
|
||||
})
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
vue(),
|
||||
// vueDevTools(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: env.VITE_APP_BASE_API,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||
secure: false
|
||||
}
|
||||
}
|
||||
},
|
||||
define: {
|
||||
'process.env': processEnv
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue