Compare commits
No commits in common. "iview-rhyme-1" and "2.0" have entirely different histories.
iview-rhym
...
2.0
1 changed files with 26 additions and 7 deletions
|
@ -24,6 +24,7 @@
|
||||||
@blur="blur"
|
@blur="blur"
|
||||||
@keydown.stop="keyDown"
|
@keydown.stop="keyDown"
|
||||||
@input="change"
|
@input="change"
|
||||||
|
ref="precisionCursor"
|
||||||
@mouseup="preventDefault"
|
@mouseup="preventDefault"
|
||||||
@change="change"
|
@change="change"
|
||||||
:readonly="readonly || !editable"
|
:readonly="readonly || !editable"
|
||||||
|
@ -190,7 +191,7 @@
|
||||||
// return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
|
// return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
|
||||||
let arr = (this.currentValue + '').split('.');
|
let arr = (this.currentValue + '').split('.');
|
||||||
if (this.precision && arr[1] && this.precision < arr[1].length) {
|
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;
|
return this.currentValue;
|
||||||
},
|
},
|
||||||
|
@ -224,7 +225,6 @@
|
||||||
if (this.disabled || this.readonly) {
|
if (this.disabled || this.readonly) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetVal = Number(e.target.value);
|
const targetVal = Number(e.target.value);
|
||||||
let val = Number(this.currentValue);
|
let val = Number(this.currentValue);
|
||||||
const step = Number(this.step);
|
const step = Number(this.step);
|
||||||
|
@ -261,7 +261,8 @@
|
||||||
if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
|
if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
|
||||||
|
|
||||||
const {min, max} = this;
|
const {min, max} = this;
|
||||||
if (val!==null) {
|
// #6245
|
||||||
|
if ( val!==null && !this.activeChange ) {
|
||||||
if (val > max) {
|
if (val > max) {
|
||||||
val = max;
|
val = max;
|
||||||
} else if (val < min) {
|
} else if (val < min) {
|
||||||
|
@ -297,6 +298,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
change (event) {
|
change (event) {
|
||||||
|
if (event.type == 'change' && this.activeChange) return;
|
||||||
|
|
||||||
if (event.type == 'input' && !this.activeChange) return;
|
if (event.type == 'input' && !this.activeChange) return;
|
||||||
let val = event.target.value.trim();
|
let val = event.target.value.trim();
|
||||||
|
@ -309,15 +311,24 @@
|
||||||
this.setValue(null);
|
this.setValue(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
|
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 + '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val = Number(val);
|
val = Number(val);
|
||||||
|
if (!isNaN(val) ) {
|
||||||
if (!isNaN(val)) {
|
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
this.setValue(val);
|
this.setValue(val);
|
||||||
} else {
|
} else {
|
||||||
event.target.value = this.currentValue;
|
event.target.value = cacheVal;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeVal (val) {
|
changeVal (val) {
|
||||||
|
@ -342,6 +353,14 @@
|
||||||
},
|
},
|
||||||
currentValue (val) {
|
currentValue (val) {
|
||||||
this.changeVal(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 () {
|
min () {
|
||||||
this.changeVal(this.currentValue);
|
this.changeVal(this.currentValue);
|
||||||
|
|
Loading…
Add table
Reference in a new issue