【前端】智能库房综合管理系统前端项目
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.

242 lines
7.0 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="time" label="时间" align="center" min-width="60" />
  13. <el-table-column prop="warehouse" label="库房" align="center" min-width="60" />
  14. <el-table-column prop="warning" label="警情" align="center" :show-overflow-tooltip="true" min-width="85" />
  15. </el-table>
  16. </div>
  17. </template>
  18. <script>
  19. import data1 from './data1.json'
  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. },
  32. data() {
  33. return {
  34. tableData: [],
  35. timeout: 1000
  36. }
  37. },
  38. created() {
  39. this.initWebSocket()
  40. },
  41. mounted() {
  42. this.getData()
  43. console.log(11333)
  44. this.$nextTick(() => {
  45. this.tableRefScroll()
  46. })
  47. // this.$nextTick(() => {
  48. // this.scroll = new Bscroll('.warehose-el-table .el-table__body-wrapper', {
  49. // scrollY: true
  50. // ,startY: 10
  51. // })
  52. // this.scroll.on('scrollEnd', () => {
  53. // // let pageIndex = this.scroll.getCurrentPage().pageX;
  54. // // this.currentPageIndex = pageIndex;
  55. // // if(vm.autoPlay) {
  56. // // vm.play();
  57. // // }
  58. // console.log('scrollEnd')
  59. // })
  60. // })
  61. },
  62. destroyed() {
  63. clearInterval(this.timer)
  64. },
  65. methods: {
  66. getData() {
  67. this.tableData = data1.rows
  68. },
  69. // 表格隔行变色
  70. rowBgColor({ row, rowIndex }) {
  71. if (rowIndex % 2 === 1) {
  72. return 'light-blue'
  73. } else {
  74. return ''
  75. }
  76. },
  77. // table滚动
  78. tableRefScroll() {
  79. clearInterval(this.timer) // 清除定时器
  80. const table = this.$refs.table // 获取DOM元素
  81. const wrapperHeight = table.$el.offsetHeight - 30
  82. this.scollNum = Math.floor(wrapperHeight / 40)
  83. const bodyWrapper = table.bodyWrapper // 获取表格中承载数据的div元素
  84. this.addTableRefScroll(bodyWrapper)
  85. // 鼠标移入
  86. bodyWrapper.onmouseover = () => {
  87. clearInterval(this.timer)
  88. }
  89. // 鼠标移出
  90. bodyWrapper.onmouseout = () => {
  91. this.addTableRefScroll(bodyWrapper)
  92. }
  93. },
  94. addTableRefScroll(bodyWrapper) {
  95. let scrollTop = bodyWrapper.scrollTop
  96. this.timer = setInterval(() => {
  97. scrollTop = bodyWrapper.scrollTop
  98. bodyWrapper.scrollTop += this.scollNum * 40
  99. if (scrollTop === bodyWrapper.scrollTop) {
  100. if (this.isScroll) {
  101. scrollTop = 0
  102. bodyWrapper.scrollTop = 0
  103. } else {
  104. if (this.flag === 1) {
  105. this.currentPage++
  106. this.handleSearch() // 函数中需要清楚定时器
  107. }
  108. }
  109. }
  110. }, 1000 * 3 * this.scollNum)
  111. },
  112. initWebSocket() {
  113. const wsUri = process.env.VUE_APP_WS_API + '/webSocket'
  114. this.websock = new WebSocket(wsUri)
  115. this.websock.onerror = this.webSocketOnError
  116. this.websock.onmessage = this.webSocketOnMessage
  117. },
  118. webSocketOnError(e) {
  119. this.$notify({
  120. title: 'WebSocket连接发生错误',
  121. type: 'error',
  122. duration: 0
  123. })
  124. },
  125. webSocketOnMessage(e) {
  126. const data = JSON.parse(e.data)
  127. console.log(data)
  128. if (data.msgType === 'INFO') {
  129. this.$notify({
  130. title: '',
  131. message: data.msg,
  132. type: 'success',
  133. dangerouslyUseHTMLString: true,
  134. duration: 5500
  135. })
  136. } else if (data.msgType === 'ERROR') {
  137. this.$notify({
  138. title: '',
  139. message: data.msg,
  140. dangerouslyUseHTMLString: true,
  141. type: 'error',
  142. duration: 0
  143. })
  144. }
  145. },
  146. webSocketSend(agentData) {
  147. this.websock.send(agentData)
  148. }
  149. // initWebSocket() {
  150. // // if (WebSocket in window) {
  151. // // 初始化weosocket
  152. // const wsUri = process.env.VUE_APP_WS_API + '/webSocket'
  153. // this.websocket = null
  154. // this.websocket = new WebSocket(wsUri)
  155. // this.websocket.onopen = this.websocketonopen
  156. // this.websocket.onerror = this.websocketonerror
  157. // this.websocket.onmessage = this.websocketonmessage
  158. // this.websocket.onclose = this.websocketclose
  159. // // } else {
  160. // // // 浏览器不支持 WebSocket
  161. // // console.log('您的浏览器不支持 WebSocket!')
  162. // // }
  163. // },
  164. // websocketonopen() {
  165. // this.start()
  166. // },
  167. // start() {
  168. // // 开启心跳
  169. // const that = this
  170. // that.timeoutObj && clearTimeout(that.timeoutObj)
  171. // that.timeoutObj = setTimeout(function() {
  172. // // 这里发送一个心跳,后端收到后,返回一个心跳消息,
  173. // if (that.websocket && that.websocket.readyState === 1) {
  174. // // 如果连接正常
  175. // console.log('WebSocket连接成功')
  176. // that.websocket.send('----timingHeart---')
  177. // } else { // 否则重连
  178. // that.reconnect()
  179. // }
  180. // }, that.timeout)
  181. // },
  182. // reconnect() { // 重新连接
  183. // console.log('重新连接')
  184. // const that = this
  185. // if (that.websocket && that.websocket.readyState === 1) {
  186. // clearInterval(that.timeoutnum)
  187. // that.timeoutnum = null
  188. // that.timeNum = 0
  189. // return
  190. // }
  191. // if (!that.timeoutnum) {
  192. // that.timeoutnum = setInterval(function() {
  193. // if (that.websocket && that.websocket.readyState === 1) {
  194. // clearInterval(that.timeoutnum)
  195. // that.timeoutnum = null
  196. // that.timeNum = 0
  197. // return
  198. // }
  199. // // 新连接
  200. // that.initWebSocket()
  201. // that.timeNum++
  202. // if (that.timeNum >= 3) {
  203. // clearInterval(that.timeoutnum)
  204. // that.timeoutnum = null
  205. // that.timeNum = 0
  206. // }
  207. // }, 1000)
  208. // }
  209. // },
  210. // websocketonerror(e) {
  211. // // 错误
  212. // // this.initWebSocket()
  213. // console.log('WebSocket连接发生错误')
  214. // },
  215. // websocketonmessage(e) {
  216. // // 数据接收
  217. // var data = JSON.parse(e.data)
  218. // // this.$store.commit('SET_ws', data)
  219. // console.log('接收数据', data)
  220. // // 操作处理...
  221. // },
  222. // websocketclose(e) {
  223. // // 关闭
  224. // this.websocket && this.websocket.close && this.websocket.close()
  225. // }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. @import "~@/assets/styles/lend-manage.scss";
  231. .warehouse-left {
  232. position: relative;
  233. h2 {
  234. position: absolute;
  235. left: 50%;
  236. top: 0;
  237. transform: translateX(-50%);
  238. color: #fff;
  239. font-size: 16px;
  240. }
  241. }
  242. </style>