88 class =" h-full"
99 style =" padding : 24px 0 "
1010 >
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"
1817 >
19- <AiChat :application-details =" application" :record =" recordList" type =" log" ></AiChat >
20- </InfiniteScroll >
18+ </AiChat >
2119 </div >
2220 <template #footer >
2321 <div >
2927</template >
3028
3129<script setup lang="ts">
32- import { ref , reactive , watch } from ' vue'
30+ import { ref , reactive , watch , nextTick } from ' vue'
3331import { 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 ()
3736const props = withDefaults (
3837 defineProps <{
3938 /**
@@ -84,12 +83,21 @@ function closeHandle() {
8483}
8584
8685function 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 ) => {
8989 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+ }
91100 })
92- }
93101}
94102
95103watch (
@@ -98,7 +106,9 @@ watch(
98106 recordList .value = []
99107 paginationConfig .total = 0
100108 paginationConfig .current_page = 1
101- getChatRecord ()
109+ if (props .chatId ) {
110+ getChatRecord ()
111+ }
102112 }
103113)
104114
@@ -110,8 +120,21 @@ watch(visible, (bool) => {
110120 }
111121})
112122
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+
113137const open = () => {
114- getChatRecord ()
115138 visible .value = true
116139}
117140
@@ -125,11 +148,13 @@ defineExpose({
125148 overflow : hidden ;
126149 text-overflow : ellipsis ;
127150}
151+
128152.chat-record-drawer {
129153 .el-drawer__body {
130154 background : var (--app-layout-bg-color );
131155 padding : 0 ;
132156 }
157+
133158 :deep (.el-divider__text ) {
134159 background : var (--app-layout-bg-color );
135160 }
0 commit comments