【解决todo】AI chat 增加回到底部

This commit is contained in:
cherishsince 2024-05-21 16:05:44 +08:00
parent 6a03b7637e
commit e3bc50e4fc

View File

@ -1,5 +1,5 @@
<template> <template>
<div ref="messageContainer" style="height: 100%;overflow-y: auto;"> <div ref="messageContainer" style="height: 100%;overflow-y: auto;position: relative;">
<div class="chat-list" v-for="(item, index) in list" :key="index" > <div class="chat-list" v-for="(item, index) in list" :key="index" >
<!-- 靠左 message --> <!-- 靠左 message -->
<!-- TODO 芋艿类型判断 --> <!-- TODO 芋艿类型判断 -->
@ -52,6 +52,10 @@
</div> </div>
</div> </div>
</div> </div>
<!-- 回到底部 -->
<div v-if="isScrolling" class="to-bottom" @click="handleGoBottom">
<el-button :icon="ArrowDownBold" circle />
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {formatDate} from "@/utils/formatTime"; import {formatDate} from "@/utils/formatTime";
@ -59,6 +63,7 @@ import MarkdownView from "@/components/MarkdownView/index.vue";
import {ChatMessageApi, ChatMessageVO} from "@/api/ai/chat/message"; import {ChatMessageApi, ChatMessageVO} from "@/api/ai/chat/message";
import {useClipboard} from "@vueuse/core"; import {useClipboard} from "@vueuse/core";
import {PropType} from "vue"; import {PropType} from "vue";
import {ArrowDownBold} from "@element-plus/icons-vue";
const {copy} = useClipboard() // copy const {copy} = useClipboard() // copy
// () // ()
@ -73,7 +78,6 @@ const props = defineProps({
} }
}) })
// ============ ============== // ============ ==============
const scrollToBottom = async (isIgnore?: boolean) =>{ const scrollToBottom = async (isIgnore?: boolean) =>{
@ -125,6 +129,22 @@ const onDelete = async (id) => {
emits('onDeleteSuccess') emits('onDeleteSuccess')
} }
/**
* 回到底部
*/
const handleGoBottom = async () => {
const scrollContainer = messageContainer.value
scrollContainer.scrollTop = scrollContainer.scrollHeight
}
/**
* 回到顶部
*/
const handlerGoTop = async () => {
const scrollContainer = messageContainer.value
scrollContainer.scrollTop = 0
}
// list // list
const { list, conversationId } = toRefs(props) const { list, conversationId } = toRefs(props)
watch(list, async (newValue, oldValue) => { watch(list, async (newValue, oldValue) => {
@ -132,11 +152,12 @@ watch(list, async (newValue, oldValue) => {
}) })
// parent // parent
defineExpose({scrollToBottom}) defineExpose({scrollToBottom, handlerGoTop})
// // emits
const emits = defineEmits(['onDeleteSuccess']) const emits = defineEmits(['onDeleteSuccess'])
//
// onMounted
onMounted(async () => { onMounted(async () => {
messageContainer.value.addEventListener('scroll', handleScroll) messageContainer.value.addEventListener('scroll', handleScroll)
}) })
@ -257,4 +278,12 @@ onMounted(async () => {
background-color: #f6f6f6; background-color: #f6f6f6;
} }
} }
//
.to-bottom {
position: absolute;
z-index: 1000;
bottom: 0;
right: 50%;
}
</style> </style>