table2.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <el-table stripe :data="data.data" :height="height" style="width: 100%" @cell-click="onClick">
  3. <el-table-column
  4. v-for="col in data.column"
  5. :key="col"
  6. :prop="col.field"
  7. :label="col.name"
  8. :width="col.width"
  9. :sortable="col.sortable"
  10. :show-overflow-tooltip="!col.slot"
  11. :fixed="col.fixed"
  12. :align="col.align ? col.align : 'center'"
  13. :resizable="col.resizable"
  14. :header-align="'center'"
  15. >
  16. <template v-if="col.slot == true" #default="item">
  17. <slot :name="col.field" :column="col" :row="item.row" :all="item" :data="item.row[col.field]"></slot>
  18. </template>
  19. </el-table-column>
  20. </el-table>
  21. <el-pagination class="mg-t-8" v-if="pageable" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="data.total"> </el-pagination>
  22. </template>
  23. <script>
  24. export default {
  25. // 名称
  26. name: "ComTable",
  27. // 使用组件
  28. components: {},
  29. // 传入参数
  30. props: {
  31. /**
  32. * {
  33. column: [{
  34. name: "风机名称",
  35. field: "name",
  36. width:'', // 宽度
  37. click:function(){} // 点击事件
  38. sortable:fasle,
  39. slot:false,
  40. fixed:false,
  41. align:'center',
  42. resizable :false,
  43. }],
  44. total:200
  45. }
  46. */
  47. data: Object,
  48. height: {
  49. type: String,
  50. default: "",
  51. },
  52. pageSize: {
  53. type: Number,
  54. default: 0,
  55. },
  56. },
  57. // 自定义事件
  58. emits: {
  59. // 分页事件
  60. onPagging: null,
  61. },
  62. // 数据
  63. data() {
  64. return {
  65. currentPage: 1,
  66. };
  67. },
  68. computed: {
  69. tableData() {
  70. let that = this;
  71. if (this.sortCol == "") {
  72. return this.data.data;
  73. } else {
  74. let data = this.data.data;
  75. data.sort((a, b) => {
  76. let rev = 1;
  77. if (that.sortType == "ASC") rev = 1;
  78. else if (that.sortType == "DESC") rev = -1;
  79. if (a[that.sortCol] > b[that.sortCol]) return rev * 1;
  80. if (a[that.sortCol] < b[that.sortCol]) return rev * -1;
  81. return 0;
  82. });
  83. return data;
  84. }
  85. },
  86. pageable() {
  87. return this.pageSize != 0;
  88. },
  89. pages() {
  90. if (this.pageable) return parseInt(this.data.total / this.pageSize) + 1;
  91. else return 0;
  92. },
  93. startRow() {
  94. if (this.pageable) return (this.currentPage - 1) * this.pageSize;
  95. else return 0;
  96. },
  97. endRow() {
  98. if (this.pageable) return this.currentPage * this.pageSize;
  99. else return this.data.data.length;
  100. },
  101. },
  102. // 函数
  103. methods: {
  104. onClick(row, column, cell, event) {
  105. if (column.rawColumnKey.click) column.rawColumnKey.click(event, row);
  106. },
  107. handleCurrentChange(val) {
  108. this.currentPage = val;
  109. this.$emit("onPagging", {
  110. pageIndex: this.currentPage,
  111. pageSize: this.pageSize,
  112. start: this.startRow,
  113. end: this.endRow,
  114. });
  115. },
  116. },
  117. // 生命周期钩子
  118. beforeCreate() {
  119. // 创建前
  120. },
  121. created() {
  122. // 创建后
  123. },
  124. beforeMount() {
  125. // 渲染前
  126. },
  127. mounted() {
  128. // 渲染后
  129. },
  130. beforeUpdate() {},
  131. updated() {},
  132. };
  133. </script>
  134. <style lang="less">
  135. @titleGray: #9ca5a8;
  136. @rowGray: #606769;
  137. @darkBack: #536268;
  138. .com-table {
  139. width: 100%;
  140. border-collapse: collapse;
  141. thead {
  142. tr {
  143. display: table;
  144. table-layout: fixed;
  145. width: 100%;
  146. th {
  147. background-color: fade(@darkBack, 20%);
  148. height: 30px;
  149. line-height: 30px;
  150. color: @titleGray;
  151. font-weight: 400;
  152. font-size: @fontsize-s;
  153. position: sticky;
  154. top: 0;
  155. cursor: pointer;
  156. &.light,
  157. &.always-light {
  158. color: @green;
  159. }
  160. }
  161. }
  162. }
  163. tbody {
  164. display: block;
  165. tr {
  166. display: table;
  167. table-layout: fixed;
  168. width: 100%;
  169. &:nth-child(2n) {
  170. background-color: fade(@rowGray, 20%);
  171. }
  172. td {
  173. padding: 0.556vh 0;
  174. color: @rowGray;
  175. text-align: center;
  176. font-size: @fontsize-s;
  177. white-space: nowrap;
  178. overflow: hidden;
  179. text-overflow: ellipsis;
  180. &.light,
  181. &.always-light {
  182. color: @green !important;
  183. }
  184. &.num {
  185. font-family: "Bicubik";
  186. font-weight: 400;
  187. }
  188. }
  189. }
  190. }
  191. .el-pagination {
  192. color: @gray;
  193. .el-pagination__total {
  194. color: @gray;
  195. }
  196. button {
  197. &.btn-next,
  198. &.btn-prev {
  199. background: center center no-repeat fade(@gray, 20);
  200. color: @gray-l;
  201. }
  202. &:disabled {
  203. color: @gray-l;
  204. background-color: fade(@gray, 20);
  205. cursor: not-allowed;
  206. }
  207. }
  208. .el-pager li {
  209. color: @gray-l;
  210. background: fade(@gray, 20);
  211. &.active {
  212. color: @green;
  213. }
  214. }
  215. .el-input__inner {
  216. color: @gray-l;
  217. background: fade(@gray, 20);
  218. border: 1px solid fade(@gray, 20);
  219. }
  220. }
  221. }
  222. </style>