feat(图表): 表格鼠标悬停暂停滚动 #9106 #9750 #10502

This commit is contained in:
wisonic 2024-07-11 14:55:45 +08:00
parent 80526b89d0
commit 43d46a8c97

View File

@ -28,6 +28,7 @@ import { customAttrTrans, customStyleTrans, recursionTransObj } from '@/utils/ca
import { deepCopy } from '@/utils/utils' import { deepCopy } from '@/utils/utils'
import { useEmitt } from '@/hooks/web/useEmitt' import { useEmitt } from '@/hooks/web/useEmitt'
import { trackBarStyleCheck } from '@/utils/canvasUtils' import { trackBarStyleCheck } from '@/utils/canvasUtils'
import { type SpreadSheet } from '@antv/s2'
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
const { const {
@ -142,7 +143,7 @@ const calcData = (view: Chart, callback, resetPageInfo = true) => {
} }
} }
// //
let myChart = null let myChart: SpreadSheet = null
// //
let actualChart: ChartObj let actualChart: ChartObj
const renderChartFromDialog = (viewInfo: Chart, chartDataInfo) => { const renderChartFromDialog = (viewInfo: Chart, chartDataInfo) => {
@ -164,7 +165,9 @@ const renderChart = (viewInfo: Chart, resetPageInfo: boolean) => {
setupPage(actualChart, resetPageInfo) setupPage(actualChart, resetPageInfo)
myChart?.facet.timer?.stop() myChart?.facet.timer?.stop()
myChart?.facet.cancelScrollFrame()
myChart?.destroy() myChart?.destroy()
myChart = null
const chartView = chartViewManager.getChartView( const chartView = chartViewManager.getChartView(
viewInfo.render, viewInfo.render,
viewInfo.type viewInfo.type
@ -207,21 +210,28 @@ const setupPage = (chart: ChartObj, resetPageInfo?: boolean) => {
} }
} }
const mouseMove = () => {
myChart?.facet.timer?.stop()
}
const mouseLeave = () => {
initScroll()
}
const initScroll = () => { const initScroll = () => {
// *toptop<* // *toptop<*
const customAttr = actualChart?.customAttr const customAttr = actualChart?.customAttr
const senior = actualChart?.senior const senior = actualChart?.senior
if ( if (
myChart &&
senior?.scrollCfg?.open && senior?.scrollCfg?.open &&
chartData.value.tableRow?.length && chartData.value.tableRow?.length &&
(view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage)) (view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage))
) { ) {
// //
myChart.facet.timer?.stop() myChart.facet.timer?.stop()
if (myChart.store.get('scrollY') !== 0) { //
myChart.store.set('scrollY', 0) let scrolledOffset = myChart.store.get('scrollY') || 0
myChart.render()
}
// //
// 2 2 : = / 2 * 2 // 2 2 : = / 2 * 2
const offsetHeight = document.getElementById(containerId).offsetHeight const offsetHeight = document.getElementById(containerId).offsetHeight
@ -239,8 +249,14 @@ const initScroll = () => {
if (scrollHeight < scrollBarSize) { if (scrollHeight < scrollBarSize) {
return return
} }
const viewHeight = offsetHeight - headerHeight - scrollBarSize // ,1
const scrollViewCount = chartData.value.tableRow.length - viewHeight / rowHeight 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 const duration = (scrollViewCount / senior.scrollCfg.row) * senior.scrollCfg.interval
myChart.facet.scrollWithAnimation( myChart.facet.scrollWithAnimation(
{ offsetY: { value: scrollHeight, animate: false } }, { offsetY: { value: scrollHeight, animate: false } },
@ -462,6 +478,7 @@ onMounted(() => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
myChart?.facet.timer?.stop() myChart?.facet.timer?.stop()
myChart?.destroy() myChart?.destroy()
myChart = null
resizeObserver?.disconnect() resizeObserver?.disconnect()
}) })
@ -501,9 +518,15 @@ const tablePageClass = computed(() => {
class="track-bar" class="track-bar"
:style="state.trackBarStyle" :style="state.trackBarStyle"
@trackClick="trackClick" @trackClick="trackClick"
@mousemove="mouseMove"
/> />
<div v-if="!isError" class="canvas-content"> <div v-if="!isError" class="canvas-content">
<div style="position: relative; height: 100%" :id="containerId"></div> <div
:id="containerId"
style="position: relative; height: 100%"
@mousemove="mouseMove"
@mouseleave="mouseLeave"
></div>
</div> </div>
<el-row :style="autoStyle" v-if="showPage && !isError"> <el-row :style="autoStyle" v-if="showPage && !isError">
<div <div