fix: 滚动排名列表问题当数据量小于等于列表数时,第一条数据会直接不显示

This commit is contained in:
刘嘉威 2022-11-18 11:25:41 +08:00
parent 804028d5be
commit b8ff876278

View File

@ -62,7 +62,7 @@ const status = reactive({
const calcRowsData = () => { const calcRowsData = () => {
let { dataset, rowNum, sort } = status.mergedConfig let { dataset, rowNum, sort } = status.mergedConfig
// @ts-ignore // @ts-ignore
sort && dataset.sort(({ value: a }, { value: b }) => { sort &&dataset.sort(({ value: a }, { value: b } ) => {
if (a > b) return -1 if (a > b) return -1
if (a < b) return 1 if (a < b) return 1
if (a === b) return 0 if (a === b) return 0
@ -94,6 +94,7 @@ const calcHeights = (onresize = false) => {
const { rowNum, dataset } = status.mergedConfig const { rowNum, dataset } = status.mergedConfig
const avgHeight = h.value / rowNum const avgHeight = h.value / rowNum
status.avgHeight = avgHeight status.avgHeight = avgHeight
if (!onresize) status.heights = new Array(dataset.length).fill(avgHeight) if (!onresize) status.heights = new Array(dataset.length).fill(avgHeight)
} }
@ -131,12 +132,17 @@ const stopAnimation = () => {
const onRestart = async () => { const onRestart = async () => {
try { try {
if (!status.mergedConfig) return if (!status.mergedConfig) return
let { dataset, rowNum, sort } = status.mergedConfig
stopAnimation() stopAnimation()
calcRowsData() calcRowsData()
calcHeights(true) let flag = true
animation(true) if (dataset.length <= rowNum) {
flag=false
}
calcHeights(flag)
animation(flag)
} catch (error) { } catch (error) {
console.log(error) console.error(error)
} }
} }