index.jsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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,setFontColorSize} 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 Textarea extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. timer:null,
  17. inpText:'',
  18. overFlag:false,
  19. editable:true,
  20. };
  21. this.$dom = React.createRef();
  22. this.handleInput = this.handleInput.bind(this);
  23. this.handleFocus = this.handleFocus.bind(this);
  24. //this.handleBlur = this.handleBlur.bind(this);
  25. this.handleKeydown = this.handleKeydown.bind(this);
  26. this.handleBlur = this.handleBlur.bind(this);
  27. }
  28. handleFocus(e){ //初始显示props中的值,focus已经显示输入的值,避免值更新闪烁
  29. const {handleFocus,fuzhen,handleInput,isChronic,hasMain,boxMark,title} = this.props;
  30. const state = store.getState()
  31. const moduleName = state.homePage.moduleName
  32. //黏贴时去掉html格式
  33. const that = this;
  34. let txt = '';
  35. $(this.$dom.current).on("paste",function(e){
  36. setTimeout(function(){
  37. txt = that.$dom.current.innerText||that.$dom.current.innerHTML;
  38. that.$dom.current.innerHTML = txt;
  39. moveEnd($(that.$dom.current)[0]); //光标落到最后去
  40. });
  41. });
  42. //const {inpText} = this.state;console.log(inpText,boxMark,hasMain)
  43. if(boxMark!='1'&&boxMark!='2'&&!hasMain&&!e.target.innerText){
  44. //现病史、其他史无主诉且本身无内容是聚焦提示无法操作
  45. this.setState({
  46. editable:false
  47. });
  48. e.target.blur();
  49. Notify.error("无法操作,请先输入主诉");
  50. return;
  51. }else{
  52. this.setState({
  53. editable:true
  54. });
  55. }
  56. handleFocus&&handleFocus(); //其他史、查体获取数据的方法
  57. /*if(fuzhen&& !isChronic&&!(this.$dom.current.innerText?this.$dom.current.innerText:this.$dom.current.innerHTML)){
  58. const text = config.currentText.replace("(**)",fuzhen.replace(";",''));
  59. this.$dom.current.innerText?(this.$dom.current.innerText = text):(this.$dom.current.innerHTML = text);
  60. handleInput&&handleInput({text});
  61. }*/
  62. if(moduleName != title) {
  63. store.dispatch({
  64. type: SET_CURRENT_MODULE,
  65. moduleName:title
  66. })
  67. store.dispatch(getMRAnalyse())
  68. }
  69. }
  70. handleInput(e){
  71. const {handleInput,boxMark,handlePush,value} = this.props;
  72. const {inpText,overFlag,editable} = this.state;
  73. const text = e.target.innerText || e.target.innerHTML;
  74. const stimer = this.state.timer;
  75. if(!editable){
  76. e.target.innerText='';
  77. return ;
  78. }
  79. if(boxMark=='1'&&text.length>config.limited){ //主诉字符数限制
  80. e.target.innerText?(e.target.innerText = text.substr(0,config.limited)):(e.target.innerHTML = text.substr(0,config.limited));
  81. e.target.blur();
  82. Notify.error(config.limitText);
  83. if(overFlag){
  84. e.target.innerText?(e.target.innerText = inpText):(e.target.innerHTML = inpText);
  85. return
  86. }
  87. this.setState({
  88. inpText:text.substr(0,config.limited),
  89. overFlag:true
  90. });
  91. handleInput&&handleInput({text:text.substr(0,config.limited).replace('<br>','')});
  92. return;
  93. }
  94. /*if(boxMark=='3'&&!hasMain){
  95. e.target.innerText = '';
  96. return;
  97. }*/
  98. this.setState({
  99. inpText:text,
  100. overFlag:false
  101. })
  102. //存值到store FF26 会有一个<br>
  103. handleInput&&handleInput({text:text.replace('<br>','')});
  104. //右侧推送--延时推送
  105. clearTimeout(stimer);
  106. let timer = setTimeout(function(){
  107. handlePush&&handlePush();
  108. clearTimeout(stimer);
  109. },config.delayPushTime);
  110. this.setState({
  111. timer
  112. });
  113. }
  114. //除主诉外 其他是否为空
  115. ifClear(){
  116. let baseList = store.getState();
  117. let jsonData = getAllDataList(baseList);
  118. let jsonStr = getAllDataStringList(baseList);
  119. let flg = ifOtherClear(jsonData,jsonStr,baseList);
  120. return flg;
  121. }
  122. handleBlur(e){
  123. //const {saveChronic} = this.props;
  124. //const text = e.target.innerText || e.target.innerHTML;
  125. //解除绑定事件
  126. $(this.$dom.current).off("paste");
  127. /*getFeature(text).then((res)=>{
  128. if(res.data.code==0){
  129. const result = res.data.data;
  130. // 慢病
  131. if(result && result[0].chronicLabel==1){
  132. let flg = this.ifClear();
  133. if(!flg){
  134. saveChronic && saveChronic(result[0],true);
  135. }
  136. }
  137. }
  138. })*/
  139. }
  140. handleKeydown(e){
  141. const {boxMark} = this.props;
  142. const ev = e||window.event;
  143. if(+boxMark===1){
  144. //禁止回车事件
  145. if(ev.keyCode==13){return false;}
  146. }
  147. }
  148. // shouldComponentUpdate(next){ 切换字体设置不渲染
  149. // if(JSON.stringify(next) == JSON.stringify(this.props)){
  150. // return false;
  151. // }
  152. // return true;
  153. // }
  154. componentWillReceiveProps(next){
  155. const isRead = this.props.isRead;
  156. if(next.isRead != isRead||(next.value!=this.props.value&&next.value&&next.value.indexOf("复诊")!=-1)){ //value对比解决复诊不显示bug,复诊对比解决关标跳到前面bug
  157. this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
  158. this.setState({
  159. inpText:''
  160. });
  161. }
  162. }
  163. componentDidMount(){
  164. const {value} = this.props;
  165. if(value){
  166. this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerHTML=value||'');
  167. }
  168. if(isIE()){
  169. $(this.$dom.current).onIe8Input(function(e){
  170. this.handleInput(e)
  171. },this);
  172. }
  173. }
  174. render() {
  175. const { title,boxMark } = this.props;
  176. return (
  177. <div className={style["box"]}>
  178. <div className={`${style["title"]} ${setFontColorSize(2,4)}`}>{title}</div>
  179. {/*{isRead?<div className={style["content"]+" "+'11'} contentEditable={true} onFocus={this.handleFocus}>{value}</div>:''}*/}
  180. <div className={`${style["content"]} ${setFontColorSize(2,5)}`}
  181. onFocus={this.handleFocus}
  182. ref={this.$dom}
  183. contentEditable={true}
  184. onInput={this.handleInput}
  185. onkeydown={this.handleKeydown}
  186. onBlur={+boxMark===1?this.handleBlur:null}>
  187. </div>
  188. </div>
  189. );
  190. }
  191. }
  192. export default Textarea;