index.jsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React,{Component} from 'react';
  2. import style from './index.less';
  3. import {isIE} 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. componentDidMount(){
  40. if(isIE()){
  41. $(this.$div.current).onIe8Input(function(e){
  42. this.handleInput(e)
  43. },this);
  44. }
  45. }
  46. render(){
  47. const {title,children,editable,className,handleFocus,onchange,fuzhen,border,handleBlur,titleTop,backgroundColor} = this.props;
  48. return <div className={style["box"]+" "+"clearfix"} >
  49. <div className={style["title"] + ' ' + className} style={{marginTop:titleTop?'22px':''}}>{title}</div>
  50. <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}>
  51. {fuzhen?children||fuzhen:children}
  52. </div>
  53. </div>
  54. }
  55. }
  56. export default ItemBox;