forked from opentiny/tiny-vue
fix(pull-refresh): fix pull up (#1235)
* fix(pull-refresh): 优化上拉加载更多触发逻辑 Signed-off-by: jacknan <zhumaonan@aliyun.com> * fix(pull-refresh): 常量定义 Signed-off-by: jacknan <zhumaonan@aliyun.com> --------- Signed-off-by: jacknan <zhumaonan@aliyun.com>
This commit is contained in:
parent
f466d63c23
commit
feec4137a3
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
import { on, off } from '../common/deps/dom'
|
import { on, off } from '../common/deps/dom'
|
||||||
|
|
||||||
|
// 上拉触发事件超时时间
|
||||||
|
const PULL_UP_TIME_OUT = 300
|
||||||
|
|
||||||
export const initPullRefresh =
|
export const initPullRefresh =
|
||||||
({ t, props, state }) =>
|
({ t, props, state }) =>
|
||||||
() => {
|
() => {
|
||||||
|
@ -37,19 +40,11 @@ export const onTouchstart = (state) => (event) => {
|
||||||
export const onTouchmove =
|
export const onTouchmove =
|
||||||
({ state, refs }) =>
|
({ state, refs }) =>
|
||||||
(event) => {
|
(event) => {
|
||||||
if (event.touches[0].clientY < state.draggposition) {
|
if (event.touches[0].clientY > state.draggposition) {
|
||||||
pullUpTouchMove(state)
|
|
||||||
} else {
|
|
||||||
pullDownTouchMove(state, refs, event)
|
pullDownTouchMove(state, refs, event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pullUpTouchMove = (state) => {
|
|
||||||
if (state.disabledPullUp || state.pullUpLoading || !state.hasMore) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const pullDownTouchMove = (state, refs, event) => {
|
export const pullDownTouchMove = (state, refs, event) => {
|
||||||
if (state.disabledPullDown || state.pullDownLoading) {
|
if (state.disabledPullDown || state.pullDownLoading) {
|
||||||
return
|
return
|
||||||
|
@ -92,7 +87,9 @@ export const pullDownTouchEnd = (api, state, emit) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pullUpTouchEnd = (state, emit, refs) => {
|
export const pullUpTouchEnd = (state, emit, refs) => {
|
||||||
setTimeout(() => {
|
clearTimeout(state.timer)
|
||||||
|
|
||||||
|
state.timer = setTimeout(() => {
|
||||||
const footNode = refs.foot
|
const footNode = refs.foot
|
||||||
|
|
||||||
if (!state.hasMore || !footNode) {
|
if (!state.hasMore || !footNode) {
|
||||||
|
@ -106,9 +103,15 @@ export const pullUpTouchEnd = (state, emit, refs) => {
|
||||||
emit('update:modelValue', true)
|
emit('update:modelValue', true)
|
||||||
emit('pullUp')
|
emit('pullUp')
|
||||||
}
|
}
|
||||||
}, 300)
|
}, PULL_UP_TIME_OUT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const onScroll =
|
||||||
|
({ state, emit, refs }) =>
|
||||||
|
() => {
|
||||||
|
pullUpTouchEnd(state, emit, refs)
|
||||||
|
}
|
||||||
|
|
||||||
export const mountedHandler =
|
export const mountedHandler =
|
||||||
({ api, refs }) =>
|
({ api, refs }) =>
|
||||||
() => {
|
() => {
|
||||||
|
@ -117,6 +120,7 @@ export const mountedHandler =
|
||||||
on(track, 'touchstart', api.onTouchstart)
|
on(track, 'touchstart', api.onTouchstart)
|
||||||
on(track, 'touchmove', api.onTouchmove)
|
on(track, 'touchmove', api.onTouchmove)
|
||||||
on(track, 'touchend', api.onTouchend)
|
on(track, 'touchend', api.onTouchend)
|
||||||
|
on(track, 'scroll', api.onScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const beforeUnmountHandler =
|
export const beforeUnmountHandler =
|
||||||
|
@ -127,6 +131,7 @@ export const beforeUnmountHandler =
|
||||||
off(track, 'touchstart', api.onTouchstart)
|
off(track, 'touchstart', api.onTouchstart)
|
||||||
off(track, 'touchmove', api.onTouchmove)
|
off(track, 'touchmove', api.onTouchmove)
|
||||||
off(track, 'touchend', api.onTouchend)
|
off(track, 'touchend', api.onTouchend)
|
||||||
|
off(track, 'scroll', api.onScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handlerModelValue =
|
export const handlerModelValue =
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
onTouchstart,
|
onTouchstart,
|
||||||
onTouchmove,
|
onTouchmove,
|
||||||
onTouchend,
|
onTouchend,
|
||||||
|
onScroll,
|
||||||
initPullRefresh,
|
initPullRefresh,
|
||||||
clearPullRefresh
|
clearPullRefresh
|
||||||
} from './index'
|
} from './index'
|
||||||
|
@ -45,7 +46,8 @@ export const renderless = (props, { watch, onMounted, reactive, onBeforeUnmount
|
||||||
animationDuration: props.animationDuration,
|
animationDuration: props.animationDuration,
|
||||||
disabledPullDown: props.disabledPullDown,
|
disabledPullDown: props.disabledPullDown,
|
||||||
disabledPullUp: props.disabledPullUp,
|
disabledPullUp: props.disabledPullUp,
|
||||||
pullUpDistance: typeof props.pullUpDistance === 'string' ? Number(props.pullUpDistance) : props.pullUpDistance
|
pullUpDistance: typeof props.pullUpDistance === 'string' ? Number(props.pullUpDistance) : props.pullUpDistance,
|
||||||
|
timer: null
|
||||||
})
|
})
|
||||||
|
|
||||||
Object.assign(api, {
|
Object.assign(api, {
|
||||||
|
@ -53,6 +55,7 @@ export const renderless = (props, { watch, onMounted, reactive, onBeforeUnmount
|
||||||
onTouchstart: onTouchstart(state),
|
onTouchstart: onTouchstart(state),
|
||||||
onTouchmove: onTouchmove({ state, refs }),
|
onTouchmove: onTouchmove({ state, refs }),
|
||||||
onTouchend: onTouchend({ api, props, state, emit, refs }),
|
onTouchend: onTouchend({ api, props, state, emit, refs }),
|
||||||
|
onScroll: onScroll({ state, emit, refs }),
|
||||||
mountedHandler: mountedHandler({ api, refs }),
|
mountedHandler: mountedHandler({ api, refs }),
|
||||||
beforeUnmountHandler: beforeUnmountHandler({ api, refs }),
|
beforeUnmountHandler: beforeUnmountHandler({ api, refs }),
|
||||||
handlerModelValue: handlerModelValue({ api, state }),
|
handlerModelValue: handlerModelValue({ api, state }),
|
||||||
|
|
Loading…
Reference in New Issue