From 16213c0f85aa3ac8317797bf4a05fd12940e16d3 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期三, 05 三月 2025 17:29:42 +0800
Subject: [PATCH] -

---
 src/uni_modules/uview-plus/components/u-slider/u-slider.vue |   65 +++++++++++++++++++++-----------
 1 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/src/uni_modules/uview-plus/components/u-slider/u-slider.vue b/src/uni_modules/uview-plus/components/u-slider/u-slider.vue
index dbc1e01..dbba2c4 100644
--- a/src/uni_modules/uview-plus/components/u-slider/u-slider.vue
+++ b/src/uni_modules/uview-plus/components/u-slider/u-slider.vue
@@ -58,7 +58,7 @@
 					<view class="u-slider__button-wrap u-slider__button-wrap-0" @touchstart="onTouchStart($event, 0)"
 						@touchmove="onTouchMove($event, 0)" @touchend="onTouchEnd($event, 0)"
 						@touchcancel="onTouchEnd($event, 0)" :style="{left: (getPx(barStyle0.width) + getPx(blockSize)/2) + 'px'}">
-						<slot v-if="$slots.default  || $slots.$default"/>
+						<slot name="min" v-if="$slots.min || $slots.$min"/>
 						<view v-else class="u-slider__button" :style="[blockStyle, {
 							height: getPx(blockSize, true),
 							width: getPx(blockSize, true),
@@ -69,7 +69,8 @@
 				<view class="u-slider__button-wrap" @touchstart="onTouchStart"
 					@touchmove="onTouchMove" @touchend="onTouchEnd"
 					@touchcancel="onTouchEnd" :style="{left: (getPx(barStyle.width) + getPx(blockSize)/2) + 'px'}">
-					<slot v-if="$slots.default  || $slots.$default"/>
+					<slot name="max" v-if="isRange && ($slots.max || $slots.$max)"/>
+					<slot v-else-if="$slots.default || $slots.$default"/>
 					<view v-else class="u-slider__button" :style="[blockStyle, {
 						height: getPx(blockSize, true),
 						width: getPx(blockSize, true),
@@ -155,8 +156,17 @@
 			value(n) {
 				// 鍙湁鍦ㄩ潪婊戝姩鐘舵�佹椂锛屾墠鍙互閫氳繃value鏇存柊婊戝潡鍊硷紝杩欓噷鐩戝惉锛屾槸涓轰簡璁╃敤鎴疯Е鍙�
 				if(this.status == 'end') this.updateValue(this.value, false);
-			}
+			},
 			// #endif
+			rangeValue:{
+            	handler(n){
+					if(this.status == 'end'){
+						this.updateValue(this.rangeValue[0], false, 0);
+						this.updateValue(this.rangeValue[1], false, 1);
+					}
+            	},
+            	deep:true
+        	}
 		},
 		created() {
 		},
@@ -166,6 +176,10 @@
 				// #ifndef APP-NVUE
 				this.$uGetRect('.u-slider__base').then(rect => {
 					this.sliderRect = rect;
+					// console.log('sliderRect', this.sliderRect)
+					if (this.sliderRect.width == 0) {
+						console.info('濡傚湪寮圭獥绛夊厓绱犱腑浣跨敤锛岃浣跨敤v-if鏉ユ樉绀烘粦鍧楋紝鍚﹀垯鏃犳硶璁$畻闀垮害銆�')
+					}
 					this.init()
 				});
 				// #endif
@@ -265,8 +279,8 @@
 				this.newValue = ((this.distanceX / this.sliderRect.width) * (this.max - this.min)) + parseFloat(this.min);
 				this.status = 'moving';
 				// 鍙戝嚭moving浜嬩欢
-				this.$emit('changing');
-				this.updateValue(this.newValue, true, index);
+				let $crtFmtValue = this.updateValue(this.newValue, true, index);
+				this.$emit('changing', $crtFmtValue);
 			},
 			onTouchMove(event, index = 1) {
 				if (this.disabled) return;
@@ -274,7 +288,7 @@
 				// 瑙︽懜鍚庣涓�娆$Щ鍔ㄥ凡缁忓皢status璁剧疆涓簃oving鐘舵�侊紝鏁呰Е鎽哥浜屾绉诲姩涓嶄細瑙﹀彂鏈簨浠�
 				if (this.status == 'start') this.$emit('start');
 				let touches = event.touches[0];
-				console.log('touchs', touches)
+				// console.log('touchs', touches)
 				// 婊戝潡鐨勫乏杈逛笉涓�瀹氳窡灞忓箷宸﹁竟鎺ュ¥锛屾墍浠ラ渶瑕佸噺鍘绘渶澶栧眰鐖跺厓绱犵殑宸﹁竟鍊�
 				let clientX = 0;
 				// #ifndef APP-NVUE
@@ -289,33 +303,34 @@
 				this.newValue = ((this.distanceX / this.sliderRect.width) * (this.max - this.min)) + parseFloat(this.min);
 				this.status = 'moving';
 				// 鍙戝嚭moving浜嬩欢
-				this.$emit('changing');
-				this.updateValue(this.newValue, true, index);
+				let $crtFmtValue = this.updateValue(this.newValue, true, index);
+				this.$emit('changing', $crtFmtValue);
 			},
 			onTouchEnd(event, index = 1) {
 				if (this.disabled) return;
 				if (this.status === 'moving') {
-					this.updateValue(this.newValue, false, index);
-					this.$emit('change');
+					let $crtFmtValue = this.updateValue(this.newValue, false, index);
+					this.$emit('change', $crtFmtValue);
 				}
 				this.status = 'end';
 			},
 			onTouchStart2(event, index = 1) {
 				if (!this.isRange) {
-					this.onChangeStart(event, index);
+					// this.onChangeStart(event, index);
 				}
 			},
 			onTouchMove2(event, index = 1) {
 				if (!this.isRange) {
-					this.onTouchMove(event, index);
+					// this.onTouchMove(event, index);
 				}
 			},
 			onTouchEnd2(event, index = 1) {
 				if (!this.isRange) {
-					this.onTouchEnd(event, index);
+					// this.onTouchEnd(event, index);
 				}
 			},
 			onClick(event) {
+				// if (this.isRange) return;
 				if (this.disabled) return;
 				// 鐩存帴鐐瑰嚮婊戝潡鐨勬儏鍐碉紝璁$畻鏂瑰紡涓巓nTouchMove鏂规硶鐩稿悓
 				// console.log('click', event)
@@ -368,7 +383,11 @@
 					default:
 						break;
 				}
-				
+				if (this.isRange) {
+					return this.rangeValue
+				} else {
+					return valueFormat
+				}
 			},
 			format(value, index = 1) {
 				// 灏嗗皬鏁板彉鎴愭暣鏁帮紝涓轰簡鍑忓皯瀵硅鍥剧殑鏇存柊锛岄�犳垚瑙嗗浘灞備笌閫昏緫灞傜殑闃诲
@@ -376,15 +395,15 @@
 					switch (index) {
 						case 0:
 							return Math.round(
-								Math.max(this.min, Math.min(value, this.rangeValue[1] - this.step,this.max))
-								/ this.step
-							) * this.step;
+								Math.max(this.min, Math.min(value, this.rangeValue[1] - parseInt(this.step),this.max))
+								/ parseInt(this.step)
+							) * parseInt(this.step);
 							break;
 						case 1:
 							return Math.round(
-								Math.max(this.min, this.rangeValue[0] + this.step, Math.min(value, this.max))
-								/ this.step
-							) * this.step;
+								Math.max(this.min, this.rangeValue[0] + parseInt(this.step), Math.min(value, this.max))
+								/ parseInt(this.step)
+							) * parseInt(this.step);
 							break;
 						default:
 							break;
@@ -392,8 +411,8 @@
 				} else {
 					return Math.round(
 						Math.max(this.min, Math.min(value, this.max))
-						/ this.step
-					) * this.step;
+						/ parseInt(this.step)
+					) * parseInt(this.step);
 				}
 			}
 		}
@@ -414,6 +433,8 @@
 
 		&-inner {
 			flex: 1;
+			display: flex;
+			flex-direction: column;
 			position: relative;
 			border-radius: 999px;
 			padding: 10px 18px;

--
Gitblit v1.9.1