8
8
class =" h-full"
9
9
style =" padding : 24px 0 "
10
10
>
11
- <InfiniteScroll
12
- :size =" recordList.length"
13
- :total =" paginationConfig.total"
14
- :page_size =" paginationConfig.page_size"
15
- v-model:current_page =" paginationConfig.current_page"
16
- @load =" getChatRecord"
17
- :loading =" loading"
11
+ <AiChat
12
+ ref =" AiChatRef"
13
+ :application-details =" application"
14
+ type =" log"
15
+ :record =" recordList"
16
+ @scroll =" handleScroll"
18
17
>
19
- <AiChat :application-details =" application" :record =" recordList" type =" log" ></AiChat >
20
- </InfiniteScroll >
18
+ </AiChat >
21
19
</div >
22
20
<template #footer >
23
21
<div >
29
27
</template >
30
28
31
29
<script setup lang="ts">
32
- import { ref , reactive , watch } from ' vue'
30
+ import { ref , reactive , watch , nextTick } from ' vue'
33
31
import { useRoute } from ' vue-router'
34
- import logApi from ' @/api/log'
35
- import { type chatType } from ' @/api/type/application'
36
- import { type ApplicationFormType } from ' @/api/type/application'
32
+ import { type ApplicationFormType , type chatType } from ' @/api/type/application'
33
+ import useStore from ' @/stores'
34
+ const AiChatRef = ref ()
35
+ const { log } = useStore ()
37
36
const props = withDefaults (
38
37
defineProps <{
39
38
/**
@@ -84,12 +83,21 @@ function closeHandle() {
84
83
}
85
84
86
85
function getChatRecord() {
87
- if (props .chatId && visible .value ) {
88
- logApi .getChatRecordLog (id as string , props .chatId , paginationConfig , loading ).then ((res ) => {
86
+ return log
87
+ .asyncChatRecordLog (id as string , props .chatId , paginationConfig , loading )
88
+ .then ((res : any ) => {
89
89
paginationConfig .total = res .data .total
90
- recordList .value = [... recordList .value , ... res .data .records ]
90
+ const list = res .data .records
91
+ recordList .value = [... list , ... recordList .value ].sort ((a , b ) =>
92
+ a .create_time .localeCompare (b .create_time )
93
+ )
94
+ if (paginationConfig .current_page === 1 ) {
95
+ nextTick (() => {
96
+ // 将滚动条滚动到最下面
97
+ AiChatRef .value .setScrollBottom ()
98
+ })
99
+ }
91
100
})
92
- }
93
101
}
94
102
95
103
watch (
@@ -98,7 +106,9 @@ watch(
98
106
recordList .value = []
99
107
paginationConfig .total = 0
100
108
paginationConfig .current_page = 1
101
- getChatRecord ()
109
+ if (props .chatId ) {
110
+ getChatRecord ()
111
+ }
102
112
}
103
113
)
104
114
@@ -110,8 +120,21 @@ watch(visible, (bool) => {
110
120
}
111
121
})
112
122
123
+ function handleScroll(event : any ) {
124
+ if (
125
+ props .chatId !== ' new' &&
126
+ event .scrollTop === 0 &&
127
+ paginationConfig .total > recordList .value .length
128
+ ) {
129
+ const history_height = event .dialogScrollbar .offsetHeight
130
+ paginationConfig .current_page += 1
131
+ getChatRecord ().then (() => {
132
+ event .scrollDiv .setScrollTop (event .dialogScrollbar .offsetHeight - history_height )
133
+ })
134
+ }
135
+ }
136
+
113
137
const open = () => {
114
- getChatRecord ()
115
138
visible .value = true
116
139
}
117
140
@@ -125,11 +148,13 @@ defineExpose({
125
148
overflow : hidden ;
126
149
text-overflow : ellipsis ;
127
150
}
151
+
128
152
.chat-record-drawer {
129
153
.el-drawer__body {
130
154
background : var (--app-layout-bg-color );
131
155
padding : 0 ;
132
156
}
157
+
133
158
:deep (.el-divider__text ) {
134
159
background : var (--app-layout-bg-color );
135
160
}
0 commit comments