|
@@ -15,49 +15,16 @@ import {handleEnter} from '@utils/tools.js';
|
|
|
class InlineTag extends Component {
|
|
|
constructor(props){
|
|
|
super(props);
|
|
|
- this.$box = React.createRef();
|
|
|
this.$span = React.createRef();
|
|
|
- this.$pre = React.createRef();
|
|
|
- this.$suf = React.createRef();
|
|
|
this.state = {
|
|
|
- editable:false,
|
|
|
value:props.value||'',
|
|
|
placeholder:props.placeholder||''
|
|
|
};
|
|
|
- this.changeToEdit = this.changeToEdit.bind(this);
|
|
|
- this.changeToClick = this.changeToClick.bind(this);
|
|
|
this.handleBlur = this.handleBlur.bind(this);
|
|
|
this.handleInput = this.handleInput.bind(this);
|
|
|
this.handleFocus = this.handleFocus.bind(this);
|
|
|
this.handleFixClick = this.handleFixClick.bind(this);
|
|
|
}
|
|
|
- changeToEdit(e){
|
|
|
- const {handledbClick,id} = this.props;
|
|
|
- // 输入框有值才可以双击编辑
|
|
|
- const text = this.$span.current.innerText;
|
|
|
- if(!text.trim()){
|
|
|
- return
|
|
|
- }
|
|
|
- this.setState({
|
|
|
- editable:true
|
|
|
- });
|
|
|
- //埋点记录
|
|
|
- handledbClick&&handledbClick({id});
|
|
|
- }
|
|
|
- changeToClick(e){
|
|
|
- e.stopPropagation();
|
|
|
- const {saveEditText,ikey} = this.props;
|
|
|
- this.setState({
|
|
|
- editable:false
|
|
|
- });
|
|
|
- saveEditText&&saveEditText({
|
|
|
- changeVal:this.$span.current.innerText,
|
|
|
- totalVal:this.$box.current.innerText,
|
|
|
- prefix:this.$pre.current.innerText,
|
|
|
- suffix:this.$suf.current.innerText,
|
|
|
- ikey
|
|
|
- });
|
|
|
- }
|
|
|
handleInput(e){ //输入时保存临时值,在修改灰显为黑色时判断用
|
|
|
e.stopPropagation();
|
|
|
}
|
|
@@ -125,24 +92,18 @@ class InlineTag extends Component {
|
|
|
}
|
|
|
render(){
|
|
|
const {prefix,suffix} = this.props;
|
|
|
- const {editable,placeholder,value} = this.state;
|
|
|
+ const {placeholder,value} = this.state;
|
|
|
return <div className={this.getStyle()}
|
|
|
- onDoubleClick={this.changeToEdit}
|
|
|
- /*onClick={!editable?this.handleFixClick:''}*/
|
|
|
- onKeyDown={handleEnter}
|
|
|
- onBlur={this.changeToClick}
|
|
|
- ref={this.$box}
|
|
|
- contentEditable={editable}>
|
|
|
- <span ref={this.$pre}> {prefix}</span>
|
|
|
+ onClick={this.handleFixClick}>
|
|
|
+ <span>{prefix}</span>
|
|
|
<span className={style['free-in']}
|
|
|
contentEditable={true}
|
|
|
onBlur={this.handleBlur}
|
|
|
onInput={this.handleInput}
|
|
|
onFocus={this.handleFocus}
|
|
|
- /*onClick={e=>e.stopPropagation()}*/
|
|
|
onKeyDown={handleEnter}
|
|
|
ref={this.$span}> {value||placeholder}</span>
|
|
|
- <span ref={this.$suf}> {suffix}</span>
|
|
|
+ <span>{suffix}</span>
|
|
|
</div>;
|
|
|
}
|
|
|
}
|