forked from github/dataease
Merge pull request #8476 from dataease/pr@dev-v2@feat_table_smooth_scroll
feat(图表): 表格支持平滑滚动 #7277
This commit is contained in:
commit
902d21842c
@ -136,6 +136,7 @@ const renderChart = (viewInfo: Chart, resetPageInfo: boolean) => {
|
|||||||
recursionTransObj(customStyleTrans, chart.customStyle, scale.value, terminal.value)
|
recursionTransObj(customStyleTrans, chart.customStyle, scale.value, terminal.value)
|
||||||
|
|
||||||
setupPage(chart, resetPageInfo)
|
setupPage(chart, resetPageInfo)
|
||||||
|
myChart?.facet.timer?.stop()
|
||||||
myChart?.destroy()
|
myChart?.destroy()
|
||||||
const chartView = chartViewManager.getChartView(
|
const chartView = chartViewManager.getChartView(
|
||||||
viewInfo.render,
|
viewInfo.render,
|
||||||
@ -172,38 +173,44 @@ const setupPage = (chart: ChartObj, resetPageInfo?: boolean) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let scrollTimer: number
|
|
||||||
let scrollTop = 0
|
|
||||||
const initScroll = () => {
|
const initScroll = () => {
|
||||||
clearInterval(scrollTimer)
|
|
||||||
// 首先回到最顶部,然后计算行高*行数作为top,最后判断:如果top<数据量*行高,继续滚动,否则回到顶部
|
// 首先回到最顶部,然后计算行高*行数作为top,最后判断:如果top<数据量*行高,继续滚动,否则回到顶部
|
||||||
const customAttr = view.value.customAttr
|
const customAttr = view.value.customAttr
|
||||||
const senior = view.value.senior
|
const senior = view.value.senior
|
||||||
scrollTop = 0
|
|
||||||
if (
|
if (
|
||||||
senior?.scrollCfg?.open &&
|
senior?.scrollCfg?.open &&
|
||||||
(view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage))
|
(view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage))
|
||||||
) {
|
) {
|
||||||
const rowHeight = customAttr.tableCell.tableItemHeight
|
// 防止多次渲染
|
||||||
const headerHeight = customAttr.tableHeader.tableTitleHeight
|
myChart.facet.timer?.stop()
|
||||||
const dom = document.getElementById(containerId)
|
if (myChart.store.get('scrollY') !== 0) {
|
||||||
if (dom.offsetHeight > rowHeight * chartData.value.tableRow.length + headerHeight) {
|
myChart.store.set('scrollY', 0)
|
||||||
|
myChart.render()
|
||||||
|
}
|
||||||
|
// 平滑滚动,兼容原有的滚动速率设置
|
||||||
|
// 假设原设定为 2 行间隔 2 秒,换算公式为: 滚动到底部的时间 = 未展示部分行数 / 2行 * 2秒
|
||||||
|
const offsetHeight = document.getElementById(containerId).offsetHeight
|
||||||
|
// 没显示就不滚了
|
||||||
|
if (!offsetHeight) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
scrollTimer = setInterval(() => {
|
const rowHeight = customAttr.tableCell.tableItemHeight
|
||||||
const offsetHeight = dom.offsetHeight
|
const headerHeight = customAttr.tableHeader.tableTitleHeight
|
||||||
const top = rowHeight * senior.scrollCfg.row
|
const scrollBarSize = myChart.theme.scrollBar.size
|
||||||
if (offsetHeight - headerHeight + scrollTop < rowHeight * chartData.value.tableRow.length) {
|
const scrollHeight =
|
||||||
scrollTop += top
|
rowHeight * chartData.value.tableRow.length + headerHeight - offsetHeight + scrollBarSize
|
||||||
} else {
|
// 显示内容没撑满
|
||||||
scrollTop = 0
|
if (scrollHeight < scrollBarSize) {
|
||||||
}
|
return
|
||||||
myChart.store.set('scrollY', scrollTop)
|
}
|
||||||
if (!offsetHeight) {
|
const viewHeight = offsetHeight - headerHeight - scrollBarSize
|
||||||
return
|
const scrollViewCount = chartData.value.tableRow.length - viewHeight / rowHeight
|
||||||
}
|
const duration = (scrollViewCount / senior.scrollCfg.row) * senior.scrollCfg.interval
|
||||||
myChart.render()
|
myChart.facet.scrollWithAnimation(
|
||||||
}, senior.scrollCfg.interval)
|
{ offsetY: { value: scrollHeight, animate: false } },
|
||||||
|
duration,
|
||||||
|
initScroll
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +342,7 @@ const resize = (width, height) => {
|
|||||||
}
|
}
|
||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
myChart?.changeSheetSize(width, height)
|
myChart?.changeSheetSize(width, height)
|
||||||
|
myChart?.facet.timer?.stop()
|
||||||
myChart?.render()
|
myChart?.render()
|
||||||
initScroll()
|
initScroll()
|
||||||
}, 500)
|
}, 500)
|
||||||
@ -363,9 +371,9 @@ onMounted(() => {
|
|||||||
resizeObserver.observe(document.getElementById(containerId))
|
resizeObserver.observe(document.getElementById(containerId))
|
||||||
})
|
})
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
myChart?.facet.timer?.stop()
|
||||||
myChart?.destroy()
|
myChart?.destroy()
|
||||||
resizeObserver?.disconnect()
|
resizeObserver?.disconnect()
|
||||||
clearInterval(scrollTimer)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const autoStyle = computed(() => {
|
const autoStyle = computed(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user