|
@@ -1,6 +1,8 @@
|
|
import React, { Component } from "react";
|
|
import React, { Component } from "react";
|
|
import style from "./index.less";
|
|
import style from "./index.less";
|
|
import classNames from 'classnames';
|
|
import classNames from 'classnames';
|
|
|
|
+import Notify from '@commonComp/Notify';
|
|
|
|
+import config from '@config/index';
|
|
/***
|
|
/***
|
|
* 标签组件
|
|
* 标签组件
|
|
* author:zn@2018-11-08
|
|
* author:zn@2018-11-08
|
|
@@ -17,7 +19,7 @@ class InlineTag extends Component {
|
|
this.$span = React.createRef();
|
|
this.$span = React.createRef();
|
|
this.state = {
|
|
this.state = {
|
|
value:props.value||'',
|
|
value:props.value||'',
|
|
- placeholder:props.placeholder||''
|
|
|
|
|
|
+ over:false
|
|
};
|
|
};
|
|
this.handleBlur = this.handleBlur.bind(this);
|
|
this.handleBlur = this.handleBlur.bind(this);
|
|
this.handleInput = this.handleInput.bind(this);
|
|
this.handleInput = this.handleInput.bind(this);
|
|
@@ -26,35 +28,50 @@ class InlineTag extends Component {
|
|
}
|
|
}
|
|
handleInput(e){ //输入时保存临时值,在修改灰显为黑色时判断用
|
|
handleInput(e){ //输入时保存临时值,在修改灰显为黑色时判断用
|
|
e.stopPropagation();
|
|
e.stopPropagation();
|
|
- const value = e.target.innerText||e.target.innerHTML.replace(/ $|^ /,'');//兼容firefox26
|
|
|
|
|
|
+ const {mainSaveText,ikey,prefix,suffix,value,boxMark} = this.props;
|
|
|
|
+ const val = e.target.innerText||e.target.innerHTML.replace(/ $|^ /,'');//兼容firefox26
|
|
|
|
+ const myval = prefix+val+suffix;
|
|
|
|
+ const i = ikey.split("-")[1];
|
|
|
|
+ const tempArr = [...mainSaveText];
|
|
|
|
+ tempArr.splice(i,1);
|
|
|
|
+ let lefts = tempArr.join("");
|
|
|
|
+ if(boxMark==='1'&&(lefts+myval).length>config.limited) { //主诉超过字数限制提示并禁止输入
|
|
|
|
+ e.target.innerHTML = value||'';
|
|
|
|
+ Notify.info(config.limitText);
|
|
|
|
+ this.setState({
|
|
|
|
+ over:true
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
this.setState({
|
|
this.setState({
|
|
- value:value
|
|
|
|
- })
|
|
|
|
|
|
+ value:val,
|
|
|
|
+ over:false
|
|
|
|
+ });
|
|
}
|
|
}
|
|
handleBlur(e){ //鼠标离开是保存值到store中
|
|
handleBlur(e){ //鼠标离开是保存值到store中
|
|
e.stopPropagation(); //不阻止会触发外层div的失焦事件
|
|
e.stopPropagation(); //不阻止会触发外层div的失焦事件
|
|
- const value = e.target.innerText||e.target.innerHTML.replace(/ $|^ /,'');;
|
|
|
|
- const {handleInput,ikey,prefix,suffix,placeholder} = this.props;
|
|
|
|
- if(!value.trim()){
|
|
|
|
|
|
+ const val = e.target.innerText||e.target.innerHTML.replace(/ $|^ /,'');
|
|
|
|
+ const {handleInput,ikey,prefix,suffix,placeholder,value,boxMark} = this.props;
|
|
|
|
+ if(!val.trim()){
|
|
this.setState({
|
|
this.setState({
|
|
- placeholder:placeholder,
|
|
|
|
value:''
|
|
value:''
|
|
});
|
|
});
|
|
|
|
+ e.target.innerHTML = placeholder;
|
|
}
|
|
}
|
|
- //this.$span.current.innerText?(this.$span.current.innerText=''):(this.$span.current.innerHTML=''); //修改生成文字变成输入的2倍bug
|
|
|
|
- handleInput&&handleInput({text:value.trim(),ikey,prefix,suffix});
|
|
|
|
- this.setState({
|
|
|
|
- value:value.trim()
|
|
|
|
- });
|
|
|
|
|
|
+ if(boxMark==='1'&&this.state.over){ //超过字数限制,显示输入前的值
|
|
|
|
+ e.target.innerHTML = value||'';
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //主诉未超过字数限制,保存值
|
|
|
|
+ e.target.innerHTML = val.trim();
|
|
|
|
+ handleInput&&handleInput({text:val.trim(),ikey,prefix,suffix});
|
|
}
|
|
}
|
|
handleFocus(e){
|
|
handleFocus(e){
|
|
e.stopPropagation();
|
|
e.stopPropagation();
|
|
- const text = e.target.innerText || e.target.innerHTML.replace(/ $|^ /,'');;
|
|
|
|
|
|
+ const text = e.target.innerText || e.target.innerHTML.replace(/ $|^ /,'');
|
|
const {placeholder} = this.props;
|
|
const {placeholder} = this.props;
|
|
if(text.trim()==placeholder){
|
|
if(text.trim()==placeholder){
|
|
- this.setState({
|
|
|
|
- placeholder:''
|
|
|
|
- });
|
|
|
|
|
|
+ e.target.innerHTML = '';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
getStyle(){
|
|
getStyle(){
|
|
@@ -91,21 +108,12 @@ class InlineTag extends Component {
|
|
}
|
|
}
|
|
componentDidMount(){
|
|
componentDidMount(){
|
|
//设置最小宽度避免输入后宽度跳动
|
|
//设置最小宽度避免输入后宽度跳动
|
|
|
|
+ this.$span.current.innerHTML=this.props.placeholder;
|
|
const spanWidth = window.getComputedStyle(this.$span.current).width;
|
|
const spanWidth = window.getComputedStyle(this.$span.current).width;
|
|
this.$span.current.style.minWidth=spanWidth;
|
|
this.$span.current.style.minWidth=spanWidth;
|
|
}
|
|
}
|
|
- componentWillReceiveProps(nextProps){
|
|
|
|
- if((nextProps.placeholder == this.props.placeholder)&&(nextProps.value == this.props.value)){
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- this.setState({
|
|
|
|
- placeholder:nextProps.placeholder,
|
|
|
|
- value:nextProps.value
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
render(){
|
|
render(){
|
|
- const {prefix,suffix,value} = this.props;
|
|
|
|
- const {placeholder} = this.state;
|
|
|
|
|
|
+ const {prefix,suffix} = this.props;
|
|
return <div className={this.getStyle()}
|
|
return <div className={this.getStyle()}
|
|
onClick={this.handleFixClick}>
|
|
onClick={this.handleFixClick}>
|
|
<span>{prefix}</span>
|
|
<span>{prefix}</span>
|
|
@@ -115,7 +123,7 @@ class InlineTag extends Component {
|
|
onInput={this.handleInput}
|
|
onInput={this.handleInput}
|
|
onFocus={this.handleFocus}
|
|
onFocus={this.handleFocus}
|
|
onClick={(e)=>{e.stopPropagation();}}
|
|
onClick={(e)=>{e.stopPropagation();}}
|
|
- ref={this.$span}> {value||placeholder}</span>
|
|
|
|
|
|
+ ref={this.$span}></span>
|
|
<span>{suffix}</span>
|
|
<span>{suffix}</span>
|
|
</div>;
|
|
</div>;
|
|
}
|
|
}
|