|
@@ -21,6 +21,7 @@ class NumberDrop extends Component{
|
|
|
editable:false, //标签是否可输入
|
|
|
timer:null,
|
|
|
sltTimer:null,
|
|
|
+ blurTimer:null,
|
|
|
hasSelect:false, //是否点过下拉键盘
|
|
|
boxLeft:0,
|
|
|
boxTop:0,
|
|
@@ -43,8 +44,10 @@ class NumberDrop extends Component{
|
|
|
this.beyondArea = this.beyondArea.bind(this);
|
|
|
}
|
|
|
select(text){ //选中键盘上数字事件
|
|
|
+ //placeholder修改后,第一次点击键盘触发blur后onClick不触发,原因未知,改为onMouseup可触发
|
|
|
let timer = null;
|
|
|
clearTimeout(this.state.sltTimer);
|
|
|
+ clearTimeout(this.state.blurTimer);
|
|
|
const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max} = this.props;
|
|
|
const needCompare=min!=undefined&&max!=undefined;
|
|
|
if(!text){
|
|
@@ -164,28 +167,31 @@ class NumberDrop extends Component{
|
|
|
numInpBlur(e){ //数字框失焦,保存值到store中
|
|
|
e.stopPropagation();
|
|
|
const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max,show} = this.props;
|
|
|
- if(show){ //修改清空后第一次点击键盘不触发click事件bug
|
|
|
+ /*if(show){ //修改清空后第一次点击键盘不触发click事件bug--失焦placehoder消失,弃用
|
|
|
return;
|
|
|
- }
|
|
|
+ }*/
|
|
|
//输入超出合理范围或输入不是数字提示且清空
|
|
|
const needCompare=min!=undefined&&max!=undefined;
|
|
|
- //if(needCompare){
|
|
|
- const txt = e.target.innerText.trim();
|
|
|
- const isFine = this.validSymbols(txt,min,max); //有~或/时是否合理
|
|
|
- const hasSymbol = /[\/|\~]/g.test(txt); //是否有~或/
|
|
|
- const singleFine = (!isNaN(+txt)&&!needCompare)||(!isNaN(+txt)&&needCompare&&parseFloat(min)<=parseFloat(txt)&&parseFloat(txt)<=parseFloat(max)); //无~或/时是否合理
|
|
|
- if(txt!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
|
|
|
- this.beyondArea();
|
|
|
- return;
|
|
|
- }
|
|
|
- //}
|
|
|
+ const txt = e.target.innerText.trim();
|
|
|
+ const isFine = this.validSymbols(txt,min,max); //有~或/时是否合理
|
|
|
+ const hasSymbol = /[\/|\~]/g.test(txt); //是否有~或/
|
|
|
+ const singleFine = (!isNaN(+txt)&&!needCompare)||(!isNaN(+txt)&&needCompare&&parseFloat(min)<=parseFloat(txt)&&parseFloat(txt)<=parseFloat(max)); //无~或/时是否合理
|
|
|
+ if(txt!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
|
|
|
+ this.beyondArea();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
//输入为空时显示placeholder
|
|
|
- if(!e.target.innerText.trim()){
|
|
|
- this.setState({
|
|
|
- placeholder:this.props.placeholder
|
|
|
- });
|
|
|
- }
|
|
|
+ const timer = setTimeout(()=>{
|
|
|
+ if(!e.target.innerText.trim()){
|
|
|
+ this.setState({
|
|
|
+ placeholder:this.props.placeholder
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },200);
|
|
|
+ this.setState({
|
|
|
+ blurTimer:timer
|
|
|
+ });
|
|
|
|
|
|
const val = e.target.innerText.trim();
|
|
|
const {placeholder} = this.state;
|
|
@@ -227,7 +233,6 @@ class NumberDrop extends Component{
|
|
|
}
|
|
|
handleBlur(e){ //双击编辑blur
|
|
|
const {handleLabelChange,ikey,boxMark,value} = this.props;
|
|
|
- //if(!this.state.editable) return;
|
|
|
this.setState({
|
|
|
editable: false
|
|
|
});
|
|
@@ -239,7 +244,6 @@ class NumberDrop extends Component{
|
|
|
handleLabelChange && handleLabelChange({ikey,changeVal,type:boxMark,totalVal,prefix,suffix});
|
|
|
}
|
|
|
getSpanClass(){ //将被替换的文字选中状态显示
|
|
|
- //const {hasSelect} = this.state;
|
|
|
const cls = this.props.show?style['blued']:'';
|
|
|
return cls;
|
|
|
}
|
|
@@ -248,14 +252,13 @@ class NumberDrop extends Component{
|
|
|
const spanWidth = window.getComputedStyle(this.$span.current).width;
|
|
|
this.$span.current.style.minWidth=spanWidth;
|
|
|
//保存输入框dom以便聚焦
|
|
|
- const {saveDoms,num} = this.props;
|
|
|
- //console.log(num);
|
|
|
+ const {saveDoms} = this.props;
|
|
|
saveDoms&&saveDoms(this.$span);
|
|
|
- //console.log(this.props.inputRef)
|
|
|
}
|
|
|
render(){
|
|
|
const {prefix,suffix,show,value,handleHide,allClick} = this.props;
|
|
|
- const {numEditable,placeholder,editable,hasSelect,boxTop,boxLeft} = this.state;
|
|
|
+ const {placeholder,editable,hasSelect,boxTop,boxLeft} = this.state;
|
|
|
+ //console.log(prefix,value,placeholder+'1',this.props.placeholder)
|
|
|
return <div className={this.getClasses()}
|
|
|
ref={this.$cont}
|
|
|
onDoubleClick={this.changeToEdit}
|