76 lines
1.4 KiB
JavaScript
76 lines
1.4 KiB
JavaScript
![]() |
Component({
|
||
|
properties: {
|
||
|
show: {
|
||
|
type: Boolean,
|
||
|
value: false,
|
||
|
observer: 'onShowChange'
|
||
|
}
|
||
|
},
|
||
|
|
||
|
data: {
|
||
|
visible: false,
|
||
|
startY: 0,
|
||
|
currentY: 0,
|
||
|
swipeToClose: false,
|
||
|
animate: false
|
||
|
},
|
||
|
|
||
|
methods: {
|
||
|
onShowChange(newVal) {
|
||
|
if (newVal) {
|
||
|
this.setData({
|
||
|
visible: true
|
||
|
}, () => {
|
||
|
wx.nextTick(() => {
|
||
|
this.setData({
|
||
|
animate: true
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
} else {
|
||
|
this.setData({
|
||
|
animate: false
|
||
|
}, () => {
|
||
|
setTimeout(() => {
|
||
|
this.setData({
|
||
|
visible: false
|
||
|
});
|
||
|
}, 300);
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
handleCancel() {
|
||
|
this.triggerEvent('cancel');
|
||
|
},
|
||
|
handleConfirm() {
|
||
|
this.triggerEvent('confirm');
|
||
|
},
|
||
|
handleOverlayTap() {
|
||
|
this.triggerEvent('cancel');
|
||
|
},
|
||
|
handleTouchStart(e) {
|
||
|
this.setData({
|
||
|
startY: e.touches[0].clientY
|
||
|
});
|
||
|
},
|
||
|
handleTouchMove(e) {
|
||
|
e.stopPropagation();
|
||
|
//阻止默认行为(如滚动)
|
||
|
e.preventDefault();
|
||
|
const currentY = e.touches[0].clientY;
|
||
|
if (currentY - this.data.startY > 50) {
|
||
|
this.setData({
|
||
|
swipeToClose: true
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
handleTouchEnd() {
|
||
|
if (this.data.swipeToClose) {
|
||
|
this.triggerEvent('cancel');
|
||
|
this.setData({
|
||
|
swipeToClose: false
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|