Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions ui/src/views/log/component/ChatRecordDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
class="h-full"
style="padding: 24px 0"
>
<InfiniteScroll
:size="recordList.length"
:total="paginationConfig.total"
:page_size="paginationConfig.page_size"
v-model:current_page="paginationConfig.current_page"
@load="getChatRecord"
:loading="loading"
<AiChat
ref="AiChatRef"
:application-details="application"
type="log"
:record="recordList"
@scroll="handleScroll"
>
<AiChat :application-details="application" :record="recordList" type="log"></AiChat>
</InfiniteScroll>
</AiChat>
</div>
<template #footer>
<div>
Expand All @@ -29,11 +27,12 @@
</template>

<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import { ref, reactive, watch, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import logApi from '@/api/log'
import { type chatType } from '@/api/type/application'
import { type ApplicationFormType } from '@/api/type/application'
import { type ApplicationFormType, type chatType } from '@/api/type/application'
import useStore from '@/stores'
const AiChatRef = ref()
const { log } = useStore()
const props = withDefaults(
defineProps<{
/**
Expand Down Expand Up @@ -84,12 +83,21 @@ function closeHandle() {
}

function getChatRecord() {
if (props.chatId && visible.value) {
logApi.getChatRecordLog(id as string, props.chatId, paginationConfig, loading).then((res) => {
return log
.asyncChatRecordLog(id as string, props.chatId, paginationConfig, loading)
.then((res: any) => {
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(
Expand All @@ -98,7 +106,9 @@ watch(
recordList.value = []
paginationConfig.total = 0
paginationConfig.current_page = 1
getChatRecord()
if (props.chatId) {
getChatRecord()
}
}
)

Expand All @@ -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 = () => {
getChatRecord()
visible.value = true
}

Expand All @@ -125,11 +148,13 @@ defineExpose({
overflow: hidden;
text-overflow: ellipsis;
}

.chat-record-drawer {
.el-drawer__body {
background: var(--app-layout-bg-color);
padding: 0;
}

:deep(.el-divider__text) {
background: var(--app-layout-bg-color);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个问题没有明确指出有什么问题或不规范的地方。它似乎是一个示例代码片段,可能是对Vue.js或其他技术栈的一个理解框架或者是用于文档目的的模板。如果这段代码是在编程环境中运行的话,需要仔细审查其中的逻辑并确保所有使用的技术都符合当前时间点的要求或者是最新的实践指导。

然而,在这个特定的时间戳下(2021年9月1日),该部分给出的问题是:在计算最大记录数时,未考虑到当已存在的条目超过给定的最大值时的情况。这可以通过简单地将 paginationConfig.total 加上超出数量来解决:

if (recordList.length >= paginationConfig.max_length) {
  paginationConfig.total += max_records_to_load;
} else {
   ...

此外,请注意在处理无限滚动插件时可能会引入一些额外的风险,因为它们可能无法保证正确性,并且可能导致性能问题。这些风险应该通过适当的监控和错误处理机制得到控制。

Expand Down
Loading