From 7cb91d0efcbff3297de5d8f64948033d13a86142 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Tue, 12 Apr 2022 17:58:03 +0800 Subject: [PATCH] 公共方法,增加网络检测 --- forms/numberValve/CNumberValve.vue | 38 ++++++++++++++++++++++++++++---------- 1 files changed, 28 insertions(+), 10 deletions(-) diff --git a/forms/numberValve/CNumberValve.vue b/forms/numberValve/CNumberValve.vue index 394d8c4..342beb5 100644 --- a/forms/numberValve/CNumberValve.vue +++ b/forms/numberValve/CNumberValve.vue @@ -16,12 +16,15 @@ :required="itemRes.required" :disabled="itemRes.disabled" :error="itemRes.error" - :value="itemRes.formData[itemRes.name]" + :value="itemRes.formData[itemRes.name] + unit" + :placeholder="placeholder" > <view class="at-icon at-icon-chevron-right"></view> </AtInput> </view> <AtFloatLayout + :class="placeholder?'on-title':''" + :title="placeholder" :isOpened="opened" :onClose="evt => handleClose()" > @@ -93,6 +96,11 @@ type: Number, default: 1, }, + // 数值单位(仅显示) + unit: { + type: String, + default: '', + }, }, data() { return { @@ -125,9 +133,17 @@ const targetValue = clientX - this.rect.left; const distance = Math.min(Math.max(targetValue, 0), this.rect.width); const sliderLeft = Math.floor((distance / this.rect.width) * 100); - const sliderValue = + // 实际值 + let sliderValue = Math.round((sliderLeft / 100) * (this.range[1] - this.range[0])) + this.range[0]; + if (this.range[0] < sliderValue && sliderValue < this.range[1]) { + sliderValue -= sliderValue % this.step; + } + // 范围限制 + sliderValue = Math.max(sliderValue, this.range[0]); + sliderValue = Math.min(sliderValue, this.range[1]); + // 设置 this.sliderLeft = sliderLeft; this.current = sliderValue; this.itemRes.onChange(sliderValue); @@ -136,16 +152,18 @@ let $slider = null; if (process.env.TARO_ENV === 'h5') { $slider = $(this.$refs.slider.$el); + const rect = $slider[0].getBoundingClientRect(); + this.rect.width = rect.width; + this.rect.left = rect.left; } else if (process.env.TARO_ENV === 'weapp') { - $slider = $(this.$refs.slider); + Taro.createSelectorQuery() + .select('#' + this.$refs.slider.uid) + .boundingClientRect(rect => { + this.rect.width = rect.width; + this.rect.left = rect.left; + }) + .exec(); } - Taro.createSelectorQuery() - .select('#' + this.$refs.slider.uid) - .boundingClientRect(rect => { - this.rect.width = rect.width; - this.rect.left = rect.left; - }) - .exec(); }, handleChangeVal(type, value) { this.updateRect(); -- Gitblit v1.9.1