mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
fix: create chat from datasource card
This commit is contained in:
@@ -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' },
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -97,7 +97,7 @@ const handleQuestion = (id: string) => {
|
||||
router.push({
|
||||
path: '/chat/index',
|
||||
query: {
|
||||
id,
|
||||
start_chat: id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user