From a025523fc55a08cd8abd03952003fb4aef0a44ce Mon Sep 17 00:00:00 2001 From: jiangjunjie Date: Thu, 24 Sep 2026 14:36:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=91=E7=94=9F=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 6 +++--- src/components/chat-new.vue | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/App.vue b/src/App.vue index 097f3e8..4b8d162 100644 --- a/src/App.vue +++ b/src/App.vue @@ -14,9 +14,9 @@ window.wx = wx const appStore = useAppStore() const appStoreRefs = storeToRefs(appStore) provide('appStore', appStore) -// Object.keys(appStoreRefs).forEach((key) => { -// provide(key, appStoreRefs[key]) -// }) +Object.keys(appStoreRefs).forEach((key) => { + provide(key, appStoreRefs[key]) +}) const handleGlobalBrowserExit = (reason, extra = {}) => { const payload = { diff --git a/src/components/chat-new.vue b/src/components/chat-new.vue index 57a6373..640d955 100644 --- a/src/components/chat-new.vue +++ b/src/components/chat-new.vue @@ -221,6 +221,27 @@ function scrollMainTo(top) { return Math.abs((el.scrollTop || 0) - value) < 2 || value === 0 } +let smoothScrollToken = 0 + +function smoothScrollMainToBottom(duration = 300) { + const el = getMainEl() + if (!el) return + const target = el.scrollHeight - el.clientHeight + const start = el.scrollTop + const delta = target - start + if (delta <= 2) return + const token = ++smoothScrollToken + const startTime = performance.now() + const step = (now) => { + if (token !== smoothScrollToken) return + const t = Math.min(1, (now - startTime) / duration) + const eased = 1 - Math.pow(1 - t, 3) + el.scrollTop = start + delta * eased + if (t < 1) requestAnimationFrame(step) + } + requestAnimationFrame(step) +} + const savedScrollTop = ref(0) const shouldRestoreScroll = ref(false) const isRestoringScroll = ref(false) @@ -462,8 +483,7 @@ watch( // 从其他路由返回、正在恢复滚动位置时,不要强制滚到底部 if (isRestoringScroll.value || shouldRestoreScroll.value) return nextTick(() => { - const container = getMainEl() - if (container) container.scrollTop = container.scrollHeight + smoothScrollMainToBottom() }) }, { deep: true },