【fix】修复滑动选择器在嵌套弹出层计算的bug

This commit is contained in:
zhengliming
2024-02-21 01:13:11 +08:00
parent 557dbb313f
commit ca5e8c9429

View File

@@ -157,7 +157,9 @@
if (this.status === 'start') this.$emit('start') if (this.status === 'start') this.$emit('start')
let movePageX = event.changedTouches[0].pageX let movePageX = event.changedTouches[0].pageX
// 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值 // 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
this.distanceX = movePageX - this.sliderRect.left let marginLeft = this.sliderRect.left;
marginLeft = marginLeft < 0 ? 0 : marginLeft;
this.distanceX = movePageX - marginLeft;
// 获得移动距离对整个滑块的百分比值,此为带有多位小数的值,不能用此更新视图 // 获得移动距离对整个滑块的百分比值,此为带有多位小数的值,不能用此更新视图
// 否则造成通信阻塞需要每改变一个step值时修改一次视图 // 否则造成通信阻塞需要每改变一个step值时修改一次视图
this.newValue = ((this.distanceX / this.sliderRect.width) * (this.max - this.min)) + this.min this.newValue = ((this.distanceX / this.sliderRect.width) * (this.max - this.min)) + this.min
@@ -168,6 +170,7 @@
}, },
// 滑动结束 // 滑动结束
touchEnd() { touchEnd() {
console.log("结束。。。");
if(this.disabled) return if(this.disabled) return
if (this.status === 'moving') { if (this.status === 'moving') {
this.updateValue(this.newValue, false) this.updateValue(this.newValue, false)
@@ -200,6 +203,7 @@
}, },
// 点击事件 // 点击事件
click(event) { click(event) {
console.log("开始点击");
if (this.disabled) return if (this.disabled) return
// 直接点击的情况计算方式和touchMove方法一致 // 直接点击的情况计算方式和touchMove方法一致
const value = (((event.detail.x - this.sliderRect.left) / this.sliderRect.width) * (this.max - this.min)) + this.min const value = (((event.detail.x - this.sliderRect.left) / this.sliderRect.width) * (this.max - this.min)) + this.min