From 64b432916af9c9218ab3f3eca614e26c542142ae Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 07 十一月 2023 15:47:13 +0800
Subject: [PATCH] bug
---
minipro_standard/uni_modules/uview-ui/components/u-slider/mpwxs.wxs | 121 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/minipro_standard/uni_modules/uview-ui/components/u-slider/mpwxs.wxs b/minipro_standard/uni_modules/uview-ui/components/u-slider/mpwxs.wxs
new file mode 100644
index 0000000..847df4a
--- /dev/null
+++ b/minipro_standard/uni_modules/uview-ui/components/u-slider/mpwxs.wxs
@@ -0,0 +1,121 @@
+/**
+ * 浣跨敤wxs鏂规瀹炵幇slider
+ * 鍏煎寰俊锛孮Q锛孒5锛孷ue鐗堢殑瀹夊崜鍜宨OS
+ */
+/**
+ * 寮�濮嬫粦鍔ㄦ搷浣�
+ * @param {Object} e
+ * @param {Object} ownerInstance
+ */
+function onTouchMove(e, ownerInstance) {
+ // wxs浜嬩欢瀵硅薄涓嬫湁涓�涓猧nstance灞炴�э紝琛ㄧず褰撳墠瑙﹀彂姝や簨浠剁殑缁勪欢鐨勫疄渚嬶紝閫氳繃璇ュ疄渚嬶紝鍙互鑾峰彇鐩稿叧鐨刣ataset锛岃缃牱寮忕瓑淇℃伅
+ // https://developers.weixin.qq.com/miniprogram/dev/framework/view/interactive-animation.html
+ var instance = e.instance;
+ // getState()涓轰竴涓璞★紝鎸傝浇鍦╥nstance涓婏紝绫讳技缁勪欢鐨刣ata涓�鏍凤紝鍙互瀛樻斁涓�浜涘彉閲忥紝渚涗互鍚庣殑瑙﹀彂浜嬩欢涓娇鐢�
+ 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
+ }
+
+ // 鐩存帴鐐瑰嚮婊戝潡鐨勬儏鍐碉紝璁$畻鏂瑰紡涓巓nTouchMove鏂规硶鐩稿悓
+ 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锛岄渶瑕佽烦姝ワ紝鎵�浠ラ渶瑕佷娇鐢∕ath.round杩涜鍙栨暣
+ percent = Math.round(Math.max(mp.min, Math.min(value, mp.max)) / mp.step) * mp.step
+ } else {
+ // 褰搒tep=1鏃讹紝鏃犻渶璺虫锛屽厖鍒嗗埄鐢╳xs鎬ц兘锛屾粦鍧楀疄鏃惰窡闅忔墜鍔匡紝杈惧埌涓濇粦鐨勬晥鏋�
+ percent = Math.max(mp.min, Math.min(value, mp.max))
+ }
+ // 杩斿洖缁勪欢鐨勫疄渚�
+ var gapInstance = ownerInstance.selectComponent('.u-slider__gap')
+ // 鍦ㄧЩ鍔ㄦ湡闂达紝涓嶅厑璁竧ransition鍔ㄧ敾锛屽惁鍒欎細閫犳垚鍗¢】
+ gapInstance[event === 'click' ? 'addClass' : 'removeClass']('u-slider__gap--ani')
+ // 璋冪敤閫昏緫灞傜殑鏂规硶锛屼慨鏀箆-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.9.3