@@ -39,15 +39,21 @@ export const useChatStore = defineStore('chat-store', {
39
39
this . chat . unshift ( { uuid : r . uuid , data : [ ] } )
40
40
}
41
41
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 )
44
47
}
45
- this . active = uuid
46
- this . reloadRoute ( uuid )
47
48
callback && callback ( )
48
49
} ,
49
50
50
51
async syncChat ( h : Chat . History , callback : ( ) => void ) {
52
+ if ( ! h . uuid ) {
53
+ callback && callback ( )
54
+ return
55
+ }
56
+
51
57
const chatIndex = this . chat . findIndex ( item => item . uuid === h . uuid )
52
58
if ( chatIndex <= - 1 || this . chat [ chatIndex ] . data . length <= 0 ) {
53
59
const chatData = ( await fetchGetChatHistory ( h . uuid ) ) . data
@@ -61,8 +67,8 @@ export const useChatStore = defineStore('chat-store', {
61
67
this . recordState ( )
62
68
} ,
63
69
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 )
66
72
this . history . unshift ( history )
67
73
this . chat . unshift ( { uuid : history . uuid , data : chatData } )
68
74
this . active = history . uuid
@@ -80,13 +86,12 @@ export const useChatStore = defineStore('chat-store', {
80
86
} ,
81
87
82
88
async deleteHistory ( index : number ) {
83
- fetchDeleteChatRoom ( this . history [ index ] . uuid )
89
+ await fetchDeleteChatRoom ( this . history [ index ] . uuid )
84
90
this . history . splice ( index , 1 )
85
91
this . chat . splice ( index , 1 )
86
92
87
93
if ( this . history . length === 0 ) {
88
- this . active = null
89
- this . reloadRoute ( )
94
+ await this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false } )
90
95
return
91
96
}
92
97
0 commit comments