mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 02:16:12 +08:00
fix(PullRefresh): failed to trigger pull refresh when scrolling
This commit is contained in:
parent
43b59ad7ef
commit
e00058b681
@ -43,8 +43,10 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
untouchable() {
|
touchable() {
|
||||||
return this.status === 'loading' || this.status === 'success' || this.disabled;
|
return (
|
||||||
|
this.status !== 'loading' && this.status !== 'success' && !this.disabled
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -54,6 +56,7 @@ export default createComponent({
|
|||||||
|
|
||||||
if (!loading && this.successText) {
|
if (!loading && this.successText) {
|
||||||
this.status = 'success';
|
this.status = 'success';
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.setStatus(0);
|
this.setStatus(0);
|
||||||
}, this.successDuration);
|
}, this.successDuration);
|
||||||
@ -69,36 +72,40 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onTouchStart(event) {
|
checkPullStart(event) {
|
||||||
if (!this.untouchable && this.getCeiling()) {
|
this.ceiling = getScrollTop(this.scrollEl) === 0;
|
||||||
|
|
||||||
|
if (this.ceiling) {
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onTouchStart(event) {
|
||||||
|
if (this.touchable) {
|
||||||
|
this.checkPullStart(event);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onTouchMove(event) {
|
onTouchMove(event) {
|
||||||
if (this.untouchable) {
|
if (!this.touchable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.ceiling) {
|
||||||
|
this.checkPullStart(event);
|
||||||
|
}
|
||||||
|
|
||||||
this.touchMove(event);
|
this.touchMove(event);
|
||||||
|
|
||||||
if (!this.ceiling && this.getCeiling()) {
|
if (this.ceiling && this.deltaY >= 0 && this.direction === 'vertical') {
|
||||||
this.duration = 0;
|
|
||||||
this.startY = event.touches[0].clientY;
|
|
||||||
this.deltaY = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.ceiling && this.deltaY >= 0) {
|
|
||||||
if (this.direction === 'vertical') {
|
|
||||||
this.setStatus(this.ease(this.deltaY));
|
|
||||||
preventDefault(event);
|
preventDefault(event);
|
||||||
}
|
this.setStatus(this.ease(this.deltaY));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onTouchEnd() {
|
onTouchEnd() {
|
||||||
if (!this.untouchable && this.ceiling && this.deltaY) {
|
if (this.touchable && this.ceiling && this.deltaY) {
|
||||||
this.duration = this.animationDuration;
|
this.duration = this.animationDuration;
|
||||||
|
|
||||||
if (this.status === 'loosing') {
|
if (this.status === 'loosing') {
|
||||||
@ -115,56 +122,70 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getCeiling() {
|
|
||||||
this.ceiling = getScrollTop(this.scrollEl) === 0;
|
|
||||||
return this.ceiling;
|
|
||||||
},
|
|
||||||
|
|
||||||
ease(distance) {
|
ease(distance) {
|
||||||
const { headHeight } = this;
|
const { headHeight } = this;
|
||||||
return Math.round(
|
|
||||||
distance < headHeight
|
if (distance > headHeight) {
|
||||||
? distance
|
if (distance < headHeight * 2) {
|
||||||
: distance < headHeight * 2
|
distance = headHeight + (distance - headHeight) / 2;
|
||||||
? headHeight + (distance - headHeight) / 2
|
} else {
|
||||||
: headHeight * 1.5 + (distance - headHeight * 2) / 4
|
distance = headHeight * 1.5 + (distance - headHeight * 2) / 4;
|
||||||
);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.round(distance);
|
||||||
},
|
},
|
||||||
|
|
||||||
setStatus(distance, isLoading) {
|
setStatus(distance, isLoading) {
|
||||||
this.distance = distance;
|
let status;
|
||||||
|
if (isLoading) {
|
||||||
|
status = 'loading';
|
||||||
|
} else if (distance === 0) {
|
||||||
|
status = 'normal';
|
||||||
|
} else {
|
||||||
|
status = distance < this.headHeight ? 'pulling' : 'loosing';
|
||||||
|
}
|
||||||
|
|
||||||
const status = isLoading
|
this.distance = distance;
|
||||||
? 'loading'
|
|
||||||
: distance === 0
|
|
||||||
? 'normal'
|
|
||||||
: distance < this.headHeight
|
|
||||||
? 'pulling'
|
|
||||||
: 'loosing';
|
|
||||||
|
|
||||||
if (status !== this.status) {
|
if (status !== this.status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
genStatus() {
|
||||||
|
const { status, distance } = this;
|
||||||
|
const slot = this.slots(status, { distance });
|
||||||
|
|
||||||
|
if (slot) {
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodes = [];
|
||||||
|
const text = this[`${status}Text`] || t(status);
|
||||||
|
|
||||||
|
if (TEXT_STATUS.indexOf(status) !== -1) {
|
||||||
|
nodes.push(<div class={bem('text')}>{text}</div>);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === 'loading') {
|
||||||
|
nodes.push(<Loading size="16">{text}</Loading>);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { status, distance } = this;
|
|
||||||
const text = this[`${status}Text`] || t(status);
|
|
||||||
const style = {
|
const style = {
|
||||||
transitionDuration: `${this.duration}ms`,
|
transitionDuration: `${this.duration}ms`,
|
||||||
transform: this.distance ? `translate3d(0,${this.distance}px, 0)` : ''
|
transform: this.distance ? `translate3d(0,${this.distance}px, 0)` : ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const Status = this.slots(status, { distance }) || [
|
|
||||||
TEXT_STATUS.indexOf(status) !== -1 && <div class={bem('text')}>{text}</div>,
|
|
||||||
status === 'loading' && <Loading size="16">{text}</Loading>
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={bem()}>
|
<div class={bem()}>
|
||||||
<div ref="track" class={bem('track')} style={style}>
|
<div ref="track" class={bem('track')} style={style}>
|
||||||
<div class={bem('head')}>{Status}</div>
|
<div class={bem('head')}>{this.genStatus()}</div>
|
||||||
{this.slots()}
|
{this.slots()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user