2424 </el-aside >
2525 <el-container :loading =" loading" >
2626 <el-main class =" chat-record-list" >
27- <el-scrollbar ref =" chatListRef" >
27+ <div v-if =" computedMessages.length == 0" class =" welcome-content-block" >
28+ <div class =" welcome-content" >
29+ <div class =" logo" >SQLBot</div >
30+ <div >{{ t('qa.greeting') }}</div >
31+ <div class =" sub" >{{ t('qa.description') }}</div >
32+ <el-button size =" large" type =" primary" @click =" createNewChat" >
33+ <el-icon >
34+ <Plus />
35+ </el-icon >
36+ {{ t('qa.New Conversation') }}
37+ </el-button >
38+ </div >
39+ </div >
40+ <el-scrollbar v-if =" computedMessages.length > 0" ref =" chatListRef" >
2841 <template v-for =" (message , _index ) in computedMessages " :key =" _index " >
2942 <ChatRow
3043 v-model:datasource =" currentChat.datasource"
8396 </template >
8497 </el-scrollbar >
8598 </el-main >
86- <el-footer class =" chat-footer" >
99+ <el-footer v-if = " computedMessages.length > 0 " class =" chat-footer" >
87100 <div style =" height : 24px " >
88101 <template v-if =" currentChat .datasource && currentChat .datasource_name " >
89102 {{ t('ds.title') }}:{{ currentChat.datasource_name }}
115128 </div >
116129 </el-footer >
117130 </el-container >
131+
132+ <ChatCreator ref =" chatCreatorRef" @on-chat-created =" onChatCreated" />
118133 </el-container >
119134</template >
120135
@@ -127,6 +142,7 @@ import ChatRow from './ChatRow.vue'
127142import ChatAnswer from ' ./ChatAnswer.vue'
128143import MdComponent from ' ./component/MdComponent.vue'
129144import PredictChartBlock from ' ./component/PredictChartBlock.vue'
145+ import ChatCreator from ' ./ChatCreator.vue'
130146import { useI18n } from ' vue-i18n'
131147import { find } from ' lodash-es'
132148
@@ -135,6 +151,7 @@ const { t } = useI18n()
135151const inputMessage = ref (' ' )
136152
137153const chatListRef = ref ()
154+ const chatCreatorRef = ref ()
138155
139156function scrollToBottom() {
140157 nextTick (() => {
@@ -155,17 +172,18 @@ const isAnalysisTyping = ref<boolean>(false)
155172const isPredictTyping = ref <boolean >(false )
156173
157174const computedMessages = computed <Array <ChatMessage >>(() => {
158- const welcome : ChatMessage = {
175+ const firstMessage : ChatMessage = {
159176 role: ' assistant' ,
160177 create_time: currentChat .value ?.create_time ,
161178 content: currentChat .value ?.datasource ,
162179 isTyping: false ,
163180 isWelcome: true ,
164181 }
165- const messages: Array <ChatMessage > = [welcome ]
182+ const messages: Array <ChatMessage > = []
166183 if (currentChatId .value === undefined ) {
167184 return messages
168185 }
186+ messages .push (firstMessage )
169187 for (let i = 0 ; i < currentChat .value .records .length ; i ++ ) {
170188 const record = currentChat .value .records [i ]
171189 if (record .question !== undefined ) {
@@ -186,12 +204,17 @@ const computedMessages = computed<Array<ChatMessage>>(() => {
186204 return messages
187205})
188206
189- const createNewChat = () => {
207+ const goEmpty = () => {
190208 currentChat .value = new ChatInfo ()
191209 currentChatId .value = undefined
192210 inputMessage .value = ' '
193211}
194212
213+ const createNewChat = () => {
214+ goEmpty ()
215+ chatCreatorRef .value ?.showDs ()
216+ }
217+
195218function getChatList() {
196219 loading .value = true
197220 chatApi
@@ -229,9 +252,12 @@ function onChatDeleted(id: number) {
229252 for (let i = 0 ; i < chatList .value .length ; i ++ ) {
230253 if (chatList .value [i ].id === id ) {
231254 chatList .value .splice (i , 1 )
232- return
255+ break
233256 }
234257 }
258+ if (id === currentChatId .value ) {
259+ goEmpty ()
260+ }
235261}
236262
237263function onChatRenamed(chat : Chat ) {
@@ -245,6 +271,12 @@ function onChatRenamed(chat: Chat) {
245271 }
246272}
247273
274+ function onChatCreated(chat : ChatInfo ) {
275+ chatList .value .unshift (chat )
276+ currentChatId .value = chat .id
277+ currentChat .value = chat
278+ }
279+
248280onMounted (() => {
249281 getChatList ()
250282})
@@ -268,32 +300,9 @@ const sendMessage = async () => {
268300 currentChat .value .records .push (currentRecord )
269301 inputMessage .value = ' '
270302
271- let error = false
303+ let error: boolean = false
272304 if (currentChatId .value === undefined ) {
273- await chatApi
274- .startChat ({
275- question: currentRecord .question .trim (),
276- datasource: currentChat .value .datasource ,
277- })
278- .then ((res ) => {
279- const chat = chatApi .toChatInfo (res )
280- if (chat !== undefined ) {
281- chatList .value .unshift (chat )
282- currentChatId .value = chat .id
283- chat .records .push (currentRecord )
284- currentChat .value = chat
285- } else {
286- error = true
287- }
288- })
289- .catch ((e ) => {
290- isTyping .value = false
291- error = true
292- console .error (e )
293- })
294- .finally (() => {
295- loading .value = false
296- })
305+ error = true
297306 }
298307 if (error ) return
299308
@@ -683,4 +692,36 @@ const handleCtrlEnter = (e: KeyboardEvent) => {
683692 line-height : 1.7692307692 ;
684693 padding : 16px 22px ;
685694}
695+
696+ .welcome-content-block {
697+ height : 100% ;
698+ width : 100% ;
699+
700+ display : flex ;
701+ justify-content : center ;
702+ align-items : center ;
703+
704+ .welcome-content {
705+ padding : 12px ;
706+
707+ width : fit-content ;
708+ display : flex ;
709+ gap : 16px ;
710+ align-items : center ;
711+ flex-direction : column ;
712+
713+ .logo {
714+ line-height : 60px ;
715+ font-size : 3em ;
716+ font-weight : bold ;
717+ color : var (--el-color-primary );
718+ text-align : left ;
719+ }
720+
721+ .sub {
722+ color : grey ;
723+ font-size : 0.8em ;
724+ }
725+ }
726+ }
686727 </style >
0 commit comments