Merge pull request #8405 from dataease/pr@dev@feat_antv_table_smooth_scroll

feat(视图): AntV 表格支持平滑滚动 #7277
This commit is contained in:
wisonic-s 2024-03-07 18:14:18 +08:00 committed by GitHub
commit 86ad926ac0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 59 deletions

View File

@ -35,7 +35,7 @@
"@antv/l7-scene": "2.15.0",
"@antv/l7-source": "2.15.0",
"@antv/l7-utils": "2.15.0",
"@antv/s2": "1.49.1",
"@antv/s2": "^1.54.6",
"@antv/util": "^2.0.17",
"@riophae/vue-treeselect": "0.4.0",
"@tinymce/tinymce-vue": "^3.2.8",

View File

@ -76,15 +76,12 @@ class SortTooltip extends BaseTooltip {
})
}
}
export function baseTableInfo(s2, container, chart, action, tableData, pageInfo, vueCom, resizeFunc) {
export function baseTableInfo(container, chart, action, tableData, pageInfo, vueCom, resizeFunc) {
const containerDom = document.getElementById(container)
// fields
let fields = chart.data.fields
if (!fields || fields.length === 0) {
if (s2) {
s2.destroy()
}
return
}
@ -242,10 +239,7 @@ export function baseTableInfo(s2, container, chart, action, tableData, pageInfo,
}
// 开始渲染
if (s2) {
s2.destroy()
}
s2 = new TableSheet(containerDom, s2DataConfig, s2Options)
const s2 = new TableSheet(containerDom, s2DataConfig, s2Options)
// click
s2.on(S2Event.DATA_CELL_CLICK, action)
@ -270,16 +264,13 @@ export function baseTableInfo(s2, container, chart, action, tableData, pageInfo,
return s2
}
export function baseTableNormal(s2, container, chart, action, tableData, vueCom, resizeFunc) {
export function baseTableNormal(container, chart, action, tableData, vueCom, resizeFunc) {
const containerDom = document.getElementById(container)
if (!containerDom) return
// fields
const fields = chart.data.fields
if (!fields || fields.length === 0) {
if (s2) {
s2.destroy()
}
return
}
@ -482,10 +473,7 @@ export function baseTableNormal(s2, container, chart, action, tableData, vueCom,
}
// 开始渲染
if (s2) {
s2.destroy()
}
s2 = new TableSheet(containerDom, s2DataConfig, s2Options)
const s2 = new TableSheet(containerDom, s2DataConfig, s2Options)
// click
s2.on(S2Event.DATA_CELL_CLICK, action)
@ -510,7 +498,7 @@ export function baseTableNormal(s2, container, chart, action, tableData, vueCom,
return s2
}
export function baseTablePivot(s2, container, chart, action, headerAction, tableData) {
export function baseTablePivot(container, chart, action, headerAction, tableData) {
const containerDom = document.getElementById(container)
// row and column
@ -531,9 +519,6 @@ export function baseTablePivot(s2, container, chart, action, headerAction, table
// fields
const fields = chart.data.fields
if (!fields || fields.length === 0) {
if (s2) {
s2.destroy()
}
return
}
@ -712,10 +697,7 @@ export function baseTablePivot(s2, container, chart, action, headerAction, table
}
// 开始渲染
if (s2) {
s2.destroy()
}
s2 = new PivotSheet(containerDom, s2DataConfig, s2Options)
const s2 = new PivotSheet(containerDom, s2DataConfig, s2Options)
// click
s2.on(S2Event.DATA_CELL_CLICK, action)

View File

@ -142,7 +142,6 @@ export default {
},
data() {
return {
myChart: null,
chartId: uuid.v1(),
showTrackBar: true,
trackBarStyle: {
@ -242,6 +241,7 @@ export default {
beforeDestroy() {
clearInterval(this.scrollTimer)
window.removeEventListener('resize', this.chartResize)
this.myChart?.facet.timer?.stop()
this.myChart?.destroy?.()
this.myChart = null
},
@ -287,8 +287,6 @@ export default {
},
drawView() {
const chart = this.chart
// type
// if (chart.data) {
this.antVRenderStatus = true
if (!chart.data || (!chart.data.data && !chart.data.series)) {
chart.data = {
@ -300,17 +298,16 @@ export default {
]
}
}
if (this.myChart) {
this.myChart?.facet.timer?.stop()
this.myChart.destroy()
}
if (chart.type === 'table-info') {
this.myChart = baseTableInfo(this.myChart, this.chartId, chart, this.antVAction, this.tableData, this.currentPage, this, this.columnResize)
this.myChart = baseTableInfo(this.chartId, chart, this.antVAction, this.tableData, this.currentPage, this, this.columnResize)
} else if (chart.type === 'table-normal') {
this.myChart = baseTableNormal(this.myChart, this.chartId, chart, this.antVAction, this.tableData, this, this.columnResize)
this.myChart = baseTableNormal(this.chartId, chart, this.antVAction, this.tableData, this, this.columnResize)
} else if (chart.type === 'table-pivot') {
this.myChart = baseTablePivot(this.myChart, this.chartId, chart, this.antVAction, this.tableHeaderClick, this.tableData)
} else {
if (this.myChart) {
this.antVRenderStatus = false
this.myChart.destroy()
}
this.myChart = baseTablePivot(this.chartId, chart, this.antVAction, this.tableHeaderClick, this.tableData)
}
if (this.myChart && this.searchCount > 0) {
@ -406,6 +403,7 @@ export default {
this.myChart?.changeSheetSize(width, height)
// tab
if (chartWidth || chartHeight || !(chartHeight || chartWidth)) {
this.myChart.facet.timer?.stop()
this.myChart.render()
}
this.initScroll()
@ -526,35 +524,32 @@ export default {
},
initScroll() {
clearInterval(this.scrollTimer)
// *toptop<*
clearTimeout(this.scrollTimer)
const customAttr = JSON.parse(this.chart.customAttr)
const senior = JSON.parse(this.chart.senior)
this.scrollTop = 0
if (senior && senior.scrollCfg && senior.scrollCfg.open && (this.chart.type === 'table-normal' || (this.chart.type === 'table-info' && !this.showPage))) {
//
this.myChart.facet.timer?.stop()
if (this.myChart.store.get('scrollY') !== 0) {
this.myChart.store.set('scrollY', 0)
this.myChart.render()
}
//
// 2 2 : = / 2 * 2
const rowHeight = customAttr.size.tableItemHeight
const headerHeight = customAttr.size.tableTitleHeight
this.scrollTimer = setInterval(() => {
const offsetHeight = document.getElementById(this.chartId).offsetHeight
const top = rowHeight * senior.scrollCfg.row
if ((offsetHeight - headerHeight + this.scrollTop) < rowHeight * this.chart.data.tableRow.length) {
this.scrollTop += top
} else {
this.scrollTop = 0
const scrollBarSize = this.myChart.theme.scrollBar.size
const offsetHeight = document.getElementById(this.chartId).offsetHeight
const scrollHeight = rowHeight * this.chart.data.tableRow.length + headerHeight - offsetHeight + scrollBarSize
const viewHeight = offsetHeight - headerHeight - scrollBarSize
const scrollViewCount = this.chart.data.tableRow.length - viewHeight / rowHeight
const duration = scrollViewCount / senior.scrollCfg.row * senior.scrollCfg.interval
this.myChart.facet.scrollWithAnimation({
offsetY: {
value: scrollHeight,
animate: false
}
if (!offsetHeight) {
return
}
this.myChart.facet.scrollWithAnimation({
offsetY: {
value: this.scrollTop,
animate: false
}
})
}, senior.scrollCfg.interval)
}, duration, this.initScroll)
}
},
initRemark() {