index.jsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React, { Component } from "react";
  2. import style from "./index.less";
  3. import Notify from '../Notify';
  4. import config from '@config/index';
  5. import {isIE,moveEnd} from '@utils/tools.js';
  6. import {getFeature} from '@store/async-actions/fetchModules';
  7. import {getAllDataList,getAllDataStringList,ifOtherClear} from "@utils/tools.js";
  8. import store from '@store';
  9. import $ from "jquery";
  10. import {SET_CURRENT_MODULE} from '@types/homePage';
  11. import {getMRAnalyse} from '@store/async-actions/pushMessage';
  12. class BlockInp extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. timer:null,
  17. inpText:'',
  18. overFlag:false,
  19. };
  20. this.$dom = React.createRef();
  21. this.handleInput = this.handleInput.bind(this);
  22. this.handleFocus = this.handleFocus.bind(this);
  23. //this.handleBlur = this.handleBlur.bind(this);
  24. this.handleKeydown = this.handleKeydown.bind(this);
  25. this.handleBlur = this.handleBlur.bind(this);
  26. }
  27. handleFocus(e){ //初始显示props中的值,focus已经显示输入的值,避免值更新闪烁
  28. const {handleFocus,fuzhen,handleInput,isChronic,hasMain,boxMark,title} = this.props;
  29. const state = store.getState()
  30. const moduleName = state.homePage.moduleName
  31. //黏贴时去掉html格式
  32. const that = this;
  33. let txt = '';
  34. $(this.$dom.current).on("paste",function(e){
  35. setTimeout(function(){
  36. txt = that.$dom.current.innerText||that.$dom.current.innerHTML;
  37. that.$dom.current.innerHTML = txt;
  38. moveEnd($(that.$dom.current)[0]); //光标落到最后去
  39. });
  40. });
  41. //const {inpText} = this.state;console.log(inpText,boxMark,hasMain)
  42. handleFocus&&handleFocus(); //其他史、查体获取数据的方法
  43. /*if(fuzhen&& !isChronic&&!(this.$dom.current.innerText?this.$dom.current.innerText:this.$dom.current.innerHTML)){
  44. const text = config.currentText.replace("(**)",fuzhen.replace(";",''));
  45. this.$dom.current.innerText?(this.$dom.current.innerText = text):(this.$dom.current.innerHTML = text);
  46. handleInput&&handleInput({text});
  47. }*/
  48. if(moduleName != title) {
  49. store.dispatch({
  50. type: SET_CURRENT_MODULE,
  51. moduleName:title
  52. })
  53. store.dispatch(getMRAnalyse())
  54. }
  55. }
  56. handleInput(e){
  57. const {handleInput,boxMark,handlePush,value} = this.props;
  58. const {inpText,overFlag} = this.state;
  59. const text = e.target.innerText || e.target.innerHTML.replace(/&nbsp;+/g,' ').replace(/<br>$/,'');
  60. const stimer = this.state.timer;//console.log(e.target,text)
  61. if(boxMark=='1'&&text.length>config.limited){ //主诉字符数限制
  62. e.target.innerText?(e.target.innerText = text.substr(0,config.limited)):(e.target.innerHTML = text.substr(0,config.limited));
  63. e.target.blur();
  64. Notify.error(config.limitText);
  65. if(overFlag){
  66. e.target.innerText?(e.target.innerText = inpText):(e.target.innerHTML = inpText);
  67. return
  68. }
  69. this.setState({
  70. inpText:text.substr(0,config.limited),
  71. overFlag:true
  72. });
  73. handleInput&&handleInput({text:text.substr(0,config.limited).replace('<br>','')});
  74. return;
  75. }
  76. /*if(boxMark=='3'&&!hasMain){
  77. e.target.innerText = '';
  78. return;
  79. }*/
  80. this.setState({
  81. inpText:text,
  82. overFlag:false
  83. })
  84. //存值到store FF26 会有一个<br>
  85. handleInput&&handleInput({text:text.replace('<br>','')});
  86. //右侧推送--延时推送
  87. clearTimeout(stimer);
  88. let timer = setTimeout(function(){
  89. handlePush&&handlePush();
  90. clearTimeout(stimer);
  91. },config.delayPushTime);
  92. this.setState({
  93. timer
  94. });
  95. }
  96. //除主诉外 其他是否为空
  97. ifClear(){
  98. let baseList = store.getState();
  99. let jsonData = getAllDataList(baseList);
  100. let jsonStr = getAllDataStringList(baseList);
  101. let flg = ifOtherClear(jsonData,jsonStr,baseList);
  102. return flg;
  103. }
  104. handleBlur(e){
  105. //解除绑定事件
  106. $(this.$dom.current).off("paste");
  107. }
  108. handleKeydown(e){
  109. const {boxMark} = this.props;
  110. const ev = e||window.event;
  111. if(+boxMark===1){
  112. //禁止回车事件
  113. if(ev.keyCode==13){return false;}
  114. }
  115. }
  116. componentWillReceiveProps(next){
  117. const isRead = this.props.isRead;
  118. if(next.isRead != isRead||(next.value!=this.props.value&&next.value&&next.value.indexOf("复诊")!=-1)){ //value对比解决复诊不显示bug,复诊对比解决关标跳到前面bug
  119. this.$dom.current.innerHTML = next.value||''; //ff26下不支持innerText,但ref会自动加上innerText属性,所以上面的判断不为空
  120. this.setState({
  121. inpText:''
  122. });
  123. }
  124. }
  125. componentDidMount(){
  126. const {value} = this.props;
  127. if(value){
  128. //this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerText=value||'');
  129. this.$dom.current.innerText=value||'';
  130. }
  131. if(isIE()){
  132. $(this.$dom.current).onIe8Input(function(e){
  133. this.handleInput(e)
  134. },this);
  135. }
  136. }
  137. render() {
  138. const { title,boxMark } = this.props;
  139. return (
  140. <div className={style["box"]}>
  141. <div className={style["title"]}>{title}</div>
  142. <div className={style["content"]}
  143. onFocus={this.handleFocus}
  144. ref={this.$dom}
  145. contentEditable={true}
  146. onInput={this.handleInput}
  147. onkeydown={this.handleKeydown}
  148. onBlur={+boxMark===1?this.handleBlur:null}>
  149. </div>
  150. </div>
  151. );
  152. }
  153. }
  154. export default BlockInp;