index.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { Component } from "react";
  2. import style from "./index.less";
  3. import config from '@config/index';
  4. import $ from 'jquery';
  5. class Textarea extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. timer:null,
  10. val:'报告描述或意见'
  11. };
  12. this.textInput = React.createRef();
  13. this.$dom = React.createRef();
  14. this.$domW = React.createRef();
  15. this.handleInput = this.handleInput.bind(this);
  16. }
  17. handleInput(e){
  18. e.stopPropagation();
  19. const {handleChangeAssistValue,idx,handlePush} = this.props;
  20. const text = e.target.innerText || e.target.innerHTML;
  21. const stimer = this.state.timer;
  22. handleChangeAssistValue&&handleChangeAssistValue(text);
  23. }
  24. shouldComponentUpdate(next){
  25. if(JSON.stringify(next) == JSON.stringify(this.props)){
  26. return false;
  27. }
  28. return true;
  29. }
  30. componentWillReceiveProps(next){
  31. const isRead = this.props.isRead;
  32. // if(next.isRead != isRead && next.value!=this.props.value){ //value对比解决复诊不显示bug
  33. // next.value ? this.$dom.current.innerText = next.value : this.$dom.current.innerText = next.value
  34. // // this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
  35. // }
  36. if(next.isRead != isRead && next.value || next.isRead != isRead && next.value!=this.props.value){ //value对比解决复诊不显示bug
  37. next.value ? this.$dom.current.innerText = next.value : this.$dom.current.innerText = ''
  38. // this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
  39. }
  40. }
  41. componentDidMount(){
  42. const {value} = this.props;
  43. if(value && value.trim()){
  44. this.$dom.current.innerText = value
  45. // this.$dom.current.focus()
  46. // this.$dom.current.innerText ? (this.$dom.current.innerText = value) : (this.$dom.current.innerHTML = value)
  47. // this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = ''):(this.$dom.current.nextSibling.innerHTML = '')
  48. }
  49. }
  50. render() {
  51. return (
  52. <div>
  53. <div
  54. style={{outline: 'none'}}
  55. contenteditable={true}
  56. ref={this.$dom}
  57. onInput={this.handleInput}
  58. onKeyUp={this.handleInput}
  59. ></div>
  60. </div>
  61. );
  62. }
  63. }
  64. export default Textarea;