Merge pull request #104 from wangzhiyonglyk/master

fix: 修复纵向滑动的下标的bug
This commit is contained in:
Zyronon 2024-09-08 20:57:53 +08:00 committed by GitHub
commit 1fd5c98c49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -79,8 +79,8 @@ watch(
() => props.list,
(newVal, oldVal) => {
// console.log('watch-list', newVal.length, oldVal.length, newVal)
//
if (newVal.length < oldVal.length) {
//
if (newVal.length <= oldVal.length) {
insertContent()
} else {
//
@ -112,10 +112,45 @@ watch(
watch(
() => props.index,
(newVal, oldVal) => {
(newVal) => {
state.localIndex = newVal
// 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.SINGLE_CLICK_BROADCAST, {
uniqueId: props.uniqueId,
@ -131,7 +166,6 @@ watch(
}, 200)
}
)
watch(
() => props.active,
(newVal) => {
@ -166,7 +200,7 @@ function insertContent() {
if (!props.list.length) return
//SlideList
slideListEl.value.innerHTML = ''
let half = (props.virtualTotal - 1) / 2
let half = parseInt((props.virtualTotal / 2).toString()) //
// props.virtualTotal domindex0
let start = 0
if (state.localIndex > half) {
@ -272,7 +306,7 @@ function touchEnd(e) {
emit('refresh')
}
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 (isNext) {