From b7ce8721e79fe9d8cd52e517d66a5f2091492134 Mon Sep 17 00:00:00 2001 From: wisonic Date: Sat, 19 Oct 2024 22:56:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=9B=BE=E8=A1=A8):=20=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=BB=9A=E5=8A=A8=E5=88=B0=E5=BA=95=E9=83=A8=E5=90=8E?= =?UTF-8?q?=E5=81=9C=E7=95=99=201.5=20=E7=A7=92=E5=86=8D=E5=9B=9E=E5=88=B0?= =?UTF-8?q?=E9=A1=B6=E9=83=A8=20#12677?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/components/ChartComponentS2.vue | 92 ++++++++++--------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue b/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue index 2575385197..717d32c7b9 100644 --- a/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue +++ b/core/core-frontend/src/views/chart/components/views/components/ChartComponentS2.vue @@ -233,52 +233,56 @@ const mouseLeave = () => { initScroll() } +let scrollTimer const initScroll = () => { - // 首先回到最顶部,然后计算行高*行数作为top,最后判断:如果top<数据量*行高,继续滚动,否则回到顶部 - const customAttr = actualChart?.customAttr - const senior = actualChart?.senior - if ( - myChart && - senior?.scrollCfg?.open && - chartData.value.tableRow?.length && - (view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage)) - ) { - // 防止多次渲染 - myChart.facet.timer?.stop() - // 已滚动的距离 - let scrolledOffset = myChart.store.get('scrollY') || 0 - // 平滑滚动,兼容原有的滚动速率设置 - // 假设原设定为 2 行间隔 2 秒,换算公式为: 滚动到底部的时间 = 未展示部分行数 / 2行 * 2秒 - const offsetHeight = document.getElementById(containerId).offsetHeight - // 没显示就不滚了 - if (!offsetHeight) { - return + scrollTimer && clearTimeout(scrollTimer) + scrollTimer = setTimeout(() => { + // 首先回到最顶部,然后计算行高*行数作为top,最后判断:如果top<数据量*行高,继续滚动,否则回到顶部 + const customAttr = actualChart?.customAttr + const senior = actualChart?.senior + if ( + myChart && + senior?.scrollCfg?.open && + chartData.value.tableRow?.length && + (view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage)) + ) { + // 防止多次渲染 + myChart.facet.timer?.stop() + // 已滚动的距离 + let scrolledOffset = myChart.store.get('scrollY') || 0 + // 平滑滚动,兼容原有的滚动速率设置 + // 假设原设定为 2 行间隔 2 秒,换算公式为: 滚动到底部的时间 = 未展示部分行数 / 2行 * 2秒 + const offsetHeight = document.getElementById(containerId).offsetHeight + // 没显示就不滚了 + if (!offsetHeight) { + return + } + const rowHeight = customAttr.tableCell.tableItemHeight + const headerHeight = + customAttr.tableHeader.showTableHeader === false ? 1 : customAttr.tableHeader.tableTitleHeight + const scrollBarSize = myChart.theme.scrollBar.size + const scrollHeight = + rowHeight * chartData.value.tableRow.length + headerHeight - offsetHeight + scrollBarSize + // 显示内容没撑满 + if (scrollHeight < scrollBarSize) { + return + } + // 到底了重置一下,1是误差 + if (scrolledOffset >= scrollHeight - 1) { + myChart.store.set('scrollY', 0) + myChart.render() + scrolledOffset = 0 + } + const viewedHeight = offsetHeight - headerHeight - scrollBarSize + scrolledOffset + const scrollViewCount = chartData.value.tableRow.length - viewedHeight / rowHeight + const duration = (scrollViewCount / senior.scrollCfg.row) * senior.scrollCfg.interval + myChart.facet.scrollWithAnimation( + { offsetY: { value: scrollHeight, animate: false } }, + duration, + initScroll + ) } - const rowHeight = customAttr.tableCell.tableItemHeight - const headerHeight = - customAttr.tableHeader.showTableHeader === false ? 1 : customAttr.tableHeader.tableTitleHeight - const scrollBarSize = myChart.theme.scrollBar.size - const scrollHeight = - rowHeight * chartData.value.tableRow.length + headerHeight - offsetHeight + scrollBarSize - // 显示内容没撑满 - if (scrollHeight < scrollBarSize) { - return - } - // 到底了重置一下,1是误差 - if (scrolledOffset >= scrollHeight - 1) { - myChart.store.set('scrollY', 0) - myChart.render() - scrolledOffset = 0 - } - const viewedHeight = offsetHeight - headerHeight - scrollBarSize + scrolledOffset - const scrollViewCount = chartData.value.tableRow.length - viewedHeight / rowHeight - const duration = (scrollViewCount / senior.scrollCfg.row) * senior.scrollCfg.interval - myChart.facet.scrollWithAnimation( - { offsetY: { value: scrollHeight, animate: false } }, - duration, - initScroll - ) - } + }, 1500) } const showPage = computed(() => {