From b26c02f9f1be4bf7e5c6fbb64ba3a2a13428c78f Mon Sep 17 00:00:00 2001 From: chensiAb <chenchenco03@163.com> Date: Wed, 17 Apr 2024 15:37:16 +0800 Subject: [PATCH] fix:'删除小程序echarts文件,使用封装过得组件' --- forms/numberValve/CNumberValve.vue | 64 +++++++++++++++++++++++++------ 1 files changed, 51 insertions(+), 13 deletions(-) diff --git a/forms/numberValve/CNumberValve.vue b/forms/numberValve/CNumberValve.vue index 394d8c4..f642855 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="valueStr" + :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()" > @@ -46,7 +49,16 @@ @touchstart="evt => handleTouchStart()" @touchmove="evt => handleTouchMove(evt)" ></view> - <view class="current"><text class="text">{{current}}</text></view> + <view class="current"> + <text + class="text m-text-ignore" + v-if="current===''" + >(请拖动)</text> + <text + class="text" + v-else + >{{current}}</text> + </view> </view> </view> <view class="btn"> @@ -93,16 +105,32 @@ type: Number, default: 1, }, + // 数值单位(仅显示) + unit: { + type: String, + default: '', + }, }, data() { return { opened: false, rect: { width: 0, left: 0 }, - current: 0, + current: '', sliderLeft: 0, }; }, - computed: {}, + computed: { + valueStr() { + if ( + this.itemRes.formData[this.itemRes.name] || + this.itemRes.formData[this.itemRes.name] === 0 + ) { + return this.itemRes.formData[this.itemRes.name] + ' ' + this.unit; + } else { + return ''; + } + }, + }, methods: { handleOpen() { this.opened = true; @@ -125,9 +153,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 +172,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