|
|
|
|
@ -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 }, |
|
|
|
|
|