index.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.$dom = React.createRef();
  13. this.$domW = React.createRef();
  14. this.handleInput = this.handleInput.bind(this);
  15. }
  16. handleInput(e){
  17. const {handleChangeAssistValue,idx,handlePush} = this.props;
  18. const text = e.target.innerText || e.target.innerHTML;
  19. const stimer = this.state.timer;
  20. handleChangeAssistValue&&handleChangeAssistValue(text,idx);
  21. //右侧推送--延时推送
  22. clearTimeout(stimer);
  23. let timer = setTimeout(function(){
  24. handlePush&&handlePush();
  25. clearTimeout(stimer);
  26. },config.delayPushTime);
  27. if(text.trim() != '' && text != '<br>'){
  28. e.target.nextSibling.innerText = ''
  29. e.target.nextSibling.innerHTML = ''
  30. }else{
  31. e.target.nextSibling.innerText = '报告描述或意见'
  32. e.target.nextSibling.innerHTML = '报告描述或意见'
  33. }
  34. this.setState({
  35. timer
  36. });
  37. }
  38. shouldComponentUpdate(next){
  39. if(JSON.stringify(next) == JSON.stringify(this.props)){
  40. return false;
  41. }
  42. return true;
  43. }
  44. componentWillReceiveProps(next){
  45. const isRead = this.props.isRead;
  46. if(next.isRead != isRead){
  47. this.$dom.current.innerText?(this.$dom.current.innerText = next.value||'') : (this.$dom.current.innerHTML = next.value||'')
  48. }
  49. }
  50. componentDidMount(){
  51. const {value} = this.props;
  52. if(value && value.trim()){
  53. this.$dom.current.innerText?(this.$dom.current.innerText = value) : (this.$dom.current.innerHTML = value)
  54. this.$dom.current.nextSibling.innerText = '';
  55. this.$dom.current.nextSibling.innerHTML = '';
  56. }else{
  57. this.$dom.current.nextSibling.innerText = '报告描述或意见'
  58. this.$dom.current.nextSibling.innerHTML = '报告描述或意见'
  59. }
  60. }
  61. render() {
  62. const {idx} = this.props;
  63. return (
  64. <div className={style.textWap}>
  65. <div className={style.divTextarea}
  66. contenteditable={true}
  67. ref={this.$dom}
  68. onInput={this.handleInput}
  69. onPropertyChange={this.handleInput}
  70. ></div>
  71. <p style={{position: "absolute",left: '0',top: '0',color: "#a5a3a3",zIndex: '5'}} className="textareaWarring"></p>
  72. </div>
  73. );
  74. }
  75. }
  76. export default Textarea;