refactor(应用): 优化应用日志显示

This commit is contained in:
wxg0103 2024-11-18 17:57:40 +08:00 committed by wxg
parent 7d161cdd43
commit 7eb031e57d

View File

@ -8,16 +8,14 @@
class="h-full" class="h-full"
style="padding: 24px 0" style="padding: 24px 0"
> >
<InfiniteScroll <AiChat
:size="recordList.length" ref="AiChatRef"
:total="paginationConfig.total" :application-details="application"
:page_size="paginationConfig.page_size" type="log"
v-model:current_page="paginationConfig.current_page" :record="recordList"
@load="getChatRecord" @scroll="handleScroll"
:loading="loading"
> >
<AiChat :application-details="application" :record="recordList" type="log"></AiChat> </AiChat>
</InfiniteScroll>
</div> </div>
<template #footer> <template #footer>
<div> <div>
@ -29,11 +27,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch } from 'vue' import { ref, reactive, watch, nextTick } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import logApi from '@/api/log' import { type ApplicationFormType, type chatType } from '@/api/type/application'
import { type chatType } from '@/api/type/application' import useStore from '@/stores'
import { type ApplicationFormType } from '@/api/type/application' const AiChatRef = ref()
const { log } = useStore()
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
/** /**
@ -84,12 +83,21 @@ function closeHandle() {
} }
function getChatRecord() { function getChatRecord() {
if (props.chatId && visible.value) { return log
logApi.getChatRecordLog(id as string, props.chatId, paginationConfig, loading).then((res) => { .asyncChatRecordLog(id as string, props.chatId, paginationConfig, loading)
.then((res: any) => {
paginationConfig.total = res.data.total paginationConfig.total = res.data.total
recordList.value = [...recordList.value, ...res.data.records] const list = res.data.records
recordList.value = [...list, ...recordList.value].sort((a, b) =>
a.create_time.localeCompare(b.create_time)
)
if (paginationConfig.current_page === 1) {
nextTick(() => {
//
AiChatRef.value.setScrollBottom()
})
}
}) })
}
} }
watch( watch(
@ -98,7 +106,9 @@ watch(
recordList.value = [] recordList.value = []
paginationConfig.total = 0 paginationConfig.total = 0
paginationConfig.current_page = 1 paginationConfig.current_page = 1
getChatRecord() if (props.chatId) {
getChatRecord()
}
} }
) )
@ -110,8 +120,21 @@ watch(visible, (bool) => {
} }
}) })
function handleScroll(event: any) {
if (
props.chatId !== 'new' &&
event.scrollTop === 0 &&
paginationConfig.total > recordList.value.length
) {
const history_height = event.dialogScrollbar.offsetHeight
paginationConfig.current_page += 1
getChatRecord().then(() => {
event.scrollDiv.setScrollTop(event.dialogScrollbar.offsetHeight - history_height)
})
}
}
const open = () => { const open = () => {
getChatRecord()
visible.value = true visible.value = true
} }
@ -125,11 +148,13 @@ defineExpose({
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.chat-record-drawer { .chat-record-drawer {
.el-drawer__body { .el-drawer__body {
background: var(--app-layout-bg-color); background: var(--app-layout-bg-color);
padding: 0; padding: 0;
} }
:deep(.el-divider__text) { :deep(.el-divider__text) {
background: var(--app-layout-bg-color); background: var(--app-layout-bg-color);
} }