forked from github/dataease
Merge pull request #12785 from dataease/pr@dev-v2@refactor_table_scroll_suspend
refactor(图表): 表格滚动到底部后停留 1.5 秒再回到顶部 #12677
This commit is contained in:
commit
2c941b7eb9
@ -233,52 +233,56 @@ const mouseLeave = () => {
|
|||||||
initScroll()
|
initScroll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let scrollTimer
|
||||||
const initScroll = () => {
|
const initScroll = () => {
|
||||||
// 首先回到最顶部,然后计算行高*行数作为top,最后判断:如果top<数据量*行高,继续滚动,否则回到顶部
|
scrollTimer && clearTimeout(scrollTimer)
|
||||||
const customAttr = actualChart?.customAttr
|
scrollTimer = setTimeout(() => {
|
||||||
const senior = actualChart?.senior
|
// 首先回到最顶部,然后计算行高*行数作为top,最后判断:如果top<数据量*行高,继续滚动,否则回到顶部
|
||||||
if (
|
const customAttr = actualChart?.customAttr
|
||||||
myChart &&
|
const senior = actualChart?.senior
|
||||||
senior?.scrollCfg?.open &&
|
if (
|
||||||
chartData.value.tableRow?.length &&
|
myChart &&
|
||||||
(view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage))
|
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
|
myChart.facet.timer?.stop()
|
||||||
// 平滑滚动,兼容原有的滚动速率设置
|
// 已滚动的距离
|
||||||
// 假设原设定为 2 行间隔 2 秒,换算公式为: 滚动到底部的时间 = 未展示部分行数 / 2行 * 2秒
|
let scrolledOffset = myChart.store.get('scrollY') || 0
|
||||||
const offsetHeight = document.getElementById(containerId).offsetHeight
|
// 平滑滚动,兼容原有的滚动速率设置
|
||||||
// 没显示就不滚了
|
// 假设原设定为 2 行间隔 2 秒,换算公式为: 滚动到底部的时间 = 未展示部分行数 / 2行 * 2秒
|
||||||
if (!offsetHeight) {
|
const offsetHeight = document.getElementById(containerId).offsetHeight
|
||||||
return
|
// 没显示就不滚了
|
||||||
|
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
|
}, 1500)
|
||||||
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 showPage = computed(() => {
|
const showPage = computed(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user