diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 35b4ea1d1158c994a56ed0b0a8561c46551835f3..3dcfbb3d0bae4ab75d9b599d572813e3873f1c35 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -166,7 +166,19 @@ const state = reactive({ branch: repoItem.branch, gitPath: repoItem.url }) +// 是否停止自动滚动到底部 +const isAutoToBottom = ref(true); +let markedWindowScrollTop = 0; +const handleScroll = () => { + const top = window.scrollY; + if (top < markedWindowScrollTop) { + isAutoToBottom.value = false; + } else { + markedWindowScrollTop = top + } +} const scrollToView = () => { + if (!isAutoToBottom.value) return; const $target = document.querySelector('#scrollElement') const height = $target.clientHeight y.value = height; @@ -216,7 +228,7 @@ defineShortcuts({ enter: { usingInput: 'queryInput', handler: () => { - handleContinueAsk(continueQuestion) + handleContinueAsk(continueQuestion.value) } } }) @@ -226,6 +238,7 @@ const handleClearInput = () => { } const handleContinueAsk = (question) => { if (asking.value) return + isAutoToBottom.value = true asking.value = true editIndex.value = data.value.length createGenerateInitItem(question) @@ -366,6 +379,10 @@ const generateFetchData = (query) => { } onMounted(() => { generateFetchData(state.query) + window.addEventListener('scroll', handleScroll) +}) +onBeforeUnmount(()=> { + window.removeEventListener('scroll', handleScroll); }) \ No newline at end of file