【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div class="warehouse-right container-wrap">
  3. <span class="right-top-line" />
  4. <span class="left-bottom-line" />
  5. <h3 class=" table-title">
  6. <p class="title-arrow">
  7. <svg-icon icon-class="alerm" class-name="warehouse-svg" />报警记录
  8. </p>
  9. </h3>
  10. <!--表格渲染-->
  11. <el-table ref="table" style="min-width: 100%;" :width="width" :height="height" :data="tableData" class="warehose-el-table" :row-class-name="rowBgColor">
  12. <el-table-column prop="alarm_time" label="时间" align="center" min-width="70" />
  13. <el-table-column prop="area_name" label="库房" align="center" min-width="35" />
  14. <el-table-column prop="event_name" label="警情" align="center" :show-overflow-tooltip="true" min-width="85" />
  15. </el-table>
  16. </div>
  17. </template>
  18. <script>
  19. import alarmApi from '@/api/home/alarm'
  20. export default {
  21. name: 'WarehouseWarning',
  22. props: {
  23. width: {
  24. type: String,
  25. default: '100%'
  26. },
  27. height: {
  28. type: String,
  29. default: '100%'
  30. },
  31. storeroomId: {
  32. type: String,
  33. default: ''
  34. }
  35. },
  36. data() {
  37. return {
  38. tableData: [], // 正在展示的警情数据
  39. // receivedData: [], // 接收到的最新警情数据
  40. // displayNum: 0,
  41. // lockReconnect: false, // 避免重复连接
  42. // heartCheck: {
  43. // timeout: 3000,
  44. // timeoutobj: null,
  45. // // serverTimeoutObj: null,
  46. // start: () => {
  47. // // const that = this
  48. // clearTimeout(this.timeoutObj)
  49. // // clearTimeout(this.serverTimeoutObj)
  50. // this.timeoutobj = setTimeout(() => {
  51. // // 这里发送一个心跳,后端收到后,返回一个心跳,这里用的ping-pong
  52. // this.socket.send('ping')
  53. // // that.serverTimeoutObj = setTimeout(() => {
  54. // // this.socket.close()
  55. // // }, that.timeout)
  56. // }, this.timeout)
  57. // }
  58. // }
  59. socket: null
  60. }
  61. },
  62. watch: {
  63. // 如果 `tableData` 发生改变,这个函数就会运行
  64. tableData: function(newData, oldData) {
  65. this.tableRefScroll()
  66. }
  67. },
  68. created() {
  69. // securitydoor().then((data) => {
  70. // this.tableData.push(...data)
  71. // })
  72. // this.openSocket()
  73. console.log(111111)
  74. alarmApi.info({ storeroomId: this.storeroomId }).then((data) => {
  75. if (data && data.length > 0) {
  76. this.tableData.push(...data)
  77. }
  78. })
  79. },
  80. destroyed() {
  81. clearInterval(this.timer)
  82. if (this.socket) {
  83. this.socket.close()
  84. }
  85. },
  86. methods: {
  87. // 表格隔行变色
  88. rowBgColor({ row, rowIndex }) {
  89. if (rowIndex % 2 === 1) {
  90. return 'light-blue'
  91. } else {
  92. return ''
  93. }
  94. },
  95. // table滚动
  96. tableRefScroll() {
  97. clearInterval(this.timer) // 清除定时器
  98. const table = this.$refs.table // 获取DOM元素
  99. const wrapperHeight = table.$el.offsetHeight - 30
  100. // 组件一页能展示的数据条数
  101. this.displayNum = Math.floor(wrapperHeight / 40)
  102. if (this.tableData.length > this.displayNum) {
  103. const bodyWrapper = table.bodyWrapper // 获取表格中承载数据的div元素
  104. this.addTableRefScroll(bodyWrapper)
  105. // 鼠标移入
  106. bodyWrapper.onmouseover = () => {
  107. clearInterval(this.timer)
  108. }
  109. // 鼠标移出
  110. bodyWrapper.onmouseout = () => {
  111. this.addTableRefScroll(bodyWrapper)
  112. }
  113. }
  114. },
  115. addTableRefScroll(bodyWrapper) {
  116. // let scrollTop = bodyWrapper.scrollTop
  117. if (this.displayNum && this.displayNum > 0) {
  118. this.timer = setInterval(() => {
  119. // scrollTop = bodyWrapper.scrollTop
  120. if (Math.round(bodyWrapper.scrollTop / 40) >= this.tableData.length - this.displayNum) {
  121. bodyWrapper.scrollTop = 0
  122. } else {
  123. bodyWrapper.scrollTop += this.displayNum * 40
  124. }
  125. // if (scrollTop === bodyWrapper.scrollTop) {
  126. // if (this.isScroll) {
  127. // scrollTop = 0
  128. // bodyWrapper.scrollTop = 0
  129. // } else {
  130. // if (this.flag === 1) {
  131. // this.currentPage++
  132. // this.handleSearch() // 函数中需要清楚定时器
  133. // }
  134. // }
  135. // }
  136. }, 1000 * 3 * this.displayNum)
  137. }
  138. }
  139. // ,
  140. // openSocket() {
  141. // if (!('WebSocket' in window)) {
  142. // console.log('您的浏览器不支持WebSocket')
  143. // } else {
  144. // console.log('您的浏览器支持WebSocket')
  145. // const socketUrl = process.env.VUE_APP_WS_API + '/webSocket'
  146. // if (this.socket != null) {
  147. // this.socket.close()
  148. // this.socket = null
  149. // }
  150. // this.socket = new WebSocket(socketUrl)
  151. // // 打开事件
  152. // this.socket.onopen = () => {
  153. // console.log('websocket已经打开')
  154. // // 心跳检测重置
  155. // // this.heartCheck.start()
  156. // }
  157. // // 获得消息
  158. // this.socket.onmessage = (msg) => {
  159. // console.log(msg)
  160. // this.tableData.splice(0, this.tableData.length, ...JSON.parse(msg.data.slice(7, msg.data.length - 2)).Data)
  161. // // 对返回数据进行处理
  162. // // this.heartCheck.start()
  163. // }
  164. // // 关闭事件
  165. // this.socket.onclose = function() {
  166. // console.log('websocket已关闭')
  167. // }
  168. // // 发生了错误事件
  169. // this.socket.onerror = function(e) {
  170. // console.log('websocket发生了错误')
  171. // console.log(e)
  172. // }
  173. // }
  174. // }
  175. }
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. @import "~@/assets/styles/lend-manage.scss";
  180. .warehouse-left {
  181. position: relative;
  182. h2 {
  183. position: absolute;
  184. left: 50%;
  185. top: 0;
  186. transform: translateX(-50%);
  187. color: #fff;
  188. font-size: 16px;
  189. }
  190. }
  191. </style>