slider组件增加并发限制逻辑, 并移入表单组

master
yutent 2023-11-24 11:52:07 +08:00
parent a3f4b72ebd
commit 1f227a9d9d
2 changed files with 14 additions and 3 deletions

View File

@ -9,3 +9,4 @@ import './select.js'
import './star.js' import './star.js'
import './switch.js' import './switch.js'
import './textarea.js' import './textarea.js'
import './slider.js'

View File

@ -38,8 +38,8 @@ class Slider extends Component {
} }
}, },
vertical: false, vertical: false,
range: false, disabled: false,
disabled: false lazy: 'num!0'
} }
#len = 100 #len = 100
@ -48,6 +48,8 @@ class Slider extends Component {
#value = 0 // 内部的值, 固定使用 0-100范围的值 #value = 0 // 内部的值, 固定使用 0-100范围的值
#decimal = 0 //小数位 #decimal = 0 //小数位
#stamp = 0
static styles = [ static styles = [
css` css`
:host { :host {
@ -241,8 +243,9 @@ class Slider extends Component {
#seek(ev) { #seek(ev) {
let { clientWidth: w, clientHeight: h } = ev.target let { clientWidth: w, clientHeight: h } = ev.target
let { min, max, step } = this let { min, max, step, lazy } = this
let val = 0 let val = 0
let now = Date.now()
if (this.vertical) { if (this.vertical) {
val = (h - ev.y) / h val = (h - ev.y) / h
@ -253,7 +256,14 @@ class Slider extends Component {
val += min val += min
this.value = this.#fix(val) this.value = this.#fix(val)
// 并发拦截
if (lazy > 0 && now - this.#stamp < lazy) {
return
}
this.#stamp = now
this.$emit('input') this.$emit('input')
this.$emit('change')
} }
#mousedown(ev) { #mousedown(ev) {