index.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React,{Component} from 'react';
  2. import style from './index.less';
  3. import {isIE,handleEnter} from '@utils/tools.js';
  4. import $ from 'jquery';
  5. /***
  6. * author:zn@2018-11-13
  7. * 电子病历项内容框
  8. * 接收参数:
  9. * boxHeight:框高度
  10. * boxWidth:框宽度
  11. * title:框名称(如主诉、现病史)
  12. * editable:是否可编辑
  13. * children:框内内容
  14. * border:边框样式,
  15. * style
  16. *
  17. * ***/
  18. class ItemBox extends Component {
  19. constructor(props){
  20. super(props);
  21. this.$div = React.createRef();
  22. this.handleClick = this.handleClick.bind(this);
  23. this.handleInput = this.handleInput.bind(this);
  24. }
  25. getBoxStyle(){
  26. const {boxHeight,boxWidth,boxLineHeight,marginTop,backgroundColor} = this.props;
  27. return {width:boxWidth?boxWidth:undefined,height:boxHeight?boxHeight:undefined,lineHeight:boxLineHeight?boxLineHeight:'22px',marginTop:marginTop,backgroundColor:backgroundColor?backgroundColor:''};
  28. }
  29. handleClick(e){
  30. const {handleClick} = this.props;
  31. handleClick && handleClick(e);//为了获取鼠标位置,显示搜索结果框;
  32. }
  33. handleInput(e){
  34. const {onchange,data} = this.props;
  35. if(!data || (data.length==0)){//避免结构化下触发onchange,导致下拉要点两下
  36. onchange&&onchange(e)
  37. }
  38. }
  39. /*componentWillReceiveProps(next){
  40. if(this.props.value && next.value!=this.props.value){
  41. this.$div.current.innerText?(this.$div.current.innerText = next.value||''):(this.$div.current.innerHTML = next.value||'');
  42. }
  43. }*/
  44. componentDidMount(){
  45. if(isIE()){
  46. $(this.$div.current).onIe8Input(function(e){
  47. this.handleInput(e)
  48. },this);
  49. }
  50. }
  51. render(){
  52. const {title,children,editable,className,handleFocus,onchange,fuzhen,border,handleBlur,titleTop,backgroundColor,boxId} = this.props;
  53. return <div className={style["box"]+" "+"clearfix"} >
  54. <div className={style["title"] + ' '+(className||'')} style={{marginTop:titleTop?'22px':''}}>{title}</div>
  55. <div ref={this.$div} className={`${style["content"]} ${border?style["border"]:''} ${backgroundColor?style["noBorder"]:''}`} contentEditable={editable} style={this.getBoxStyle()} onFocus={handleFocus} onInput={this.handleInput} onClick={(e)=>{this.handleClick(e);}} onBlur={handleBlur} id={boxId} onkeydown={handleEnter}>
  56. {fuzhen?children||fuzhen:children}
  57. </div>
  58. </div>
  59. }
  60. }
  61. export default ItemBox;