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

135 lines
3.7 KiB

3 years ago
3 years ago
  1. <template>
  2. <div class="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="menjin" class-name="warehouse-svg" />门禁记录
  8. </p>
  9. </h3>
  10. <el-table ref="table" style="min-width: 100%;" :height="height" :data="tableData" class="warehose-el-table" stripe>
  11. <el-table-column prop="update_time" label="时间" align="center" min-width="60">
  12. <template slot-scope="scope">
  13. <div>{{ scope.row.update_time | parseTime }}</div>
  14. </template>
  15. </el-table-column>
  16. <el-table-column label="库房" align="center" min-width="30">
  17. <template>
  18. 档案库
  19. </template>
  20. </el-table-column>
  21. <el-table-column prop="alarmMsg" label="警情" align="center" :show-overflow-tooltip="true" min-width="85" />
  22. </el-table>
  23. </div>
  24. </template>
  25. <script>
  26. import { securitydoor } from '@/api/home/securityDoor/securityDoor'
  27. export default {
  28. name: 'SecurityDoor',
  29. props: {
  30. width: {
  31. type: String,
  32. default: '100%'
  33. },
  34. height: {
  35. type: String,
  36. default: '100%'
  37. }
  38. },
  39. data() {
  40. return {
  41. tableData: [], // 正在展示的数据
  42. scrollTimer: null,
  43. getDataTimer: null
  44. }
  45. },
  46. watch: {
  47. // 如果 `tableData` 发生改变,这个函数就会运行
  48. tableData: function(newData, oldData) {
  49. this.tableRefScroll()
  50. }
  51. },
  52. created() {
  53. this.getSecuritydoor()
  54. },
  55. destroyed() {
  56. clearInterval(this.scrollTimer)
  57. this.scrollTimer = null
  58. },
  59. methods: {
  60. // 表格隔行变色
  61. rowBgColor({ row, rowIndex }) {
  62. if (rowIndex % 2 === 1) {
  63. return 'light-blue'
  64. } else {
  65. return ''
  66. }
  67. },
  68. // table滚动
  69. tableRefScroll() {
  70. clearInterval(this.scrollTimer) // 清除定时器
  71. const table = this.$refs.table // 获取DOM元素
  72. this.wrapperHeight = table.$el.offsetHeight - 30
  73. // 组件一页能完整展示的数据条数
  74. this.displayNum = Math.floor(this.wrapperHeight / 40)
  75. if (this.tableData.length > this.displayNum) {
  76. const bodyWrapper = table.bodyWrapper // 获取表格中承载数据的div元素
  77. this.addTableRefScroll(bodyWrapper)
  78. // 鼠标移入
  79. bodyWrapper.onmouseover = () => {
  80. clearInterval(this.scrollTimer)
  81. }
  82. // 鼠标移出
  83. bodyWrapper.onmouseout = () => {
  84. this.addTableRefScroll(bodyWrapper)
  85. }
  86. } else {
  87. this.scrollTimer = setInterval(() => {
  88. this.getSecuritydoor()
  89. }, 1000 * 3 * this.tableData.length)
  90. }
  91. },
  92. addTableRefScroll(bodyWrapper) {
  93. // let scrollTop = bodyWrapper.scrollTop
  94. if (this.displayNum && this.displayNum > 0) {
  95. this.scrollTimer = setInterval(() => {
  96. // scrollTop = bodyWrapper.scrollTop
  97. if (bodyWrapper.scrollTop + this.wrapperHeight >= this.tableData.length * 40) {
  98. this.getSecuritydoor()
  99. } else {
  100. bodyWrapper.scrollTop += this.displayNum * 40
  101. }
  102. }, 1000 * 3 * this.displayNum)
  103. }
  104. },
  105. getSecuritydoor() {
  106. securitydoor().then((data) => {
  107. if (data && data.length > 0) {
  108. this.tableData.splice(0, data.length, ...data)
  109. }
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. @import "~@/assets/styles/lend-manage.scss";
  117. .warehouse-left {
  118. position: relative;
  119. h2 {
  120. position: absolute;
  121. left: 50%;
  122. top: 0;
  123. transform: translateX(-50%);
  124. color: #fff;
  125. font-size: 16px;
  126. }
  127. }
  128. ::v-deep
  129. .el-table--striped
  130. .el-table__body
  131. tr.el-table__row--striped
  132. td.el-table__cell {
  133. background: #02255f;
  134. }
  135. </style>