index.jsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. this.handleFocus = this.handleFocus.bind(this);
  17. }
  18. handleInput(e){
  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,idx);
  23. //右侧推送--延时推送
  24. clearTimeout(stimer);
  25. let timer = setTimeout(function(){
  26. handlePush&&handlePush();
  27. clearTimeout(stimer);
  28. },config.delayPushTime);
  29. if(text.trim() != '' && text != '<br>'){
  30. e.target.nextSibling.innerText?(e.target.nextSibling.innerText = ''):(e.target.nextSibling.innerHTML = '')
  31. }else{
  32. e.target.nextSibling.innerText?(e.target.nextSibling.innerText = '报告描述或意见'):(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. if(next.value && next.value.trim()){
  49. this.$dom.current.nextSibling.innerText = ''
  50. }else{
  51. this.$dom.current.nextSibling.innerHTML = '报告描述或意见'
  52. }
  53. }
  54. }
  55. componentDidMount(){
  56. const {value} = this.props;
  57. if(value && value.trim()){
  58. this.$dom.current.innerText?(this.$dom.current.innerText = value) : (this.$dom.current.innerHTML = value)
  59. this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = ''):(this.$dom.current.nextSibling.innerHTML = '')
  60. }else{
  61. this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = '报告描述或意见'):(this.$dom.current.nextSibling.innerHTML = '报告描述或意见')
  62. }
  63. }
  64. handleFocus(){ //ie8下提示语挡住输入框,导致输入框无法聚焦
  65. this.textInput.current.previousSibling.focus();
  66. }
  67. render() {
  68. const {idx,disabled} = this.props;
  69. return (
  70. <div className={style.textWap}>
  71. <div className={style.divTextarea}
  72. contenteditable={disabled?false:true}
  73. ref={this.$dom}
  74. onInput={this.handleInput}
  75. onKeyUp={this.handleInput}
  76. ></div>
  77. <p ref={this.textInput} onClick={this.handleFocus} className={style.textareaWarring}></p>
  78. </div>
  79. );
  80. }
  81. }
  82. export default Textarea;