Compare commits

...

3 commits

Author SHA1 Message Date
rhyme
c09e262f39 update 2020-06-17 12:11:58 +08:00
rhyme
c87f7f730b update 2020-06-17 11:52:52 +08:00
rhyme
e205e05247 update 2020-06-17 10:51:48 +08:00

View file

@ -24,7 +24,6 @@
@blur="blur"
@keydown.stop="keyDown"
@input="change"
ref="precisionCursor"
@mouseup="preventDefault"
@change="change"
:readonly="readonly || !editable"
@ -191,7 +190,7 @@
// return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
let arr = (this.currentValue + '').split('.');
if (this.precision && arr[1] && this.precision < arr[1].length) {
return this.currentValue.toFixed(this.precision);
return this.currentValue.toFixed(this.precision);
}
return this.currentValue;
},
@ -225,6 +224,7 @@
if (this.disabled || this.readonly) {
return false;
}
const targetVal = Number(e.target.value);
let val = Number(this.currentValue);
const step = Number(this.step);
@ -261,8 +261,7 @@
if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
const {min, max} = this;
// #6245
if ( val!==null && !this.activeChange ) {
if (val!==null) {
if (val > max) {
val = max;
} else if (val < min) {
@ -298,7 +297,6 @@
}
},
change (event) {
if (event.type == 'change' && this.activeChange) return;
if (event.type == 'input' && !this.activeChange) return;
let val = event.target.value.trim();
@ -311,24 +309,15 @@
this.setValue(null);
return;
}
if (event.type == 'input' && val.match(/^\-?\.?$|\.$/g)) return; // prevent fire early if decimal. If no more input the change event will fire later
//#fixed when setting the precision val, input point cannot show problem
const precision = this.precision;
let cacheVal = this.currentValue;
if( precision ){
const valMatchPointArr = (val+'').match(/\./g);
if( valMatchPointArr && valMatchPointArr.length >= 2 ){
cacheVal = this.currentValue + '.';
}
}
if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
val = Number(val);
if (!isNaN(val) ) {
if (!isNaN(val)) {
this.currentValue = val;
this.setValue(val);
} else {
event.target.value = cacheVal;
event.target.value = this.currentValue;
}
},
changeVal (val) {
@ -353,14 +342,6 @@
},
currentValue (val) {
this.changeVal(val);
//optimization - Solve the problem of cursor positioning inaccuracy
this.$nextTick(()=>{
if( this.precision ){
const currentValueLength = ( this.currentValue || 0 ).toString().length;
const precisionCursor = this.$refs.precisionCursor;
precisionCursor.selectionStart = precisionCursor.selectionEnd = currentValueLength;
}
});
},
min () {
this.changeVal(this.currentValue);