黄陂项目
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.

208 lines
7.0 KiB

4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months 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" @click="toPage">
  6. <p class="title-arrow" style="cursor: pointer;">
  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" @row-click="toPage">
  12. <el-table-column prop="TS" label="时间" align="center" width="160">
  13. <template slot-scope="scope">
  14. <span v-if="scope.row.TS">{{ scope.row.TS | formatTs }}</span>
  15. <!-- <span v-if="scope.row.TS">{{ scope.row.TS | parseTime }}</span> -->
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="siteName" label="设备" align="center" :show-overflow-tooltip="true" :width="isScreen ? 112 :''">
  19. <template slot-scope="scope">
  20. <!-- siteName = "环境监控.空气净化机" -->
  21. <span>{{ getDeviceName(scope.row.siteName) }}</span>
  22. </template>
  23. </el-table-column>
  24. <el-table-column prop="value" label="警情" align="center" :show-overflow-tooltip="true" :width="isScreen ? 136 :''" />
  25. </el-table>
  26. </div>
  27. </template>
  28. <script>
  29. import alarmApi from '@/api/home/alarm'
  30. import { mapGetters } from 'vuex'
  31. export default {
  32. name: 'WarehouseWarning',
  33. props: {
  34. isScreen: {
  35. type: Boolean,
  36. default: false
  37. },
  38. width: {
  39. type: String,
  40. default: '100%'
  41. },
  42. height: {
  43. type: String,
  44. default: '100%'
  45. },
  46. storeroomId: {
  47. type: String,
  48. default: ''
  49. }
  50. },
  51. data() {
  52. return {
  53. tableData: [], // 正在展示的警情数据
  54. scrollTimer: null
  55. }
  56. },
  57. computed: {
  58. ...mapGetters([
  59. 'roles'
  60. ])
  61. },
  62. watch: {
  63. // 如果 `tableData` 发生改变,这个函数就会运行
  64. // tableData: function(newData, oldData) {
  65. // this.tableRefScroll()
  66. // }
  67. },
  68. created() {
  69. this.getAlarmInfo()
  70. },
  71. mounted() {
  72. this.scrollTimer = setInterval(() => {
  73. this.getAlarmInfo()
  74. }, 15000)
  75. },
  76. destroyed() {
  77. clearInterval(this.scrollTimer)
  78. this.scrollTimer = null
  79. },
  80. methods: {
  81. getDeviceName(siteName) {
  82. if (!siteName) return ''
  83. const parts = siteName.split('.')
  84. return parts.length > 1 ? parts[1] : siteName
  85. },
  86. toPage() {
  87. this.$router.push({
  88. name: 'RunningLog',
  89. params: {
  90. locationIndex: 0
  91. }
  92. })
  93. // if (this.roles.includes('admin') || this.roles.includes('RunningLog:list')) {
  94. // } else {
  95. // this.$message({
  96. // message: '当前账号没有权限',
  97. // type: 'warning'
  98. // })
  99. // }
  100. },
  101. // 表格隔行变色
  102. rowBgColor({ row, rowIndex }) {
  103. if (rowIndex % 2 === 1) {
  104. return 'light-blue'
  105. } else {
  106. return ''
  107. }
  108. },
  109. // table滚动
  110. tableRefScroll() {
  111. clearInterval(this.scrollTimer) // 清除定时器
  112. const table = this.$refs.table // 获取DOM元素
  113. this.wrapperHeight = table.$el.offsetHeight - 30
  114. // 组件一页能完整展示的数据条数
  115. this.displayNum = Math.floor(this.wrapperHeight / 40)
  116. if (this.tableData.length > this.displayNum) {
  117. const bodyWrapper = table.bodyWrapper // 获取表格中承载数据的div元素
  118. this.addTableRefScroll(bodyWrapper)
  119. // 鼠标移入
  120. bodyWrapper.onmouseover = () => {
  121. clearInterval(this.scrollTimer)
  122. }
  123. // 鼠标移出
  124. bodyWrapper.onmouseout = () => {
  125. this.addTableRefScroll(bodyWrapper)
  126. }
  127. } else {
  128. this.scrollTimer = setInterval(() => {
  129. this.getAlarmInfo()
  130. }, 15000)
  131. // * this.tableData.length
  132. }
  133. },
  134. addTableRefScroll(bodyWrapper) {
  135. // let scrollTop = bodyWrapper.scrollTop
  136. if (this.displayNum && this.displayNum > 0) {
  137. this.scrollTimer = setInterval(() => {
  138. // scrollTop = bodyWrapper.scrollTop
  139. if (bodyWrapper.scrollTop + this.wrapperHeight >= this.tableData.length * 40) {
  140. bodyWrapper.scrollTop = 0
  141. this.getAlarmInfo()
  142. } else {
  143. bodyWrapper.scrollTop += this.displayNum * 40
  144. }
  145. // if (scrollTop === bodyWrapper.scrollTop) {
  146. // if (this.isScroll) {
  147. // scrollTop = 0
  148. // bodyWrapper.scrollTop = 0
  149. // } else {
  150. // if (this.flag === 1) {
  151. // this.currentPage++
  152. // this.handleSearch() // 函数中需要清楚定时器
  153. // }
  154. // }
  155. // }
  156. }, 15000)
  157. // * this.displayNum
  158. console.log('this.displayNum', this.displayNum)
  159. }
  160. },
  161. getAlarmInfo() {
  162. // this.tableData = [{"alarmid": "88347b05","lscid": 1,"WYID":"192.168.99.101:5004_1","Itemlevels":7, "siteName": "环境监控.空气净化机", "TS":"2026/1/6 15:08:56", "id":11955, "isAD":1,"type":0,"IP":" 192.168.99.101:5004 ","name":"串口", "value":"无响应", "dw":"", "ItemClass":3},{"alarmid": "4b232d46","lscid": 1,"WYID":"192.168.99.101:5003_1","Itemlevels":7, "siteName": "环境监控.恒湿净化机", "TS":"2026/1/6 16:13:31", "id":11922, "isAD":1,"type":0,"IP":" 192.168.99.101:5003 ","name":"串口", "value":"无响应", "dw":"", "ItemClass":1},{"alarmid": "3a309a0a","lscid": 9,"WYID":"192.168.99.101:6003_9","Itemlevels":7, "siteName": "环境监控.环控设备监测", "TS":"2026/1/6 16:18:33", "id":12061, "isAD":1,"type":0,"IP":" 192.168.99.101:6003 ","name":"红外感应", "value":"OFF", "dw":"", "ItemClass":3},{"alarmid": "63df6a30","lscid": 1,"WYID":"192.168.99.101:5005_1","Itemlevels":7, "siteName": "环境监控.温湿度传感器", "TS":"2026/1/6 16:19:58", "id":11305, "isAD":1,"type":0,"IP":" 192.168.99.101:5005 ","name":"串口", "value":"无响应", "dw":"", "ItemClass":1}]
  163. // this.tableData = [
  164. // {
  165. // 'id': 'eb6b8653',
  166. // 'lscid': 0,
  167. // 'wyid': '',
  168. // 'itemLevels': 1,
  169. // 'siteName': '.环境监控',
  170. // 'TS': 1765944141000,
  171. // 'isAd': true,
  172. // 'type': 0,
  173. // 'ip': '192.168.99.101:6003',
  174. // 'name': '开关量',
  175. // 'value': '设备断线',
  176. // 'dw': '',
  177. // 'itemClass': 1
  178. // }
  179. // ]
  180. // name 6字 说明 7 字
  181. alarmApi.info({ storeroomId: this.storeroomId }).then((data) => {
  182. this.tableData = []
  183. if (data && data.length > 0) {
  184. // this.tableData.splice(0, data.length, ...data)
  185. this.tableData = data
  186. } else {
  187. this.tableData = []
  188. }
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. @import "~@/assets/styles/lend-manage.scss";
  196. .warehouse-left {
  197. position: relative;
  198. h2 {
  199. position: absolute;
  200. left: 50%;
  201. top: 0;
  202. transform: translateX(-50%);
  203. color: #fff;
  204. font-size: 16px;
  205. }
  206. }
  207. </style>