feat: 对话功能开发

This commit is contained in:
2026-04-12 13:05:52 +08:00
parent fad8c10e69
commit 7a5b6680f2
4 changed files with 18 additions and 11 deletions

View File

@@ -36,7 +36,10 @@
<div
v-for="(item, index) in historyStore.historyItems"
:key="index"
class="flex items-center w-[216px] h-[37px] justify-between rounded-[10px] pl-3 pr-3 mx-auto text-gray-500 hover:bg-gray-50 hover:text-gray-700 cursor-pointer transition-all duration-200"
:class="[
'flex items-center w-[216px] h-[37px] justify-between rounded-[10px] pl-3 pr-3 mx-auto cursor-pointer transition-all duration-200',
route.params.id === item.id ? 'bg-[#DEE0E4] text-gray-900' : 'text-gray-500 hover:bg-gray-50 hover:text-gray-700',
]"
@click="onHistoryClick(item)"
:title="item.name"
>
@@ -133,7 +136,7 @@ const statusLabel = computed(() => {
const menus = ref([
{ name: '新对话', index: '/', icon: 'plus' },
{ name: '知识空间', index: '/knowledge', icon: 'book' },
{ name: 'opencode对话', index: '/chat', icon: 'bot' },
// { name: 'opencode对话', index: '/chat', icon: 'bot' },
{ name: '发现设备', index: '/bonjour', icon: 'server' },
{ name: '测试页', index: '/test', icon: 'flask-conical' },
]);
@@ -168,8 +171,8 @@ async function onHistoryClick(item) {
}
// 跳转到对话页面
router.push({
path: '/chat',
query: { sessionId: item.id },
name: 'Chat',
params: { id: item.id },
});
}

View File

@@ -8,7 +8,7 @@ const routes = [
meta: { title: '首页' },
},
{
path: '/chat',
path: '/chat/:id?',
name: 'Chat',
component: () => import('@/views/chat/ChatView.vue'),
meta: { title: 'OpenCode 对话' },

View File

@@ -63,7 +63,7 @@ const localAssistantMessageIds = new Set();
let unsubscribeCallbacks = [];
// 从路由参数中获取 sessionId
const routeSessionId = computed(() => route.query.sessionId);
const routeSessionId = computed(() => route.params.id || route.query.sessionId);
// 加载历史消息
async function loadHistoryMessages(sessionId) {

View File

@@ -75,6 +75,7 @@ import { useRouter } from 'vue-router';
import { useAppStore } from '@/stores/app';
import { useHistoryStore } from '@/stores/history';
import { Document, Plus, Promotion } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
const router = useRouter();
const appStore = useAppStore();
@@ -84,6 +85,11 @@ const isCreating = ref(false);
// 处理发送消息
async function handleSend() {
// 检查 opencode 服务是否已启动
if (appStore.serviceStatus !== appStore.SERVICE_STATUS.RUNNING) {
ElMessage.warning('暂时没有运行的智能体');
return;
}
const text = inputText.value.trim();
if (!text || isCreating.value) return;
@@ -98,11 +104,9 @@ async function handleSend() {
// 跳转到对话页面,并将消息文本带入 query
router.push({
path: '/chat',
query: {
sessionId: session.id,
text: text,
},
name: 'Chat',
params: { id: session.id },
query: { text: text },
});
} catch (err) {
console.error('创建会话失败:', err);