feat: 对话功能开发

This commit is contained in:
2026-04-12 12:58:13 +08:00
parent 6ca081afa8
commit fad8c10e69
2 changed files with 24 additions and 17 deletions

View File

@@ -44,7 +44,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useRoute, useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { ChatDotRound, ArrowRight, ArrowDown } from '@element-plus/icons-vue';
import { useAppStore } from '@/stores/app.js';
@@ -52,6 +52,7 @@ import { sseManager } from '@/http/sse.js';
import axios from 'axios';
const route = useRoute();
const router = useRouter();
const appStore = useAppStore();
const isSending = ref(false);
const inputText = ref('');
@@ -144,10 +145,25 @@ async function loadHistoryMessages(sessionId) {
// 监听路由参数变化,加载对应会话
watch(
routeSessionId,
(newSessionId) => {
async (newSessionId) => {
if (newSessionId) {
currentSessionId.value = newSessionId;
loadHistoryMessages(newSessionId);
// 等待历史消息加载完毕,避免在 send 时 messages 被清空
await loadHistoryMessages(newSessionId);
// 处理从首页带过来的初始消息
const text = route.query.text;
if (text) {
inputText.value = text;
// 清除 query 中的 text防止刷新页面时重复发送
const query = { ...route.query };
delete query.text;
router.replace({ query });
// 触发发送逻辑
send();
}
// 确保 SSE 连接已建立
if (!appStore.sseConnected) {
appStore.initSSE();