Skip to content

Commit 85c6c7d

Browse files
author
levy
committed
Merge branch 'dev'
2 parents 843c621 + 21fc802 commit 85c6c7d

2 files changed

Lines changed: 48 additions & 29 deletions

File tree

src/el-number-range.vue

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<template>
22
<div class="el-number-range">
3-
<el-input :style="{width}" type="number" v-model.number="minValue"/>
3+
<el-input
4+
:style="{width}"
5+
type="number"
6+
v-model.number="minValue"
7+
@blur="clampMin($event)"
8+
@focus="handleFocus($event, 'min')"
9+
/>
410
<span class="separator">{{ separator }}</span>
5-
<el-input :style="{width}" type="number" v-model.number="maxValue"/>
11+
<el-input
12+
:style="{width}"
13+
type="number"
14+
v-model.number="maxValue"
15+
@blur="clampMax($event)"
16+
@focus="handleFocus($event, 'max')"
17+
/>
618
</div>
719
</template>
820
<script>
@@ -52,12 +64,7 @@ export default {
5264
return this.value[0]
5365
},
5466
set(val) {
55-
if (this.isNum(val)) {
56-
val = this.clamp(val)
57-
if (this.isNum(this.maxValue)) val = Math.min(val, this.maxValue)
58-
} else {
59-
val = undefined
60-
}
67+
if (val === '') val = undefined
6168
this.$emit('input', [val, this.maxValue])
6269
}
6370
},
@@ -66,24 +73,32 @@ export default {
6673
return this.value[1]
6774
},
6875
set(val) {
69-
if (this.isNum(val)) {
70-
val = this.clamp(val)
71-
if (this.isNum(this.minValue)) val = Math.max(val, this.minValue)
72-
} else {
73-
val = undefined
74-
}
75-
/**
76-
* 配合v-model使用
77-
*/
76+
if (val === '') val = undefined
7877
this.$emit('input', [this.minValue, val])
7978
}
8079
}
8180
},
8281
methods: {
82+
clampMin(event) {
83+
this.$emit('blur', event, 'min')
84+
if (this.minValue === undefined) return
85+
let val = this.clamp(this.minValue)
86+
if (this.maxValue !== undefined) val = Math.min(val, this.maxValue)
87+
this.$emit('input', [val, this.maxValue])
88+
},
89+
clampMax(event) {
90+
this.$emit('blur', event, 'max')
91+
if (this.maxValue === undefined) return
92+
let val = this.clamp(this.maxValue)
93+
if (this.minValue !== undefined) val = Math.max(val, this.minValue)
94+
this.$emit('input', [this.minValue, val])
95+
},
96+
handleFocus(event, position) {
97+
this.$emit('focus', event, position)
98+
},
8399
clamp(val) {
84100
return Math.max(this.min, Math.min(this.max, val))
85-
},
86-
isNum: n => typeof n === 'number'
101+
}
87102
}
88103
}
89104
</script>

yarn.lock

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5871,9 +5871,10 @@ lodash._createset@~4.0.0:
58715871
version "4.0.3"
58725872
resolved "https://registry.npm.taobao.org/lodash._createset/download/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
58735873

5874-
lodash._reinterpolate@~3.0.0:
5874+
lodash._reinterpolate@^3.0.0:
58755875
version "3.0.0"
5876-
resolved "https://registry.npm.taobao.org/lodash._reinterpolate/download/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
5876+
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
5877+
integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=
58775878

58785879
lodash._root@~3.0.0:
58795880
version "3.0.1"
@@ -5897,17 +5898,19 @@ lodash.sortby@^4.7.0:
58975898
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
58985899

58995900
lodash.template@^4.0.2:
5900-
version "4.4.0"
5901-
resolved "https://registry.npm.taobao.org/lodash.template/download/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0"
5901+
version "4.5.0"
5902+
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab"
5903+
integrity sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A==
59025904
dependencies:
5903-
lodash._reinterpolate "~3.0.0"
5905+
lodash._reinterpolate "^3.0.0"
59045906
lodash.templatesettings "^4.0.0"
59055907

59065908
lodash.templatesettings@^4.0.0:
5907-
version "4.1.0"
5908-
resolved "https://registry.npm.taobao.org/lodash.templatesettings/download/lodash.templatesettings-4.1.0.tgz#2b4d4e95ba440d915ff08bc899e4553666713316"
5909+
version "4.2.0"
5910+
resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz#e481310f049d3cf6d47e912ad09313b154f0fb33"
5911+
integrity sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ==
59095912
dependencies:
5910-
lodash._reinterpolate "~3.0.0"
5913+
lodash._reinterpolate "^3.0.0"
59115914

59125915
lodash.union@~4.6.0:
59135916
version "4.6.0"
@@ -5922,8 +5925,9 @@ lodash.without@~4.4.0:
59225925
resolved "https://registry.npm.taobao.org/lodash.without/download/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac"
59235926

59245927
lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0:
5925-
version "4.17.11"
5926-
resolved "http://registry.npm.taobao.org/lodash/download/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
5928+
version "4.17.14"
5929+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
5930+
integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==
59275931

59285932
log-symbols@^2.1.0, log-symbols@^2.2.0:
59295933
version "2.2.0"

0 commit comments

Comments
 (0)