mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
c3df9397c8
commit
2d47fb418f
@ -324,17 +324,39 @@ VantComponent({
|
|||||||
onTouchEnd() {
|
onTouchEnd() {
|
||||||
if (!this.data.swipeable) return;
|
if (!this.data.swipeable) return;
|
||||||
|
|
||||||
const { tabs, currentIndex } = this.data;
|
|
||||||
const { direction, deltaX, offsetX } = this;
|
const { direction, deltaX, offsetX } = this;
|
||||||
const minSwipeDistance = 50;
|
const minSwipeDistance = 50;
|
||||||
|
|
||||||
if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
|
if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
|
||||||
if (deltaX > 0 && currentIndex !== 0) {
|
const index = this.getAvaiableTab(deltaX);
|
||||||
this.setCurrentIndex(currentIndex - 1);
|
if (index !== -1) {
|
||||||
} else if (deltaX < 0 && currentIndex !== tabs.length - 1) {
|
this.setCurrentIndex(index);
|
||||||
this.setCurrentIndex(currentIndex + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getAvaiableTab(direction: number) {
|
||||||
|
const { tabs, currentIndex } = this.data;
|
||||||
|
const step = direction > 0 ? -1 : 1;
|
||||||
|
|
||||||
|
for (
|
||||||
|
let i = step;
|
||||||
|
currentIndex + i < tabs.length && currentIndex + i >= 0;
|
||||||
|
i += step
|
||||||
|
) {
|
||||||
|
const index = currentIndex + i;
|
||||||
|
|
||||||
|
if (
|
||||||
|
index >= 0 &&
|
||||||
|
index < tabs.length &&
|
||||||
|
tabs[index] &&
|
||||||
|
!tabs[index].disabled
|
||||||
|
) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user