diff --git a/composables/useFetchRequest.js b/composables/useFetchRequest.js index 6903e1ad91dae8f0e1fa44b9560e84d03693ef82..7653a6516bd8b84ba75254f2ce05042e8cd391c0 100644 --- a/composables/useFetchRequest.js +++ b/composables/useFetchRequest.js @@ -9,7 +9,13 @@ const useFetchRequest = (baseUrl) => { fetchConfig = fetchConfig || {} fetchConfig.method = (fetchConfig.method || 'get').toLocaleUpperCase() fetchConfig = Object.assign(config, fetchConfig) - return $fetch(url, fetchConfig) + return new Promise((resolve, reject) => { + $fetch(url, fetchConfig).then((result) => { + resolve(result) + }).catch(() => { + resolve(null) + }) + }) } return { fetchRequest diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 3e2d9e97dd99b999f9889fde66e97eaab02af4c7..06217ce5046e3888fbe1f4ffa0ca97a0c9291648 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