group-table.vue 6.3 KB

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