feat: 对话 吸底
This commit is contained in:
parent
1ecce3bc84
commit
50480616c5
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="ai-chat" :class="log ? 'chart-log' : ''">
|
<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 ref="dialogScrollbar" class="ai-chat__content p-24">
|
||||||
<div class="item-content mb-16">
|
<div class="item-content mb-16">
|
||||||
<div class="avatar">
|
<div class="avatar">
|
||||||
@ -127,7 +127,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<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 { useRoute } from 'vue-router'
|
||||||
import LogOperationButton from './LogOperationButton.vue'
|
import LogOperationButton from './LogOperationButton.vue'
|
||||||
import OperationButton from './OperationButton.vue'
|
import OperationButton from './OperationButton.vue'
|
||||||
@ -263,16 +263,21 @@ function chatMessage() {
|
|||||||
vote_status: '-1'
|
vote_status: '-1'
|
||||||
})
|
})
|
||||||
inputValue.value = ''
|
inputValue.value = ''
|
||||||
|
nextTick(() => {
|
||||||
|
scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER)
|
||||||
|
})
|
||||||
|
|
||||||
applicationApi.postChatMessage(chartOpenId.value, problem_text).then((response) => {
|
applicationApi.postChatMessage(chartOpenId.value, problem_text).then((response) => {
|
||||||
const row = chatList.value.find((item) => item.id === id)
|
const row = chatList.value.find((item) => item.id === id)
|
||||||
|
|
||||||
if (row) {
|
if (row) {
|
||||||
ChatManagement.addChatRecord(row, 50, loading)
|
ChatManagement.addChatRecord(row, 50, loading)
|
||||||
ChatManagement.write(id)
|
ChatManagement.write(id)
|
||||||
|
nextTick(() => {
|
||||||
|
scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER)
|
||||||
|
})
|
||||||
const reader = response.body.getReader()
|
const reader = response.body.getReader()
|
||||||
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||||
const write = ({ done, value }: { done: boolean; value: any }) => {
|
const write = ({ done, value }: { done: boolean; value: any }) => {
|
||||||
let scrollInterval
|
|
||||||
try {
|
try {
|
||||||
if (done) {
|
if (done) {
|
||||||
ChatManagement.close(id)
|
ChatManagement.close(id)
|
||||||
@ -290,12 +295,8 @@ function chatMessage() {
|
|||||||
const content = chunk?.content
|
const content = chunk?.content
|
||||||
if (content) {
|
if (content) {
|
||||||
ChatManagement.append(id, content)
|
ChatManagement.append(id, content)
|
||||||
scrollInterval = setInterval(() => {
|
|
||||||
handleScrollBottom()
|
|
||||||
}, 5000)
|
|
||||||
}
|
}
|
||||||
if (chunk.is_end) {
|
if (chunk.is_end) {
|
||||||
clearInterval(scrollInterval)
|
|
||||||
// 流处理成功 返回成功回调
|
// 流处理成功 返回成功回调
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
@ -327,18 +328,44 @@ function regenerationChart(item: chatType) {
|
|||||||
chatMessage()
|
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(() => {
|
const handleScroll = () => {
|
||||||
if (!props.log) {
|
if (!props.log && scrollDiv.value) {
|
||||||
handleScrollBottom()
|
// 内部高度小于外部高度 就需要出滚动条
|
||||||
|
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>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.ai-chat {
|
.ai-chat {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user