fix: 修复纵向滑动的下标的bug

This commit is contained in:
王志勇 2024-09-08 20:28:16 +08:00
parent 83caeaf669
commit 9a23497964

View File

@ -79,8 +79,8 @@ watch(
() => props.list, () => props.list,
(newVal, oldVal) => { (newVal, oldVal) => {
// console.log('watch-list', newVal.length, oldVal.length, newVal) // console.log('watch-list', newVal.length, oldVal.length, newVal)
// //
if (newVal.length < oldVal.length) { if (newVal.length <= oldVal.length) {
insertContent() insertContent()
} else { } else {
// //
@ -112,10 +112,45 @@ watch(
watch( watch(
() => props.index, () => props.index,
(newVal, oldVal) => { (newVal) => {
state.localIndex = newVal state.localIndex = newVal
// console.log('watch-index', newVal, oldVal) // console.log('watch-index', newVal, oldVal)
if (!props.list.length) return if (!props?.list?.length) return
//
if (
slideListEl.value &&
slideListEl.value?.innerHTML &&
state.localIndex < props?.list?.length
) {
let startIndex = slideListEl.value
.querySelector(`.${itemClassName}:first-child`)
.getAttribute('data-index')
let endIndex = slideListEl.value
.querySelector(`.${itemClassName}:last-child`)
.getAttribute('data-index')
if (
state.localIndex >= (startIndex as any) * 1 &&
state.localIndex <= (endIndex as any) * 1
) {
//
touchEnd({})
} else {
//
insertContent()
}
}
}
)
/**
* 滑动
*/
watch(
() => state.localIndex,
(newVal, oldVal) => {
bus.emit(EVENT_KEY.CURRENT_ITEM, props.list[newVal]) bus.emit(EVENT_KEY.CURRENT_ITEM, props.list[newVal])
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, { bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
uniqueId: props.uniqueId, uniqueId: props.uniqueId,
@ -131,7 +166,6 @@ watch(
}, 200) }, 200)
} }
) )
watch( watch(
() => props.active, () => props.active,
(newVal) => { (newVal) => {
@ -166,7 +200,7 @@ function insertContent() {
if (!props.list.length) return if (!props.list.length) return
//SlideList //SlideList
slideListEl.value.innerHTML = '' slideListEl.value.innerHTML = ''
let half = (props.virtualTotal - 1) / 2 let half = parseInt((props.virtualTotal / 2).toString()) //
// props.virtualTotal domindex0 // props.virtualTotal domindex0
let start = 0 let start = 0
if (state.localIndex > half) { if (state.localIndex > half) {
@ -272,7 +306,7 @@ function touchEnd(e) {
emit('refresh') emit('refresh')
} }
slideTouchEnd(e, state, canNext, (isNext) => { slideTouchEnd(e, state, canNext, (isNext) => {
let half = (props.virtualTotal - 1) / 2 let half = parseInt((props.virtualTotal / 2).toString()) //
if (props.list.length > props.virtualTotal) { if (props.list.length > props.virtualTotal) {
//() //()
if (isNext) { if (isNext) {