diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index c67162f..f1c50f2 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -39,9 +39,9 @@
@@ -193,7 +193,7 @@ 你可能感兴趣
-
+
{ // console.log('move-nextcb') }, - SlideType.HORIZONTAL, () => { if (state.operationStatus !== SlideAlbumOperationStatus.Normal) { Utils.$stopPropagation(e) @@ -567,7 +567,7 @@ function touchEnd(e) { startLoop() state.operationStatus = SlideAlbumOperationStatus.Look } else { - slideTouchEnd( + slideTouchUp( e, state, canNext, @@ -582,7 +582,7 @@ function touchEnd(e) { startLoop() } ) - slideReset(wrapperEl.value, state, SlideType.HORIZONTAL, null) + slideReset(wrapperEl.value, state) } } } diff --git a/src/components/slide/SlideHorizontal.vue b/src/components/slide/SlideHorizontal.vue index 84f3ec7..05bb84c 100644 --- a/src/components/slide/SlideHorizontal.vue +++ b/src/components/slide/SlideHorizontal.vue @@ -2,12 +2,12 @@ import { onMounted, onUnmounted, reactive, ref, watch } from 'vue' import GM from '../../utils' import { - getSlideDistance, + getSlideOffset, slideInit, + slidePointerDown, + slidePointerMove, slideReset, - slideTouchEnd, - slideTouchMove, - slideTouchStart + slideTouchUp } from '@/utils/slide' import { SlideType } from '@/utils/const_var' @@ -31,17 +31,22 @@ const props = defineProps({ const emit = defineEmits(['update:index']) let ob = null -const judgeValue = 20 const wrapperEl = ref(null) const state = reactive({ + judgeValue: 20, + type: SlideType.HORIZONTAL, name: props.name, localIndex: props.index, needCheck: true, next: false, start: { x: 0, y: 0, time: 0 }, move: { x: 0, y: 0 }, - wrapper: { width: 0, height: 0, childrenLength: 0 }, - isDown: false + wrapper: { + width: 0, + height: 0, + //childrenLength用于canNext方法判断当前页是否是最后一页,是则不能滑动,不捕获事件 + childrenLength: 0 + } }) watch( @@ -55,15 +60,17 @@ watch( GM.$setCss( wrapperEl.value, 'transform', - `translate3d(${getSlideDistance(state, SlideType.HORIZONTAL, wrapperEl.value)}px, 0, 0)` + `translate3d(${getSlideOffset(state, wrapperEl.value)}px, 0, 0)` ) } } ) onMounted(() => { - slideInit(wrapperEl.value, state, SlideType.HORIZONTAL) + slideInit(wrapperEl.value, state) + //观察子元素数量变动,获取最新数量 + //childrenLength用于canNext方法判断当前页是否是最后一页,是则不能滑动,不捕获事件 ob = new MutationObserver(() => { state.wrapper.childrenLength = wrapperEl.value.children.length }) @@ -74,27 +81,17 @@ onUnmounted(() => { ob.disconnect() }) -function touchStart(e: PointerEvent) { - slideTouchStart(e, wrapperEl.value, state) +function touchStart(e: TouchEvent) { + slidePointerDown(e, wrapperEl.value, state) } -function touchMove(e: PointerEvent) { - slideTouchMove( - e, - wrapperEl.value, - state, - judgeValue, - canNext, - null, - SlideType.HORIZONTAL, - null, - null - ) +function touchMove(e: TouchEvent) { + slidePointerMove(e, wrapperEl.value, state, canNext) } -function touchEnd(e: PointerEvent) { - slideTouchEnd(e, state, canNext, () => {}) - slideReset(wrapperEl.value, state, SlideType.HORIZONTAL, emit) +function touchEnd(e: TouchEvent) { + slideTouchUp(e, state, canNext, () => {}) + slideReset(wrapperEl.value, state, emit) } function canNext(isNext: boolean) { @@ -110,9 +107,9 @@ function canNext(isNext: boolean) {
diff --git a/src/components/slide/SlideVertical.vue b/src/components/slide/SlideVertical.vue index 4878bbe..16ef8ef 100644 --- a/src/components/slide/SlideVertical.vue +++ b/src/components/slide/SlideVertical.vue @@ -2,12 +2,12 @@ import { onMounted, reactive, ref, watch } from 'vue' import GM from '../../utils' import { - getSlideDistance, + getSlideOffset, slideInit, slideReset, - slideTouchEnd, - slideTouchMove, - slideTouchStart + slideTouchUp, + slidePointerMove, + slidePointerDown } from '@/utils/slide' import { SlideType } from '@/utils/const_var' @@ -26,17 +26,17 @@ const props = defineProps({ }) const emit = defineEmits(['update:index']) -const judgeValue = 20 const wrapperEl = ref(null) const state = reactive({ + judgeValue: 20, + type: SlideType.HORIZONTAL, name: 'SlideVertical', localIndex: props.index, needCheck: true, next: false, start: { x: 0, y: 0, time: 0 }, move: { x: 0, y: 0 }, - wrapper: { width: 0, height: 0, childrenLength: 0 }, - isDown: false + wrapper: { width: 0, height: 0, childrenLength: 0 } }) watch( @@ -50,27 +50,27 @@ watch( GM.$setCss( wrapperEl.value, 'transform', - `translate3d(0,${getSlideDistance(state, SlideType.VERTICAL)}px, 0)` + `translate3d(0,${getSlideOffset(state, wrapperEl.value)}px, 0)` ) } } ) onMounted(() => { - slideInit(wrapperEl.value, state, SlideType.VERTICAL) + slideInit(wrapperEl.value, state) }) function touchStart(e) { - slideTouchStart(e, wrapperEl.value, state) + slidePointerDown(e, wrapperEl.value, state) } function touchMove(e) { - slideTouchMove(e, wrapperEl.value, state, judgeValue, canNext, null, SlideType.VERTICAL) + slidePointerMove(e, wrapperEl.value, state, canNext) } function touchEnd(e) { - slideTouchEnd(e, state, canNext, null, null, SlideType.VERTICAL) - slideReset(wrapperEl.value, state, SlideType.VERTICAL, emit) + slideTouchUp(e, state, canNext, null, null, SlideType.VERTICAL) + slideReset(wrapperEl.value, state, emit) } function canNext(isNext) { @@ -86,9 +86,9 @@ function canNext(isNext) {
diff --git a/src/components/slide/SlideVerticalInfinite.vue b/src/components/slide/SlideVerticalInfinite.vue index 1d59fe8..6c6801f 100644 --- a/src/components/slide/SlideVerticalInfinite.vue +++ b/src/components/slide/SlideVerticalInfinite.vue @@ -2,12 +2,12 @@ import { createApp, onMounted, reactive, ref, render as vueRender, watch } from 'vue' import GM from '../../utils' import { - getSlideDistance, + getSlideOffset, slideInit, slideReset, - slideTouchEnd, - slideTouchMove, - slideTouchStart + slideTouchUp, + slidePointerMove, + slidePointerDown } from '@/utils/slide' import { SlideType } from '@/utils/const_var' import SlideItem from '@/components/slide/SlideItem.vue' @@ -62,14 +62,15 @@ const appInsMap = new Map() const itemClassName = 'slide-item' const wrapperEl = ref(null) const state = reactive({ + judgeValue: 20, + type: SlideType.VERTICAL, name: props.name, localIndex: props.index, needCheck: true, next: false, start: { x: 0, y: 0, time: 0 }, move: { x: 0, y: 0 }, - wrapper: { width: 0, height: 0, childrenLength: 0 }, - isDown: false + wrapper: { width: 0, height: 0, childrenLength: 0 } }) const baseStore = useBaseStore() @@ -169,11 +170,7 @@ function insertContent(list = props.list) { let el = getInsEl(item, start + index, start + index === state.localIndex) wrapperEl.value.appendChild(el) }) - GM.$setCss( - wrapperEl.value, - 'transform', - `translate3d(0px,${getSlideDistance(state, SlideType.VERTICAL)}px, 0px)` - ) + GM.$setCss(wrapperEl.value, 'transform', `translate3d(0px,${getSlideOffset(state)}px, 0px)`) if (state.localIndex > 2 && list.length > 5) { $(wrapperEl.value) @@ -229,12 +226,12 @@ function getInsEl(item, index, play = false) { } function touchStart(e) { - slideTouchStart(e, wrapperEl.value, state) + slidePointerDown(e, wrapperEl.value, state) } //TODO 2022-3-28:在最顶部,反复滑动会抖动一下,初步猜测是因为方向变了,导致的加判断距离变成了减 function touchMove(e) { - slideTouchMove(e, wrapperEl.value, state, baseStore.judgeValue, canNext, null, SlideType.VERTICAL) + slidePointerMove(e, wrapperEl.value, state, canNext) } function touchEnd(e) { @@ -246,7 +243,7 @@ function touchEnd(e) { ) { emit('refresh') } - slideTouchEnd( + slideTouchUp( e, state, canNext, @@ -325,7 +322,7 @@ function touchEnd(e) { null, SlideType.VERTICAL ) - slideReset(wrapperEl.value, state, SlideType.VERTICAL, emit) + slideReset(wrapperEl.value, state, emit) } function canNext(isNext) { @@ -343,9 +340,9 @@ function canNext(isNext) { class="slide-list flex-direction-column" ref="wrapperEl" @click="null" - @pointerdown="touchStart" - @pointermove="touchMove" - @pointerup="touchEnd" + @touchstart="touchStart" + @touchmove="touchMove" + @touchend="touchEnd" >
diff --git a/src/pages/home/index.vue b/src/pages/home/index.vue index 6dfd362..43d0a8b 100644 --- a/src/pages/home/index.vue +++ b/src/pages/home/index.vue @@ -1,6 +1,6 @@