|
@@ -23,6 +23,8 @@ class NumberDrop extends Component{
|
|
|
isClosed:false
|
|
|
};
|
|
|
this.$span = React.createRef();
|
|
|
+ this.$pre = React.createRef();
|
|
|
+ this.$suf = React.createRef();
|
|
|
this.select = this.select.bind(this);
|
|
|
this.numInpBlur = this.numInpBlur.bind(this);
|
|
|
this.handleSpanInp = this.handleSpanInp.bind(this);
|
|
@@ -81,8 +83,9 @@ class NumberDrop extends Component{
|
|
|
numEditable:true,
|
|
|
hasSelect:false
|
|
|
});
|
|
|
+ const val = e.target.innerText.replace(/^\s*/,'');
|
|
|
const {handleSelect,ikey,suffix,prefix,mainSaveText,placeholder} = this.props;
|
|
|
- const text = e.target.innerText===placeholder?'':e.target.innerText;
|
|
|
+ const text = val===placeholder?'':val;
|
|
|
e.target.innerText = ''; //避免出现重复输入值
|
|
|
handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText});
|
|
|
}
|
|
@@ -110,14 +113,17 @@ class NumberDrop extends Component{
|
|
|
}
|
|
|
}
|
|
|
handleBlur(e){ //双击编辑blur
|
|
|
- const {handleLabelChange,ikey,boxMark} = this.props;
|
|
|
+ const {handleLabelChange,ikey,boxMark,value} = this.props;
|
|
|
//if(!this.state.editable) return;
|
|
|
this.setState({
|
|
|
editable: false
|
|
|
});
|
|
|
let totalVal = e.target.innerText;
|
|
|
- let changeVal = this.props.value;
|
|
|
- handleLabelChange && handleLabelChange({ikey,changeVal,type:boxMark,totalVal});
|
|
|
+ let changeVal = this.$span.current.innerText.replace(/^\s*/,'');//数字框值-修改后;去掉前空格避免多空格叠加
|
|
|
+ let prefix = this.$pre.current.innerText.replace(/^\s*/,''); //前缀值-修改后
|
|
|
+ let suffix = this.$suf.current.innerText.replace(/^\s*/,''); //后缀值-修改后
|
|
|
+ console.log('数字框:'+changeVal,";全部:"+totalVal,";前缀:"+prefix+";后缀:"+suffix);
|
|
|
+ handleLabelChange && handleLabelChange({ikey,changeVal,type:boxMark,totalVal,prefix,suffix});
|
|
|
}
|
|
|
getSpanClass(){ //将被替换的文字选中状态显示
|
|
|
const {hasSelect} = this.state;
|
|
@@ -129,9 +135,10 @@ class NumberDrop extends Component{
|
|
|
const {numEditable,editable,hasSelect} = this.state;
|
|
|
return <div className={this.getClasses()}
|
|
|
onDoubleClick={this.changeToEdit}
|
|
|
- onBlur={this.handleBlur} contentEditable={editable}
|
|
|
+ contentEditable={editable}
|
|
|
+ onBlur={this.handleBlur}
|
|
|
onkeydown={handleEnter}>
|
|
|
- <span> {prefix}</span>
|
|
|
+ <span ref = {this.$pre}> {prefix}</span>
|
|
|
<span onFocus={this.handleNumFocus}
|
|
|
onClick={this.handleNumClick}
|
|
|
contentEditable={numEditable}
|
|
@@ -140,8 +147,8 @@ class NumberDrop extends Component{
|
|
|
onBlur={this.numInpBlur}
|
|
|
onInput={this.handleSpanInp}
|
|
|
className={this.getSpanClass()}
|
|
|
- onkeydown={handleEnter}>{value||placeholder}</span>
|
|
|
- <span> {suffix}</span>
|
|
|
+ onkeydown={handleEnter}> {value||placeholder}</span>
|
|
|
+ <span ref = {this.$suf}> {suffix}</span>
|
|
|
<NumberPan handleSelect={(text)=>this.select(text)}
|
|
|
onClose={handleHide}
|
|
|
show={show} toClear={!hasSelect}/>
|