tabroll.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="tabroll-wrap cockpit-tabroll-table">
  3. <el-table
  4. :show-header="false"
  5. v-loading="shujuloading"
  6. :data="tableData"
  7. :max-height="maxHeight"
  8. ref="shujuscroll_Table"
  9. strip
  10. style="width: 100%"
  11. @mouseenter.native="shujuautoScroll(true)"
  12. @mouseleave.native="shujuautoScroll(false)"
  13. id="Tabtab"
  14. >
  15. <el-table-column
  16. v-for="(column, index) in columns"
  17. :key="index"
  18. :prop="column.prop"
  19. :label="column.label"
  20. show-overflow-tooltip
  21. :width="getColumnWidth(column.prop)"
  22. :min-width="getColumnMinWidth(column.prop)"
  23. />
  24. </el-table>
  25. </div>
  26. </template>
  27. <script>
  28. import { COCKPIT_TABLE_BODY_HEIGHT } from "./cockpitTableMetrics";
  29. export default {
  30. props: {
  31. tableData: {
  32. type: Array,
  33. default: () => [],
  34. },
  35. shujuloading: {
  36. type: Boolean,
  37. default: false,
  38. },
  39. tableTitle: {
  40. type: String,
  41. default: "",
  42. },
  43. columns: {
  44. type: Array,
  45. default: () => [],
  46. },
  47. maxHeight: {
  48. type: Number,
  49. default: COCKPIT_TABLE_BODY_HEIGHT,
  50. },
  51. columnWidths: {
  52. type: Object,
  53. default: () => ({}),
  54. },
  55. YCcolumnWidths: {
  56. type: Object,
  57. default: () => ({}),
  58. },
  59. },
  60. mounted() {
  61. this.$nextTick(() => this.shujuautoScroll());
  62. },
  63. watch: {
  64. tableData() {
  65. this.$nextTick(() => {
  66. this.shujuautoScroll(true);
  67. this.shujuautoScroll();
  68. });
  69. },
  70. },
  71. beforeDestroy() {
  72. this.shujuautoScroll(true);
  73. },
  74. methods: {
  75. shujuautoScroll(stop) {
  76. if (stop) {
  77. window.clearInterval(this.scrolltimer);
  78. this.scrolltimer = null;
  79. return;
  80. }
  81. const table = this.$refs.shujuscroll_Table;
  82. const divData = table && table.$refs.bodyWrapper;
  83. if (!divData || !this.tableData || this.tableData.length === 0) {
  84. return;
  85. }
  86. if (divData.scrollHeight <= divData.clientHeight) {
  87. return;
  88. }
  89. window.clearInterval(this.scrolltimer);
  90. this.scrolltimer = window.setInterval(() => {
  91. divData.scrollTop += 1;
  92. if (
  93. divData.clientHeight + divData.scrollTop >=
  94. divData.scrollHeight
  95. ) {
  96. divData.scrollTop = 0;
  97. }
  98. }, 150);
  99. },
  100. getColumnWidth(prop) {
  101. const w =
  102. this.columnWidths[prop] ?? this.YCcolumnWidths[prop];
  103. if (w == null || w === "auto") return undefined;
  104. if (typeof w === "string" && w.endsWith("%")) return undefined;
  105. if (typeof w === "string") return w;
  106. return `${w}px`;
  107. },
  108. getColumnMinWidth(prop) {
  109. const w =
  110. this.columnWidths[prop] ?? this.YCcolumnWidths[prop];
  111. if (typeof w === "string" && w.endsWith("%")) {
  112. return w;
  113. }
  114. return undefined;
  115. },
  116. tableRowClassName({ row, rowIndex }) {
  117. if (rowIndex % 2 === 1) {
  118. return "warning-row";
  119. } else {
  120. return "success-row";
  121. }
  122. },
  123. },
  124. };
  125. </script>
  126. <style lang="scss" scoped>
  127. .tabroll-wrap {
  128. width: 100%;
  129. }
  130. #Tabtab {
  131. width: 100% !important;
  132. font-size: 12px;
  133. }
  134. ::v-deep #Tabtab .el-table__body,
  135. ::v-deep #Tabtab .el-table__body-wrapper table {
  136. width: 100% !important;
  137. table-layout: fixed;
  138. }
  139. ::v-deep .cockpit-tabroll-table .el-table__body .el-table__cell {
  140. padding: 0 !important;
  141. }
  142. ::v-deep .cockpit-tabroll-table .el-table__body .el-table__cell .cell {
  143. padding-top: 0 !important;
  144. padding-bottom: 0 !important;
  145. padding-left: var(--cockpit-td-padding-x, 8px) !important;
  146. padding-right: var(--cockpit-td-padding-x, 8px) !important;
  147. }
  148. /* 去掉最下面的那一条线 */
  149. .el-table::before {
  150. height: 0px;
  151. }
  152. /* 自动滚动:隐藏滚动条 */
  153. ::v-deep .cockpit-tabroll-table .el-table__body-wrapper {
  154. scrollbar-width: none;
  155. -ms-overflow-style: none;
  156. }
  157. ::v-deep .cockpit-tabroll-table .el-table__body-wrapper::-webkit-scrollbar {
  158. width: 0 !important;
  159. height: 0 !important;
  160. display: none !important;
  161. }
  162. </style>