feat: 对话 吸底

This commit is contained in:
shaohuzhang1 2023-12-26 16:26:18 +08:00
parent 1ecce3bc84
commit 50480616c5

View File

@ -1,6 +1,6 @@
<template>
<div class="ai-chat" :class="log ? 'chart-log' : ''">
<el-scrollbar ref="scrollDiv">
<el-scrollbar ref="scrollDiv" @scroll="handleScrollTop">
<div ref="dialogScrollbar" class="ai-chat__content p-24">
<div class="item-content mb-16">
<div class="avatar">
@ -127,7 +127,7 @@
</div>
</template>
<script setup lang="ts">
import { ref, nextTick, onMounted, onUpdated, computed, watch } from 'vue'
import { ref, nextTick, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import LogOperationButton from './LogOperationButton.vue'
import OperationButton from './OperationButton.vue'
@ -263,16 +263,21 @@ function chatMessage() {
vote_status: '-1'
})
inputValue.value = ''
nextTick(() => {
scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER)
})
applicationApi.postChatMessage(chartOpenId.value, problem_text).then((response) => {
const row = chatList.value.find((item) => item.id === id)
if (row) {
ChatManagement.addChatRecord(row, 50, loading)
ChatManagement.write(id)
nextTick(() => {
scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER)
})
const reader = response.body.getReader()
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
const write = ({ done, value }: { done: boolean; value: any }) => {
let scrollInterval
try {
if (done) {
ChatManagement.close(id)
@ -290,12 +295,8 @@ function chatMessage() {
const content = chunk?.content
if (content) {
ChatManagement.append(id, content)
scrollInterval = setInterval(() => {
handleScrollBottom()
}, 5000)
}
if (chunk.is_end) {
clearInterval(scrollInterval)
//
return Promise.resolve()
}
@ -327,18 +328,44 @@ function regenerationChart(item: chatType) {
chatMessage()
}
//
function handleScrollBottom() {
nextTick(() => {
scrollDiv.value.setScrollTop(dialogScrollbar.value.scrollHeight)
})
/**
* 滚动条距离最上面的高度
*/
const scrollTop = ref(0)
const scorll = ref(true)
const handleScrollTop = ($event: any) => {
scrollTop.value = $event.scrollTop
if (
dialogScrollbar.value.scrollHeight - (scrollTop.value + scrollDiv.value.wrapRef.offsetHeight) <=
10
) {
scorll.value = true
} else {
scorll.value = false
}
}
onUpdated(() => {
if (!props.log) {
handleScrollBottom()
const handleScroll = () => {
if (!props.log && scrollDiv.value) {
//
if (scrollDiv.value.wrapRef.offsetHeight < dialogScrollbar.value.scrollHeight) {
//
if (scorll.value) {
scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER)
}
}
}
})
}
watch(
chatList,
() => {
handleScroll()
},
{ deep: true, immediate: true }
)
</script>
<style lang="scss" scoped>
.ai-chat {