Commit ad2150ea authored by tyyin lan's avatar tyyin lan

feat(首页): 消息列表滚动置底

parent 2bb401e2
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
name="viewport" name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/> />
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_4711453_j0r9s4e1cc9.css" /> <link rel="stylesheet" href="//at.alicdn.com/t/c/font_4711453_t9t0ftzqft.css" />
<link <link
rel="preload" rel="preload"
href="https://gsst-poe-sit.gz.bcebos.com/front/SourceHanSansCN-Medium.otf" href="https://gsst-poe-sit.gz.bcebos.com/front/SourceHanSansCN-Medium.otf"
......
...@@ -19,6 +19,7 @@ import type { SelectRenderLabel, SelectRenderTag } from 'naive-ui' ...@@ -19,6 +19,7 @@ import type { SelectRenderLabel, SelectRenderTag } from 'naive-ui'
interface Props { interface Props {
currentSessionId: string currentSessionId: string
messageListLength: number messageListLength: number
isNotShowBackBottomBtn: boolean | undefined
} }
const props = defineProps<Props>() const props = defineProps<Props>()
...@@ -87,7 +88,7 @@ const messageListScrollToBottomThrottle = throttle( ...@@ -87,7 +88,7 @@ const messageListScrollToBottomThrottle = throttle(
() => { () => {
emit('messageListScrollToBottom') emit('messageListScrollToBottom')
}, },
500, 100,
{ leading: true, trailing: true }, { leading: true, trailing: true },
) )
...@@ -203,7 +204,7 @@ function questionSubmit() { ...@@ -203,7 +204,7 @@ function questionSubmit() {
reasoningContent: reasoningContent, reasoningContent: reasoningContent,
}) })
messageListScrollToBottomThrottle() props.isNotShowBackBottomBtn && messageListScrollToBottomThrottle()
} }
// 回复消息 // 回复消息
...@@ -214,7 +215,7 @@ function questionSubmit() { ...@@ -214,7 +215,7 @@ function questionSubmit() {
content: messageContent, content: messageContent,
}) })
messageListScrollToBottomThrottle() props.isNotShowBackBottomBtn && messageListScrollToBottomThrottle()
} }
// 插件 // 插件
...@@ -223,7 +224,7 @@ function questionSubmit() { ...@@ -223,7 +224,7 @@ function questionSubmit() {
pluginName: data.function.name, pluginName: data.function.name,
}) })
messageListScrollToBottomThrottle() props.isNotShowBackBottomBtn && messageListScrollToBottomThrottle()
} }
}, },
onend: () => { onend: () => {
...@@ -232,8 +233,8 @@ function questionSubmit() { ...@@ -232,8 +233,8 @@ function questionSubmit() {
isAnswerLoading: false, isAnswerLoading: false,
}) })
messageListScrollToBottomThrottle() props.isNotShowBackBottomBtn && messageListScrollToBottomThrottle()
}, 500) }, 100)
}, },
onclose: () => { onclose: () => {
isAgentResponding.value = false isAgentResponding.value = false
......
...@@ -4,6 +4,8 @@ import type { MessageItemInterface } from '../types' ...@@ -4,6 +4,8 @@ import type { MessageItemInterface } from '../types'
import { ref, useTemplateRef } from 'vue' import { ref, useTemplateRef } from 'vue'
import { ScrollbarInst } from 'naive-ui' import { ScrollbarInst } from 'naive-ui'
import EditorDrawer from '@/components/editor-drawer/editor-drawer.vue' import EditorDrawer from '@/components/editor-drawer/editor-drawer.vue'
import { useElementVisibility } from '@vueuse/core'
import { throttle } from 'lodash-es'
interface Props { interface Props {
messageList: Map<string, MessageItemInterface> messageList: Map<string, MessageItemInterface>
...@@ -11,11 +13,10 @@ interface Props { ...@@ -11,11 +13,10 @@ interface Props {
defineProps<Props>() defineProps<Props>()
defineExpose({
scrollToBottom,
})
const scrollbarRef = useTemplateRef<ScrollbarInst | null>('scrollbarRef') const scrollbarRef = useTemplateRef<ScrollbarInst | null>('scrollbarRef')
const backBottomBtnFlagRef = useTemplateRef<HTMLDivElement | null>('backBottomBtnFlagRef')
const isNotShowBackBottomBtn = useElementVisibility(backBottomBtnFlagRef)
const isShowEditorDrawer = ref(false) const isShowEditorDrawer = ref(false)
const contentEdit = ref('') const contentEdit = ref('')
...@@ -31,21 +32,61 @@ function onContentedit(content: string) { ...@@ -31,21 +32,61 @@ function onContentedit(content: string) {
isShowEditorDrawer.value = true isShowEditorDrawer.value = true
} }
const handleBackBottom = throttle(() => {
scrollToBottom()
}, 500)
defineExpose({
scrollToBottom,
isNotShowBackBottomBtn,
})
</script> </script>
<template> <template>
<div class="flex-1 overflow-hidden overflow-y-auto py-[20px]"> <div class="relative flex-1 overflow-hidden overflow-y-auto py-[20px]">
<n-scrollbar ref="scrollbarRef"> <n-scrollbar ref="scrollbarRef" content-class="content-class">
<div class="mx-auto w-[750px] pr-[10px]"> <div class="relative mx-auto w-[750px] pr-[10px]">
<MessageItem <MessageItem
v-for="[key, messageItem] in messageList" v-for="[key, messageItem] in messageList"
:key="key" :key="key"
:message-item="messageItem" :message-item="messageItem"
@contentedit="onContentedit" @contentedit="onContentedit"
/> />
<div ref="backBottomBtnFlagRef" class="-z-1 absolute bottom-0 h-[40px] w-full"></div>
</div> </div>
</n-scrollbar> </n-scrollbar>
<Transition name="back-bottom-btn" mode="out-in">
<div
v-show="!isNotShowBackBottomBtn"
class="absolute bottom-[30px] left-1/2 w-[750px] text-end"
style="translate: calc(-50% + 30px)"
>
<button
class="flex-center flex-center inline-flex h-[26px] w-[26px] rounded-full bg-[#ECEFFF]"
@click="handleBackBottom"
>
<i class="iconfont icon-huidaodibu text-[12px]" />
</button>
</div>
</Transition>
<EditorDrawer v-model:is-show-editor-drawer="isShowEditorDrawer" v-model:content-edit="contentEdit" /> <EditorDrawer v-model:is-show-editor-drawer="isShowEditorDrawer" v-model:content-edit="contentEdit" />
</div> </div>
</template> </template>
<style lang="scss" scoped>
.back-bottom-btn-enter-active,
.back-bottom-btn-leave-active {
transition-timing-function: ease-in-out;
transition-duration: 0.2s;
transition-property: opacity;
}
.back-bottom-btn-enter-from,
.back-bottom-btn-leave-to {
opacity: 0;
}
</style>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, useTemplateRef, watch } from 'vue' import { ref, useTemplateRef, watch } from 'vue'
import AgentAbout from './components/agent-about.vue' import AgentAbout from './components/agent-about.vue'
import FooterOperation from './components/footer-operation.vue' import FooterOperation from './components/footer-operation.vue'
import HistoryMenuSidebar from './components/history-menu-sidebar.vue' import HistoryMenuSidebar from './components/history-menu-sidebar.vue'
...@@ -92,12 +92,6 @@ watch( ...@@ -92,12 +92,6 @@ watch(
createSessionId() createSessionId()
})() })()
onMounted(() => {
setTimeout(() => {
messageListScrollToBottom()
}, 700)
})
function createSessionId() { function createSessionId() {
fetchCreateSessionId<string>().then((res) => { fetchCreateSessionId<string>().then((res) => {
currentSessionId.value = res.data currentSessionId.value = res.data
...@@ -192,10 +186,6 @@ function onGetMessageRecordList(recordId: string) { ...@@ -192,10 +186,6 @@ function onGetMessageRecordList(recordId: string) {
}) })
messageList.value = new Map(messageListDraft as any) messageList.value = new Map(messageListDraft as any)
setTimeout(() => {
messageListScrollToBottom()
}, 500)
} }
}) })
.catch(() => { .catch(() => {
...@@ -234,6 +224,7 @@ function onClearSessionReferenceFile() { ...@@ -234,6 +224,7 @@ function onClearSessionReferenceFile() {
v-model:current-fetch-event-source-controller="currentFetchEventSourceController" v-model:current-fetch-event-source-controller="currentFetchEventSourceController"
:current-session-id="currentSessionId" :current-session-id="currentSessionId"
:message-list-length="messageList.size" :message-list-length="messageList.size"
:is-not-show-back-bottom-btn="messageListRef?.isNotShowBackBottomBtn"
@message-list-scroll-to-bottom="messageListScrollToBottom" @message-list-scroll-to-bottom="messageListScrollToBottom"
@add-message-item="onAddMessageItem" @add-message-item="onAddMessageItem"
@update-specify-message-item="onUpdateSpecifyMessageItem" @update-specify-message-item="onUpdateSpecifyMessageItem"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment