调整发生不显示问题

master
jiangjunjie 1 week ago
parent eda66d9d9e
commit a025523fc5
  1. 6
      src/App.vue
  2. 24
      src/components/chat-new.vue

@ -14,9 +14,9 @@ window.wx = wx
const appStore = useAppStore() const appStore = useAppStore()
const appStoreRefs = storeToRefs(appStore) const appStoreRefs = storeToRefs(appStore)
provide('appStore', appStore) provide('appStore', appStore)
// Object.keys(appStoreRefs).forEach((key) => { Object.keys(appStoreRefs).forEach((key) => {
// provide(key, appStoreRefs[key]) provide(key, appStoreRefs[key])
// }) })
const handleGlobalBrowserExit = (reason, extra = {}) => { const handleGlobalBrowserExit = (reason, extra = {}) => {
const payload = { const payload = {

@ -221,6 +221,27 @@ function scrollMainTo(top) {
return Math.abs((el.scrollTop || 0) - value) < 2 || value === 0 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 savedScrollTop = ref(0)
const shouldRestoreScroll = ref(false) const shouldRestoreScroll = ref(false)
const isRestoringScroll = ref(false) const isRestoringScroll = ref(false)
@ -462,8 +483,7 @@ watch(
// 从其他路由返回、正在恢复滚动位置时,不要强制滚到底部 // 从其他路由返回、正在恢复滚动位置时,不要强制滚到底部
if (isRestoringScroll.value || shouldRestoreScroll.value) return if (isRestoringScroll.value || shouldRestoreScroll.value) return
nextTick(() => { nextTick(() => {
const container = getMainEl() smoothScrollMainToBottom()
if (container) container.scrollTop = container.scrollHeight
}) })
}, },
{ deep: true }, { deep: true },

Loading…
Cancel
Save