From 6d5427f4103fbb079ee18674144f116374f95f50 Mon Sep 17 00:00:00 2001 From: DebugIsFalse <511418503@qq.com> Date: Thu, 23 May 2024 11:30:59 +0800 Subject: [PATCH] scroll --- pages/search/[id].vue | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 420d3b6..662beea 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -41,13 +41,13 @@ const route = useRoute() const { fetchRequest } = useFetchRequest() const editIndex = ref(0) const { y } = useWindowScroll({ behavior: 'smooth' }) - -let repoData = await fetchRequest('/v1/chat/repository', { +const { directions } = useScroll(window) +let repoData = await fetchRequest('/v1/chat/repository22', { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } -}) -repoData = repoData.data.map(item => { +}).catch(()=> {}) +repoData = repoData && repoData.data.map(item => { return { label: item.name, url: item.path, @@ -73,14 +73,12 @@ function handleUpdateQuery(query) { } // 是否停止自动滚动到底部 const isAutoToBottom = ref(true) -const handleScroll = (event, params) => { - // 在asking操作的时候生效 - if (!asking.value || !isAutoToBottom.value) return - const top = window.scrollY; - if (top < y.value) { - isAutoToBottom.value = false +watch(() => { + console.log(`directions.top:`, directions.top) + if (directions.top) { + isAutoToBottom.value = true } -} +}) const scrollToView = () => { if (!isAutoToBottom.value) return const $target = document.querySelector('#scrollElement') @@ -145,9 +143,9 @@ const handleFormFetchData = (fetchData) => { if (Object.keys(message).length === 0) return const { meta, choices } = message const index = editIndex.value - setTimeout(() => { + if (isAutoToBottom.value) { scrollToView() - }) + } // 处理报错信息 if (!meta) { handleStopGenerate() @@ -245,10 +243,6 @@ const generateFetchData = (query) => { } onMounted(() => { generateFetchData(state.query) - window.addEventListener('scroll', handleScroll) -}) -onBeforeUnmount(()=> { - window.removeEventListener('scroll', handleScroll) }) \ No newline at end of file -- GitLab