MessBox.jsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React from 'react';
  2. import Message from "./Message.jsx";
  3. import "antd/dist/antd.css";
  4. import "../../assets/css/App.css";
  5. import MessageDialog from './MessageDialog.jsx';
  6. import headMes from "../../assets/images/header-message.png";
  7. import headMes2 from "../../assets/images/header-message2.png";
  8. import {Tooltip} from "antd";
  9. class MessBox extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. messageCount: 0,
  14. dataSource:[],
  15. visible:true,
  16. }
  17. }
  18. componentWillUnmount() {
  19. if (this.messageTimer) {
  20. clearInterval(this.messageTimer);
  21. this.messageTimer = null;
  22. }
  23. this.setState = (state, callback) => {
  24. return;
  25. };
  26. }
  27. // 消息列表
  28. showMessage = (event) => {
  29. event.stopPropagation();
  30. this.messageRef.show();
  31. };
  32. /**
  33. * 消息定时器任务
  34. * @author changeBy: DYK
  35. * @param ref
  36. * @param stutus
  37. */
  38. onMessageRef = (ref) => {
  39. this.messageRef = ref;
  40. if (this.messageTimer) {
  41. clearInterval(this.messageTimer);
  42. }
  43. this.messageTimer = setInterval(() => {
  44. ref.recordData();
  45. }, 60000);
  46. };
  47. onMessageDialogRef = (ref) =>{
  48. this.onMessageDialog = ref
  49. }
  50. render() {
  51. let showMessagePopUp = window.sessionStorage ? window.sessionStorage.getItem("showMessagePopUp") : "Y";
  52. let content = "";
  53. let showMessagePopUpFlag="N";
  54. this.state.dataSource.map((item, index) => {
  55. if (item.showDialog == 'Y') {
  56. showMessagePopUpFlag="Y";
  57. }
  58. })
  59. //头菜单
  60. if (this.props.position == "top") {
  61. content = (
  62. <span style={{ marginRight: "4px", cursor: "pointer", position: "relative" }} className="side-badge" onClick={this.showMessage}>
  63. {/*changeBy: DYK*/}
  64. <Message onRef={this.onMessageRef} handlerThis={this}></Message>
  65. <span style={{
  66. backgroundColor: "#ff00ff",
  67. color: "#fff",
  68. position: "absolute",
  69. right: "-4px",
  70. top: "-12px",
  71. height: "16px",
  72. lineHeight: "16px",
  73. borderRadius: "50%",
  74. width: "20px",
  75. alignItems: "center",
  76. justifyContent: "center",
  77. padding: "12px",
  78. fontSize: "12px",
  79. display: this.state.messageCount && this.state.messageCount > 0 ? "flex" : "none"
  80. }}>
  81. {
  82. this.state.messageCount && this.state.messageCount > 99 ? "99+" : this.state.messageCount
  83. }
  84. </span>
  85. <MessageDialog dataSource={this.state.dataSource} visible={(this.state.visible) && (showMessagePopUpFlag!=="N") && showMessagePopUp !== "N"} onRef={this.onMessageDialogRef} handlerThis={this} />
  86. {/*<span style={{ color: "#fff", }}>{this.state.localeProvider && this.state.localeProvider.MoreEditMessageNotification ? this.setMessage('MoreEditMessageNotification', 'descripts') : "消息提醒"} </span>*/}
  87. <Tooltip title="消息提醒">
  88. <img style={{width: "26px", height: "26px", marginRight: "10px"}} src={headMes}/>
  89. </Tooltip>
  90. </span>
  91. )
  92. }
  93. else {
  94. //侧菜单
  95. content = (
  96. <span style={{ marginRight: "4px", cursor: "pointer", position: "relative" }} className="side-badge" onClick={this.showMessage}>
  97. <Message onRef={this.onMessageRef} handlerThis={this}></Message>
  98. <span style={{
  99. backgroundColor: "#ff00ff",
  100. color: "#fff",
  101. position: "absolute",
  102. right: "-4px",
  103. top: "-12px",
  104. // display: "flex",
  105. height: "16px",
  106. lineHeight: "16px",
  107. borderRadius: "50%",
  108. width: "20px",
  109. alignItems: "center",
  110. justifyContent: "center",
  111. padding: "12px",
  112. fontSize: "12px",
  113. display: this.state.messageCount && this.state.messageCount > 0 ? "flex" : "none"
  114. }}>
  115. {
  116. this.state.messageCount && this.state.messageCount > 99 ? "99+" : this.state.messageCount
  117. }
  118. </span>
  119. <MessageDialog dataSource={this.state.dataSource} visible={(this.state.visible) && (showMessagePopUpFlag!=="N") && showMessagePopUp !== "N"} onRef={this.onMessageDialogRef} handlerThis={this} />
  120. {/*<span style={{ color: "rgb(102, 102, 102)", }}>{this.state.localeProvider && this.state.localeProvider.MoreEditMessageNotification ? this.setMessage('MoreEditMessageNotification', 'descripts') : "消息提醒"} </span>*/}
  121. <Tooltip title="消息提醒">
  122. <img style={{width: "26px", height: "26px", marginRight: "20px"}} src={headMes2}/>
  123. </Tooltip>
  124. </span>
  125. )
  126. }
  127. return content
  128. }
  129. }
  130. export default MessBox