Table.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="page_table">
  3. <el-table
  4. class="el-table--border"
  5. ref="tableRef"
  6. :show-header="showHeader"
  7. :data="tableData"
  8. stripe
  9. v-loading="loading"
  10. element-loading-text="拼命加载中……"
  11. element-loading-spinner="el-icon-loading"
  12. element-loading-background="#ffffff"
  13. element-loading-custom-class="loading_icon"
  14. :row-class-name="tableRowClassName"
  15. @row-click="(row, column) => $emit('rowClick', row)"
  16. :span-method="spanMethod"
  17. >
  18. <template v-for="(item, index) in tableColumns">
  19. <el-table-column
  20. :key="item?.name"
  21. v-if="!item.hidden"
  22. :prop="item.name"
  23. :min-width="item.minWidth"
  24. :width="item.width"
  25. :label="item.label"
  26. :fixed="item.fixed ? item.fixed : false"
  27. :align="item.align"
  28. >
  29. <template v-if="item.customHeader" v-slot:header>
  30. <slot :name="'header-' + item.name"></slot>
  31. </template>
  32. <template v-if="item.custom" v-slot:default="row">
  33. <slot :name="item.name" :row="row.row" :currentIndex="(row.$index + 1)"></slot>
  34. </template>
  35. </el-table-column>
  36. </template>
  37. </el-table>
  38. <div class="page_pagination" v-if="!hidePagination">
  39. <el-pagination
  40. :hide-on-single-page="hidesinglePage"
  41. :current-page="currentPage"
  42. :page-size="pageSize"
  43. :page-sizes="[20, 50, 100]"
  44. background
  45. layout="prev, pager, next"
  46. :total="Number(totalNum)"
  47. @current-change="(val) => $emit('paginationChange', { type: 'currentPage', val })"
  48. @size-change="(val) => $emit('paginationChange', { type: 'pageSize', val })"
  49. />
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. /*
  55. interface tableColumnItm {
  56. name:String,
  57. label:String,
  58. width?:String,
  59. fixed?:String,
  60. align?:String,
  61. minWidth?:String,
  62. custom:Boolean,
  63. customHeader?:Boolean,
  64. hidden:Boolean,
  65. }
  66. */
  67. export default {
  68. name: 'Table',
  69. props: {
  70. tableData: {
  71. type: Array,
  72. required: true
  73. },
  74. tableColumns: {
  75. type: Array, //类型为 tableColumnItm[]
  76. required: true
  77. },
  78. currentPage: {
  79. type: Number,
  80. default: 1
  81. },
  82. pageSize: {
  83. type: Number,
  84. default: 20
  85. },
  86. totalNum: {
  87. type: Number,
  88. default: 0
  89. },
  90. loading: {
  91. type: Boolean,
  92. default: false
  93. },
  94. hidesinglePage: {
  95. type: Boolean
  96. },
  97. hidePagination: {
  98. type: Boolean,
  99. default: false
  100. },
  101. spanMethod: {
  102. type: Function,
  103. required: false
  104. },
  105. tableRowClassName: {
  106. type: Function,
  107. required: false
  108. },
  109. showHeader: {
  110. type: Boolean,
  111. default: true
  112. }
  113. },
  114. data() {
  115. return {
  116. // Vue 2 中没有 defineModel,tableRef 仅作为内部状态或普通 ref
  117. // 父组件获取表格实例请使用 this.$refs.tableRef
  118. tableRef: null
  119. };
  120. },
  121. mounted(){
  122. }
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .page_table {
  127. overflow: auto;
  128. display: flex;
  129. flex-direction: column;
  130. justify-content: flex-start;
  131. ::v-deep .el-table {
  132. tr th.el-table__cell {
  133. font-size: 14px;
  134. }
  135. }
  136. .el-table {
  137. flex-grow: 1;
  138. ::v-deep .el-scrollbar__view {
  139. height: 100%;
  140. }
  141. }
  142. ::v-deep .el-table__body {
  143. tbody tr.even_row td {
  144. background-color: white;
  145. }
  146. tbody tr.odd_row td {
  147. background-color: rgb(250, 250, 250);
  148. }
  149. tbody tr.hover-row td {
  150. background-color: rgb(245, 247, 250) !important;
  151. }
  152. tbody tr td:last-child:not([rowspan="1"]) {
  153. border-left: solid rgba(235, 238, 245) 1px;
  154. }
  155. }
  156. }
  157. ::v-deep .loading_icon {
  158. .el-loading-spinner {
  159. .el-loading-text {
  160. color: #2e64fa;
  161. }
  162. }
  163. }
  164. </style>