Skip to content

Commit

Permalink
fix: stepper允许直接输入(不完善)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadais-lwt committed Mar 8, 2021
1 parent c963cd4 commit 024d776
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions components/pi-stepper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@tap="handleChange(-1)"
/>
<input
:value="val"
:value="value"
type="digit"
class="step-input"
:disabled="disabled || disableInput"
Expand Down Expand Up @@ -133,7 +133,7 @@ export default {
},
// 形状
shape: {
// round || square
// round, square
type: String,
// round
default: stepper.shape,
Expand Down Expand Up @@ -236,13 +236,25 @@ export default {
this.handleEmitChange()
},
handleInputChange(e) {
setTimeout(() => {
const val = e.detail.value
if (!this.$pi.validate.isNumerical(val)) {
this.val = val.replace(/[^0-9]/gi, '')
} else {
this.val = val
const val = e.detail.value
if (!this.$pi.validate.isNumerical(val)) {
this.val = val.replace(/[^0-9]/gi, '')
} else {
let reg = /^(\d+)(?:\.(\d+))?$/i
let results = val.match(reg)
let tmpVal = 0
if (results) {
if (this.decimal > 0 && results[2]) {
let min = Math.min(results[2].length, this.decimal)
tmpVal = parseFloat(`${results[1]}.${results[2].substr(0, min)}`)
} else {
tmpVal = parseFloat(results[1])
}
}
}
setTimeout(() => {
this.val = tmpVal
this.handleEmitChange()
}, 10)
}
}
Expand Down

0 comments on commit 024d776

Please sign in to comment.