table3.vue 5.5 KB

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