diff --git a/src/utils/constants.js b/src/utils/constants.js index 5cd6ab72..11a3517a 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -198,6 +198,11 @@ export const dnsServerRole = { RTDNSM: 'RTDNSM' } +// 整屏滚动的路径映射 +export const wholeScreenRouterMapping = { + dns: '/panel/dnsServiceInsights' +} + export const themeData = [ { value: 'light', label: 'light' }, { value: 'dark', label: 'dark' } diff --git a/src/utils/tools.js b/src/utils/tools.js index c7f94b24..21e7e25d 100644 --- a/src/utils/tools.js +++ b/src/utils/tools.js @@ -652,3 +652,35 @@ export function arrayIsEqual (arr1, arr2) { } } } + +export function scrollToTop (dom, toTop, duration, direction) { + const clientHeight = dom.clientHeight + const currentTop = dom.scrollTop + const totalScrollDistance = Math.abs(currentTop - toTop) + let scrollY = currentTop + let oldTimestamp = null + + function step (newTimestamp) { + if (oldTimestamp !== null) { + if (direction === 'up') { + scrollY -= totalScrollDistance * (newTimestamp - oldTimestamp) / duration + console.info(scrollY) + if (scrollY < 0) { + dom.scrollTop = 0 + return + } + dom.scrollTop = scrollY + } else if (direction === 'down') { + scrollY += totalScrollDistance * (newTimestamp - oldTimestamp) / duration + if (scrollY > clientHeight) { + dom.scrollTop = clientHeight + return + } + dom.scrollTop = scrollY + } + } + oldTimestamp = newTimestamp + window.requestAnimationFrame(step) + } + window.requestAnimationFrame(step) +} diff --git a/src/views/charts/Panel.vue b/src/views/charts/Panel.vue index 0f2ab89e..05697a68 100644 --- a/src/views/charts/Panel.vue +++ b/src/views/charts/Panel.vue @@ -1,5 +1,5 @@