|
@@ -1,7 +1,7 @@
|
|
import React,{Component} from 'react';
|
|
import React,{Component} from 'react';
|
|
import style from './index.less';
|
|
import style from './index.less';
|
|
import config from "@config/index";
|
|
import config from "@config/index";
|
|
-import {filterArr,isIE,getPageCoordinate,filterDataArr,preventDefault} from '@utils/tools.js';
|
|
|
|
|
|
+import {filterArr,isIE,getPageCoordinate,filterDataArr,preventDefault,setFontColorSize,moveEnd} from '@utils/tools.js';
|
|
import Notify from '../Notify/index.js';
|
|
import Notify from '../Notify/index.js';
|
|
import classNames from 'classnames';
|
|
import classNames from 'classnames';
|
|
|
|
|
|
@@ -17,6 +17,7 @@ import $ from 'jquery';
|
|
* * text:标签内文字
|
|
* * text:标签内文字
|
|
*
|
|
*
|
|
* ****/
|
|
* ****/
|
|
|
|
+let indexNum = '';
|
|
|
|
|
|
class EditableSpan extends Component{
|
|
class EditableSpan extends Component{
|
|
constructor(props){
|
|
constructor(props){
|
|
@@ -36,8 +37,9 @@ class EditableSpan extends Component{
|
|
this.handleBlur = this.handleBlur.bind(this);
|
|
this.handleBlur = this.handleBlur.bind(this);
|
|
this.handleKeydown = this.handleKeydown.bind(this);
|
|
this.handleKeydown = this.handleKeydown.bind(this);
|
|
this.handleKeyup = this.handleKeyup.bind(this);
|
|
this.handleKeyup = this.handleKeyup.bind(this);
|
|
- this.moveEnd = this.moveEnd.bind(this);
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
+ this.selectStart = this.selectStart.bind(this);
|
|
|
|
+ this.selectEnd=this.selectEnd.bind(this);
|
|
}
|
|
}
|
|
handleFocus(e){
|
|
handleFocus(e){
|
|
e.stopPropagation();
|
|
e.stopPropagation();
|
|
@@ -48,8 +50,10 @@ class EditableSpan extends Component{
|
|
setTimeout(function(){
|
|
setTimeout(function(){
|
|
txt = that.$span.current.innerText||that.$span.current.innerHTML;
|
|
txt = that.$span.current.innerText||that.$span.current.innerHTML;
|
|
that.$span.current.innerHTML = txt;
|
|
that.$span.current.innerHTML = txt;
|
|
|
|
+ moveEnd($(that.$span.current)[0]); //光标落到最后去
|
|
});
|
|
});
|
|
})
|
|
})
|
|
|
|
+
|
|
const {mainSaveText,full,setFocusIndex,i,boxMark,value}= this.props;
|
|
const {mainSaveText,full,setFocusIndex,i,boxMark,value}= this.props;
|
|
let mainText = filterDataArr(mainSaveText);//主诉字数
|
|
let mainText = filterDataArr(mainSaveText);//主诉字数
|
|
if(+boxMark==3||+boxMark==4){ //主诉为空,且第一次聚焦其他史查体时提示且不可输入
|
|
if(+boxMark==3||+boxMark==4){ //主诉为空,且第一次聚焦其他史查体时提示且不可输入
|
|
@@ -79,6 +83,7 @@ class EditableSpan extends Component{
|
|
if(mainText.length >= config.limited){
|
|
if(mainText.length >= config.limited){
|
|
if(text1.length > labelVal.length){
|
|
if(text1.length > labelVal.length){
|
|
e.target.innerHTML = labelVal; //innerHTML兼容FF26
|
|
e.target.innerHTML = labelVal; //innerHTML兼容FF26
|
|
|
|
+ e.target.blur();
|
|
Notify.info(config.limitText);
|
|
Notify.info(config.limitText);
|
|
return
|
|
return
|
|
}else if(text1.length == labelVal.length){
|
|
}else if(text1.length == labelVal.length){
|
|
@@ -134,21 +139,6 @@ class EditableSpan extends Component{
|
|
$(this.$span.current).off("paste");
|
|
$(this.$span.current).off("paste");
|
|
}
|
|
}
|
|
|
|
|
|
- moveEnd(obj) {
|
|
|
|
- if(window.getSelection){//ie11 10 9 ff safari
|
|
|
|
- obj.focus(); //解决ff不获取焦点无法定位问题
|
|
|
|
- var range = window.getSelection();//创建range
|
|
|
|
- range.selectAllChildren(obj);//range 选择obj下所有子内容
|
|
|
|
- range.collapseToEnd();//光标移至最后
|
|
|
|
- }
|
|
|
|
- else if (document.selection) {//ie10 9 8 7 6 5
|
|
|
|
- var range = document.selection.createRange();//创建选择对象
|
|
|
|
- range.moveToElementText(obj);//range定位到obj
|
|
|
|
- range.collapse(false);//光标移至最后
|
|
|
|
- range.select();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
handleKeydown(e){
|
|
handleKeydown(e){
|
|
const ev = e||window.event;
|
|
const ev = e||window.event;
|
|
const {i} = this.props;
|
|
const {i} = this.props;
|
|
@@ -163,32 +153,35 @@ class EditableSpan extends Component{
|
|
preVal:innerVal
|
|
preVal:innerVal
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
let range = window.getSelection();
|
|
let range = window.getSelection();
|
|
let textIndex = range.focusOffset;
|
|
let textIndex = range.focusOffset;
|
|
- let textLength = range.anchorNode.length;
|
|
|
|
- if(ev.keyCode==37&& i!=0){//向左
|
|
|
|
|
|
+ let textLength = range.anchorNode&&range.anchorNode.length;
|
|
|
|
+ let preObj = $(this.$span.current).prev();
|
|
|
|
+ if(ev.keyCode==37){//向左
|
|
let preObj = $(this.$span.current).prev();
|
|
let preObj = $(this.$span.current).prev();
|
|
let obj = preObj[0]&&preObj[0].nodeName=="DIV"?preObj.prev():preObj;
|
|
let obj = preObj[0]&&preObj[0].nodeName=="DIV"?preObj.prev():preObj;
|
|
if(textIndex == 0){
|
|
if(textIndex == 0){
|
|
preventDefault(ev);
|
|
preventDefault(ev);
|
|
if(obj){
|
|
if(obj){
|
|
- this.moveEnd(obj[0]);
|
|
|
|
|
|
+ obj[0]&&moveEnd(obj[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(ev.keyCode==39){//向右
|
|
if(ev.keyCode==39){//向右
|
|
|
|
+ let curObj = $(this.$span.current)
|
|
let nextObj = $(this.$span.current).next();
|
|
let nextObj = $(this.$span.current).next();
|
|
let obj = nextObj[0]&&nextObj[0].nodeName=="DIV"?nextObj.next():nextObj;
|
|
let obj = nextObj[0]&&nextObj[0].nodeName=="DIV"?nextObj.next():nextObj;
|
|
if(textIndex == textLength || textLength==undefined || (textIndex == 0 && textLength==1)){
|
|
if(textIndex == textLength || textLength==undefined || (textIndex == 0 && textLength==1)){
|
|
preventDefault(ev);
|
|
preventDefault(ev);
|
|
if(obj){
|
|
if(obj){
|
|
- obj.focus();
|
|
|
|
|
|
+ obj[0]&&obj.focus();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
handleKeyup(e){
|
|
handleKeyup(e){
|
|
- const {boxMark,handleKeydown,removeId,handleClear,removeSpan} = this.props;
|
|
|
|
|
|
+ const {boxMark,handleKeydown,removeId,handleClear,removeSpan,handleChange,select_end} = this.props;
|
|
const {preVal,index} = this.state;
|
|
const {preVal,index} = this.state;
|
|
const ev = e||window.event;
|
|
const ev = e||window.event;
|
|
const target = ev.target||ev.srcElement;
|
|
const target = ev.target||ev.srcElement;
|
|
@@ -200,13 +193,24 @@ class EditableSpan extends Component{
|
|
if(ev.keyCode==46){//delete
|
|
if(ev.keyCode==46){//delete
|
|
//判断nexObj
|
|
//判断nexObj
|
|
// let nextObj = $(this.$span.current).next();
|
|
// let nextObj = $(this.$span.current).next();
|
|
|
|
+ // ||textIndex ==innerVal.length&&preObj[0].nodeName=="DIV"
|
|
|
|
+ let range = window.getSelection();
|
|
|
|
+ let textIndex = range.focusOffset;
|
|
|
|
+
|
|
let nextObj = $(this.$span.current);
|
|
let nextObj = $(this.$span.current);
|
|
|
|
+ let nexObj = $(this.$span.current).next();
|
|
|
|
+ let nexObjN = nexObj.next();
|
|
|
|
+ let preObj = $(this.$span.current).prev();
|
|
|
|
+ let nexVal = nexObj[0]&&nexObj[0].innerText || nexObj[0]&&nexObj[0].innerHTML;
|
|
if(preVal.trim().length==1&& !innerVal){
|
|
if(preVal.trim().length==1&& !innerVal){
|
|
removeId && removeId({boxMark,i:index,text:"",flag:'del'});
|
|
removeId && removeId({boxMark,i:index,text:"",flag:'del'});
|
|
handleClear && handleClear({boxMark});//删除最后一个字时清空搜索结果,避免现病史搜索框不立即消失的情况
|
|
handleClear && handleClear({boxMark});//删除最后一个字时清空搜索结果,避免现病史搜索框不立即消失的情况
|
|
//如果后一个不是标签,则光标移到最前
|
|
//如果后一个不是标签,则光标移到最前
|
|
if(nextObj && nextObj[0].nodeName !=="DIV"){
|
|
if(nextObj && nextObj[0].nodeName !=="DIV"){
|
|
- nextObj.focus();
|
|
|
|
|
|
+ // nextObj.focus();
|
|
|
|
+ moveEnd(nextObj[0],1)
|
|
|
|
+ }else{
|
|
|
|
+ moveEnd(preObj[0])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//action里往后删除
|
|
//action里往后删除
|
|
@@ -214,32 +218,53 @@ class EditableSpan extends Component{
|
|
let data = innerVal.trim();
|
|
let data = innerVal.trim();
|
|
if(nextObj && !config.punctuationReg.test(data) || data=='<br>'){
|
|
if(nextObj && !config.punctuationReg.test(data) || data=='<br>'){
|
|
handleKeydown&&handleKeydown({boxMark,i:index,text:data,flag:'del'});
|
|
handleKeydown&&handleKeydown({boxMark,i:index,text:data,flag:'del'});
|
|
- // nextObj.focus();
|
|
|
|
if(nextObj && nextObj[0] && nextObj[0].nodeName !=="DIV"){
|
|
if(nextObj && nextObj[0] && nextObj[0].nodeName !=="DIV"){
|
|
// IE浏览器focus光标在最后,其他浏览器在最前
|
|
// IE浏览器focus光标在最后,其他浏览器在最前
|
|
- nextObj.focus();
|
|
|
|
|
|
+ // nextObj.focus();
|
|
|
|
+ if(boxMark==2&&this.props.data[index+1]&&this.props.data[index+1].flag==3){
|
|
|
|
+ moveEnd(nexObjN[0],1);
|
|
|
|
+ }else{
|
|
|
|
+ moveEnd(nextObj[0],1);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
/*this.setState({
|
|
/*this.setState({
|
|
index: null
|
|
index: null
|
|
})*/
|
|
})*/
|
|
|
|
+ }else if(indexNum ==innerVal.length&&nexObj[0]&&nexObj[0].nodeName=="DIV"){//span最后一位后面为div标签
|
|
|
|
+ handleKeydown&&handleKeydown({boxMark,i:index+1,text:data,flag:'del'});
|
|
|
|
+ moveEnd(nextObj[0]);
|
|
|
|
+ }else if(nexObj[0]&&nexObj[0].nodeName=="SPAN"){
|
|
|
|
+ if(nexVal.length <= 1){//为空或者一个字delete时候
|
|
|
|
+ removeId && removeId({boxMark,i:index+1,text:"",flag:'del'});
|
|
|
|
+ handleClear && handleClear({boxMark});
|
|
|
|
+ moveEnd(nexObj[0])
|
|
|
|
+ }else if(nexVal.length > 1){
|
|
|
|
+ let tmpVal = nexVal.substr(1,data.length)
|
|
|
|
+ handleChange&&handleChange({text1:tmpVal,boxMark,i:index+1});
|
|
|
|
+ nexObj.html(tmpVal)
|
|
|
|
+ moveEnd(nexObj[0],1)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if(ev.keyCode==8){
|
|
|
|
|
|
+ if(ev.keyCode==8&&!select_end){
|
|
// 主诉现病史去重:删除最后一个字的时候移除该数据(将name、id和value替换成空)并移除id
|
|
// 主诉现病史去重:删除最后一个字的时候移除该数据(将name、id和value替换成空)并移除id
|
|
// 前面是标签,内容为空时再删一次才移除标签;前面是文本,则直接移除;
|
|
// 前面是标签,内容为空时再删一次才移除标签;前面是文本,则直接移除;
|
|
let preObj = $(this.$span.current).prev();
|
|
let preObj = $(this.$span.current).prev();
|
|
|
|
+ let curObj = $(this.$span.current);
|
|
if(index!==0&&preVal.trim().length==1&& !innerVal){
|
|
if(index!==0&&preVal.trim().length==1&& !innerVal){
|
|
removeId && removeId({boxMark,i:index,text:""});
|
|
removeId && removeId({boxMark,i:index,text:""});
|
|
handleClear && handleClear({boxMark});//删除最后一个字时清空搜索结果,避免现病史搜索框不立即消失的情况
|
|
handleClear && handleClear({boxMark});//删除最后一个字时清空搜索结果,避免现病史搜索框不立即消失的情况
|
|
if(preObj[0].nodeName !=="DIV"){
|
|
if(preObj[0].nodeName !=="DIV"){
|
|
- this.moveEnd(preObj[0]);
|
|
|
|
|
|
+ moveEnd(preObj[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ let range = window.getSelection();
|
|
|
|
+ let textIndex = range.focusOffset;
|
|
if(innerVal !== preVal){
|
|
if(innerVal !== preVal){
|
|
-
|
|
|
|
|
|
+
|
|
}else{
|
|
}else{
|
|
// 中英文数字和下划线--单独删除标签
|
|
// 中英文数字和下划线--单独删除标签
|
|
/*const reg = new RegExp("([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_])");
|
|
/*const reg = new RegExp("([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_])");
|
|
@@ -256,14 +281,34 @@ class EditableSpan extends Component{
|
|
// let pattern = new RegExp(/^\,?$|^\,?$|^\.?$|^\。?$|^\、?$|^\;?$|^\;?$|^\:?$|^\:?$|\s/);
|
|
// let pattern = new RegExp(/^\,?$|^\,?$|^\.?$|^\。?$|^\、?$|^\;?$|^\;?$|^\:?$|^\:?$|\s/);
|
|
// if(index!==0 && pattern.test(data)){
|
|
// if(index!==0 && pattern.test(data)){
|
|
// 后半段是处理IE
|
|
// 后半段是处理IE
|
|
- if(index!==0 && !config.punctuationReg.test(data) || index!==0 && data=='<br>'){
|
|
|
|
|
|
+ if(index!==0 && !config.punctuationReg.test(data) || index!==0 && data=='<br>'||indexNum == 0&&preObj[0]&&preObj[0].nodeName=="DIV"){
|
|
// let preObj = $(this.$span.current).prev();
|
|
// let preObj = $(this.$span.current).prev();
|
|
let obj = preObj[0].nodeName=="DIV"?preObj.prev():preObj;
|
|
let obj = preObj[0].nodeName=="DIV"?preObj.prev():preObj;
|
|
handleKeydown&&handleKeydown({boxMark,i:index,text:data,flag:'backsp'});
|
|
handleKeydown&&handleKeydown({boxMark,i:index,text:data,flag:'backsp'});
|
|
- this.moveEnd(obj[0]);
|
|
|
|
|
|
+ moveEnd(obj[0]);
|
|
this.setState({
|
|
this.setState({
|
|
index: null
|
|
index: null
|
|
})
|
|
})
|
|
|
|
+ }else if(textIndex == 0&&preObj[0]&&preObj[0].nodeName=="SPAN"){
|
|
|
|
+ let data = preObj[0].innerText || preObj[0].innerHTML;
|
|
|
|
+ if(data.length == 1){//span只有一个文本,删除后移除检索
|
|
|
|
+ removeId && removeId({boxMark,i:index-1,text:""});
|
|
|
|
+ handleClear && handleClear({boxMark});
|
|
|
|
+ if(preObj[0].nodeName !=="DIV"){
|
|
|
|
+ if(boxMark==2){
|
|
|
|
+ moveEnd(preObj[0],1);
|
|
|
|
+ }else{
|
|
|
|
+ moveEnd(preObj[0]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ let tmpVal = data.substr(0,data.length-1)
|
|
|
|
+ handleChange&&handleChange({text1:tmpVal,boxMark,i:index});
|
|
|
|
+ preObj.html(tmpVal)
|
|
|
|
+ if(preObj[0].nodeName !=="DIV"){
|
|
|
|
+ moveEnd(preObj[0]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 主诉使用模板删除最后一个空span时移除
|
|
// 主诉使用模板删除最后一个空span时移除
|
|
@@ -271,7 +316,6 @@ class EditableSpan extends Component{
|
|
removeSpan();
|
|
removeSpan();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
componentWillReceiveProps(next){
|
|
componentWillReceiveProps(next){
|
|
const isRead = this.props.isRead;
|
|
const isRead = this.props.isRead;
|
|
@@ -281,6 +325,9 @@ class EditableSpan extends Component{
|
|
}
|
|
}
|
|
handleClick(e){
|
|
handleClick(e){
|
|
$(this.$span.current).attr({"contentEditable":true}).focus()
|
|
$(this.$span.current).attr({"contentEditable":true}).focus()
|
|
|
|
+ let range = window.getSelection();
|
|
|
|
+ let textIndex = range.focusOffset;
|
|
|
|
+ indexNum = textIndex
|
|
}
|
|
}
|
|
componentDidMount(){
|
|
componentDidMount(){
|
|
const {value} = this.props;
|
|
const {value} = this.props;
|
|
@@ -288,8 +335,19 @@ class EditableSpan extends Component{
|
|
this.$span.current.innerText?(this.$span.current.innerText = value||''):(this.$span.current.innerHTML = value||'');
|
|
this.$span.current.innerText?(this.$span.current.innerText = value||''):(this.$span.current.innerHTML = value||'');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ selectStart(){
|
|
|
|
+ const {i,setSelectArea,boxMark}= this.props;
|
|
|
|
+ setSelectArea({i,boxMark,dir:'start'});
|
|
|
|
+ }
|
|
|
|
+ selectEnd(){
|
|
|
|
+ const {i,setSelectArea,boxMark,select_start}= this.props;
|
|
|
|
+ if(select_start!==i){ //判断不能省,否则无法聚焦
|
|
|
|
+ setSelectArea({i,boxMark,dir:'end'});
|
|
|
|
+ window.getSelection().empty();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
getClass(){
|
|
getClass(){
|
|
- const {full,value,saveText,i,preIsExt,afterIsExt} = this.props;
|
|
|
|
|
|
+ const {full,value,saveText,i,preIsExt,afterIsExt,mouseSelect} = this.props;
|
|
const br = preIsExt&&!afterIsExt; //最后一个体征标签
|
|
const br = preIsExt&&!afterIsExt; //最后一个体征标签
|
|
const preSelected = saveText[i-1];
|
|
const preSelected = saveText[i-1];
|
|
const isFull = full?' '+style['full']:''; //是否宽度设为整行宽度
|
|
const isFull = full?' '+style['full']:''; //是否宽度设为整行宽度
|
|
@@ -297,11 +355,12 @@ class EditableSpan extends Component{
|
|
const ext = preIsExt?style['ext']:style['unselect'];
|
|
const ext = preIsExt?style['ext']:style['unselect'];
|
|
const unselect = value.match(config.punctuationReg)||preSelected?'':ext;
|
|
const unselect = value.match(config.punctuationReg)||preSelected?'':ext;
|
|
const hasBr = br?style['editable-br']:''; //最后一个体征标签换行
|
|
const hasBr = br?style['editable-br']:''; //最后一个体征标签换行
|
|
|
|
+ const selectedArea = mouseSelect?style['selected-area']:'';
|
|
const $span = this.$span.current;
|
|
const $span = this.$span.current;
|
|
if(br&&$span&&!$span.innerText){
|
|
if(br&&$span&&!$span.innerText){
|
|
this.$span.current.innerHTML=' ';
|
|
this.$span.current.innerHTML=' ';
|
|
}
|
|
}
|
|
- return classNames(style['editable-span'],isFull,unselect,hasBr);
|
|
|
|
|
|
+ return classNames(style['editable-span'],isFull,unselect,hasBr,setFontColorSize(2,6),selectedArea);
|
|
}
|
|
}
|
|
|
|
|
|
render() {
|
|
render() {
|
|
@@ -311,6 +370,8 @@ class EditableSpan extends Component{
|
|
onInput={this.onChange}
|
|
onInput={this.onChange}
|
|
onFocus={this.handleFocus}
|
|
onFocus={this.handleFocus}
|
|
onBlur={this.handleBlur}
|
|
onBlur={this.handleBlur}
|
|
|
|
+ onmousedown={this.selectStart}
|
|
|
|
+ onmouseup={this.selectEnd}
|
|
onkeydown={this.handleKeydown}
|
|
onkeydown={this.handleKeydown}
|
|
onclick={this.handleClick}
|
|
onclick={this.handleClick}
|
|
onkeyup={this.handleKeyup}></span>;
|
|
onkeyup={this.handleKeyup}></span>;
|