From da25434b85fc5b4321c429bf95e719d00ec395bb Mon Sep 17 00:00:00 2001
From: quanyawei <401863037@qq.com>
Date: Thu, 11 Jan 2024 16:21:16 +0800
Subject: [PATCH] 定位优化

---
 uni_modules/uview-ui/components/u-slider/mpwxs.wxs |  121 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/uni_modules/uview-ui/components/u-slider/mpwxs.wxs b/uni_modules/uview-ui/components/u-slider/mpwxs.wxs
new file mode 100644
index 0000000..847df4a
--- /dev/null
+++ b/uni_modules/uview-ui/components/u-slider/mpwxs.wxs
@@ -0,0 +1,121 @@
+/**
+ * ������wxs������������slider
+ * ���������������QQ���H5���Vue���������������iOS
+ */
+/**
+ * ������������������
+ * @param {Object} e
+ * @param {Object} ownerInstance
+ */
+function onTouchMove(e, ownerInstance) {
+	// wxs������������������������instance������������������������������������������������������������������������������������������������dataset������������������������
+	// https://developers.weixin.qq.com/miniprogram/dev/framework/view/interactive-animation.html
+	var instance = e.instance;
+	// getState()���������������������������instance���������������������data���������������������������������������������������������������������
+	var state = instance.getState()
+
+	// ���������������������������������
+	var mp = state.mp
+	if(mp.disabled) {
+		return
+	}
+	
+	var distanceX = getTouchX(e) - mp.left
+	// ������������������������������������������������������������������������������������step������1������������������������������
+	var percent = (distanceX / mp.width) * 100
+
+	updateSliderPlacement(instance, ownerInstance, percent, 'moving')
+	
+	// ������������������������������������������������������������������������������������������������������������
+	e.stopPropagation && e.stopPropagation() 
+	e.preventDefault && e.preventDefault()
+}
+
+function onClick(e, ownerInstance) {
+	var instance = e.instance
+	var state = instance.getState()
+	var mp = state.mp
+	if(mp.disabled) {
+		return
+	}
+	
+	// ���������������������������������������������onTouchMove������������
+	var value = ((e.detail.x - mp.left) / mp.width) * 100
+	updateSliderPlacement(instance, ownerInstance, value, 'click')
+}
+
+function sizeReady(newValue, oldValue, ownerInstance, instance) {
+	// ���������������������������������������������������������������������������������������������������
+	if(!newValue || newValue.disabled) {
+		return 
+	}
+	var state = instance.getState()
+	state.mp = newValue
+	updateSliderPlacement(instance, ownerInstance, newValue.value)
+}
+
+// ���������������������
+function updateSliderPlacement(instance, ownerInstance, value, event) {
+	var state = instance.getState()
+	var mp = state.mp
+	if(mp.disabled) {
+		return
+	}
+
+	var percent = 0
+	if (mp.step > 1) {
+		// ������step������������1������������������������������������Math.round������������
+		percent = Math.round(Math.max(mp.min, Math.min(value, mp.max)) / mp.step) * mp.step
+	} else {
+		// ���step=1���������������������������������wxs���������������������������������������������������������
+		percent = Math.max(mp.min, Math.min(value, mp.max))
+	}
+	// ���������������������
+	var gapInstance = ownerInstance.selectComponent('.u-slider__gap')
+	// ���������������������������transition������������������������������
+	gapInstance[event === 'click' ? 'addClass' : 'removeClass']('u-slider__gap--ani')
+	// ���������������������������������v-model������������
+	ownerInstance.callMethod('updateValue', Math.round(percent))
+	if(event) {
+		ownerInstance.callMethod('emitEvent', {
+			event: event,
+			value: Math.round(percent)
+		})
+	}
+	
+	// ������������������
+	gapInstance.requestAnimationFrame(function() {
+		gapInstance.setStyle({
+			width: percent / 100 * mp.width + 'px',
+		})
+	})
+}
+
+// ������������
+function onTouchStart(e, ownerInstance) {
+	ownerInstance.callMethod('emitEvent', {
+		event: 'start', 
+		value: null
+	})
+}
+
+// ������������
+function onTouchEnd(e, ownerInstance) {
+	ownerInstance.callMethod('emitEvent', {
+		event: 'end', 
+		value: null
+	})
+}
+
+// ������������������������X������������
+function getTouchX(e) {
+	return e.touches[0].clientX
+}
+
+module.exports = {
+	onTouchStart: onTouchStart,
+	onTouchMove: onTouchMove,
+	onTouchEnd: onTouchEnd,
+	sizeReady: sizeReady,
+	onClick: onClick
+}

--
Gitblit v1.8.0