@@ -39,15 +39,21 @@ export const useChatStore = defineStore('chat-store', {
3939 this . chat . unshift ( { uuid : r . uuid , data : [ ] } )
4040 }
4141 if ( uuid == null ) {
42- uuid = Date . now ( )
43- this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false } )
42+ await this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false } )
43+ }
44+ else {
45+ this . active = uuid
46+ this . reloadRoute ( uuid )
4447 }
45- this . active = uuid
46- this . reloadRoute ( uuid )
4748 callback && callback ( )
4849 } ,
4950
5051 async syncChat ( h : Chat . History , callback : ( ) => void ) {
52+ if ( ! h . uuid ) {
53+ callback && callback ( )
54+ return
55+ }
56+
5157 const chatIndex = this . chat . findIndex ( item => item . uuid === h . uuid )
5258 if ( chatIndex <= - 1 || this . chat [ chatIndex ] . data . length <= 0 ) {
5359 const chatData = ( await fetchGetChatHistory ( h . uuid ) ) . data
@@ -61,8 +67,8 @@ export const useChatStore = defineStore('chat-store', {
6167 this . recordState ( )
6268 } ,
6369
64- addHistory ( history : Chat . History , chatData : Chat . Chat [ ] = [ ] ) {
65- fetchCreateChatRoom ( history . title , history . uuid )
70+ async addHistory ( history : Chat . History , chatData : Chat . Chat [ ] = [ ] ) {
71+ await fetchCreateChatRoom ( history . title , history . uuid )
6672 this . history . unshift ( history )
6773 this . chat . unshift ( { uuid : history . uuid , data : chatData } )
6874 this . active = history . uuid
@@ -80,13 +86,12 @@ export const useChatStore = defineStore('chat-store', {
8086 } ,
8187
8288 async deleteHistory ( index : number ) {
83- fetchDeleteChatRoom ( this . history [ index ] . uuid )
89+ await fetchDeleteChatRoom ( this . history [ index ] . uuid )
8490 this . history . splice ( index , 1 )
8591 this . chat . splice ( index , 1 )
8692
8793 if ( this . history . length === 0 ) {
88- this . active = null
89- this . reloadRoute ( )
94+ await this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false } )
9095 return
9196 }
9297
0 commit comments