fix: create chat from datasource card

This commit is contained in:
ulleo
2025-07-21 11:28:19 +08:00
parent d69002db30
commit c807a787dd
4 changed files with 36 additions and 9 deletions
+3
View File
@@ -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' },
},
],
+14 -6
View File
@@ -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<Array<any>>([])
@@ -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,
})
</script>
<template>
<div>
<div v-if="!hidden">
<el-drawer
ref="DatasourceListRef"
v-model="dialogVisible"
+18 -2
View File
@@ -285,6 +285,7 @@
</el-container>
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
<ChatCreator ref="hiddenChatCreatorRef" hidden @on-chat-created="onChatCreatedQuick" />
</el-container>
</template>
@@ -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<Array<ChatMessage>>(() => {
})
}
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
}
})
</script>
<style lang="less" scoped>
+1 -1
View File
@@ -97,7 +97,7 @@ const handleQuestion = (id: string) => {
router.push({
path: '/chat/index',
query: {
id,
start_chat: id,
},
})
}