|
@@ -10,7 +10,9 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { nextTick, watch, ref } from 'vue'
|
|
|
+import { wait } from '@/utils/tools'
|
|
|
+import { useFps, useWindowSize, watchDebounced } from '@vueuse/core'
|
|
|
+import { nextTick, ref, watch } from 'vue'
|
|
|
|
|
|
const props = defineProps({
|
|
|
tableData: {
|
|
@@ -49,11 +51,23 @@ watch(
|
|
|
{ immediate: true, deep: true }
|
|
|
)
|
|
|
|
|
|
+const { height: windowHeight } = useWindowSize()
|
|
|
+
|
|
|
+// 窗口高度改变时重新开始滚动
|
|
|
+watchDebounced(
|
|
|
+ windowHeight,
|
|
|
+ () => {
|
|
|
+ initScroll()
|
|
|
+ },
|
|
|
+ { debounce: 500, maxWait: 1000 }
|
|
|
+)
|
|
|
+
|
|
|
let animationId = null
|
|
|
|
|
|
-function initScroll() {
|
|
|
+const fps = useFps()
|
|
|
+
|
|
|
+async function initScroll() {
|
|
|
const ele = listRef.value
|
|
|
- ele.style.maxHeight = 50 * props.rowNum + 'px'
|
|
|
let stopFlag = false
|
|
|
if (animationId !== null) {
|
|
|
stopFlag = true
|
|
@@ -66,7 +80,10 @@ function initScroll() {
|
|
|
return
|
|
|
}
|
|
|
let itemH = ele.scrollHeight / Math.ceil(tableData_render.value.length)
|
|
|
- let intervalLast = props.interval
|
|
|
+ ele.style.maxHeight = itemH * props.rowNum + 'px'
|
|
|
+ if (fps.value === 0) await wait(500) // 等待fps值计算完成,否则为0
|
|
|
+ const computedInterval = Math.round((props.interval * (fps.value || 60)) / 60)
|
|
|
+ let intervalLast = computedInterval
|
|
|
const scroll = (isResume = false) => {
|
|
|
if (ele.scrollTop >= itemH) {
|
|
|
ele.scrollTo(0, 0)
|
|
@@ -76,7 +93,7 @@ function initScroll() {
|
|
|
intervalLast--
|
|
|
} else {
|
|
|
ele.scrollTo(0, ele.scrollTop + props.speed)
|
|
|
- intervalLast = props.interval
|
|
|
+ intervalLast = computedInterval
|
|
|
}
|
|
|
if (stopFlag || isResume) {
|
|
|
window.cancelAnimationFrame(animationId)
|