From c807a787ddf99af466bca8f19f453067845a9f40 Mon Sep 17 00:00:00 2001 From: ulleo Date: Mon, 21 Jul 2025 11:28:08 +0800 Subject: [PATCH] fix: create chat from datasource card --- frontend/src/router/index.ts | 3 +++ frontend/src/views/chat/ChatCreator.vue | 20 ++++++++++++++------ frontend/src/views/chat/index.vue | 20 ++++++++++++++++++-- frontend/src/views/ds/Datasource.vue | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index e24b0bc9..80236fa1 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -36,6 +36,9 @@ const router = createRouter({ path: 'index', name: 'chat', component: chat, + props: (route) => { + return { startChatDsId: route.query.start_chat } + }, meta: { title: t('menu.Data Q&A'), icon: 'chat' }, }, ], diff --git a/frontend/src/views/chat/ChatCreator.vue b/frontend/src/views/chat/ChatCreator.vue index d9663c65..68fac999 100644 --- a/frontend/src/views/chat/ChatCreator.vue +++ b/frontend/src/views/chat/ChatCreator.vue @@ -3,7 +3,15 @@ import { chatApi, ChatInfo } from '@/api/chat.ts' import { onMounted, ref } from 'vue' import { datasourceApi } from '@/api/datasource.ts' import DatasourceItemCard from '../ds/DatasourceItemCard.vue' -import { useRoute } from 'vue-router' + +const props = withDefaults( + defineProps<{ + hidden?: boolean + }>(), + { + hidden: false, + } +) const dsList = ref>([]) @@ -14,7 +22,6 @@ function listDs() { dsList.value = res }) } -const route = useRoute() const dialogVisible = ref(false) @@ -67,20 +74,21 @@ function createChat(datasource: number) { } onMounted(() => { + if (props.hidden) { + return + } listDs() - const id = route.query.id as unknown as number - if (!id) return - createChat(id) }) defineExpose({ showDs, hideDs, + createChat, }) @@ -313,6 +314,11 @@ import logo from '@/assets/LOGO.svg' import icon_send_filled from '@/assets/svg/icon_send_filled.svg' import { useAssistantStore } from '@/stores/assistant' + +const props = defineProps<{ + startChatDsId?: number +}>() + const assistantStore = useAssistantStore() const isAssistant = computed(() => assistantStore.getAssistant) @@ -367,7 +373,6 @@ const computedMessages = computed>(() => { }) } - console.log(messages) return messages }) @@ -390,7 +395,6 @@ const createNewChat = async () => { } return } - console.log(chatCreatorRef.value) chatCreatorRef.value?.showDs() } @@ -745,6 +749,18 @@ defineExpose({ getCurrentChatId, createNewChat, }) + +const hiddenChatCreatorRef = ref() + +onMounted(() => { + if (props.startChatDsId) { + const _id = props.startChatDsId + nextTick(() => { + hiddenChatCreatorRef.value?.createChat(_id) + }) + // todo remove 'start_chat' in url + } +})