table3.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. v-if="data && data.data"
  10. >
  11. <el-table-column
  12. v-for="col in data.column"
  13. :key="col"
  14. :prop="col.field"
  15. :label="col.name"
  16. :width="col.width"
  17. :min-width="col.minWidth"
  18. :sortable="col.sortable"
  19. :sort-orders="sortOrder"
  20. :sort-by="col.field + '.time'"
  21. :show-overflow-tooltip="!col.slot"
  22. :fixed="col.fixed"
  23. :resizable="col.resizable"
  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. v-model:page-size="selfPageSize"
  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. sortOrder: {
  90. type: Array,
  91. default: () => {
  92. return ["descending", "ascending", null];
  93. },
  94. },
  95. },
  96. // 自定义事件
  97. emits: {
  98. // 分页事件
  99. onPagging: null,
  100. },
  101. // 数据
  102. data() {
  103. return {
  104. currentPage: 1,
  105. };
  106. },
  107. computed: {
  108. tableData() {
  109. let that = this;
  110. if (this.sortCol == "") {
  111. return this.data.data;
  112. } else {
  113. let data = this.data.data;
  114. data.sort((a, b) => {
  115. let rev = 1;
  116. if (that.sortType == "ASC") rev = 1;
  117. else if (that.sortType == "DESC") rev = -1;
  118. if (a[that.sortCol] > b[that.sortCol]) return rev * 1;
  119. if (a[that.sortCol] < b[that.sortCol]) return rev * -1;
  120. return 0;
  121. });
  122. return data;
  123. }
  124. },
  125. pageable() {
  126. return this.pageSize != 0;
  127. },
  128. pages() {
  129. if (this.pageable) return parseInt(this.data.total / this.pageSize) + 1;
  130. else return 0;
  131. },
  132. startRow() {
  133. if (this.pageable) return (this.currentPage - 1) * this.pageSize;
  134. else return 0;
  135. },
  136. endRow() {
  137. if (this.pageable) return this.currentPage * this.pageSize;
  138. else return this.data.data.length;
  139. },
  140. // sortOrder: {
  141. // type: Array,
  142. // default: () => {
  143. // return ["descending", "ascending", null];
  144. // },
  145. // },
  146. },
  147. // 函数
  148. methods: {
  149. onClick(row, column, cell, event) {
  150. // if (column.rawColumnKey.click) column.rawColumnKey.click(event, row);
  151. },
  152. handleCurrentChange(val) {
  153. this.currentPage = val;
  154. this.$emit("onPagging", {
  155. pageIndex: this.currentPage,
  156. pageSize: this.pageSize,
  157. start: this.startRow,
  158. end: this.endRow,
  159. });
  160. },
  161. },
  162. // 生命周期钩子
  163. beforeCreate() {
  164. // 创建前
  165. },
  166. created() {
  167. // 创建后
  168. this.selfPageSize = this.pageSize;
  169. },
  170. beforeMount() {
  171. // 渲染前
  172. },
  173. mounted() {
  174. // 渲染后
  175. },
  176. beforeUpdate() {},
  177. updated() {},
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. $titleGray: #9ca5a8;
  182. $rowGray: #606769;
  183. $darkBack: #536268;
  184. $green:#606769;
  185. $gray:#606769;
  186. $gray-l:#606769;
  187. .com-table {
  188. width: 100%;
  189. border-collapse: collapse;
  190. thead {
  191. tr {
  192. display: table;
  193. table-layout: fixed;
  194. width: 100%;
  195. th {
  196. background-color: fade($darkBack, 20%);
  197. height: 30px;
  198. line-height: 30px;
  199. color: $titleGray;
  200. font-weight: 400;
  201. font-size: 16px;
  202. position: sticky;
  203. top: 0;
  204. cursor: pointer;
  205. &.light,
  206. &.always-light {
  207. color: #606769;
  208. }
  209. }
  210. }
  211. }
  212. tbody {
  213. display: block;
  214. tr {
  215. display: table;
  216. table-layout: fixed;
  217. width: 100%;
  218. &:nth-child(2n) {
  219. background-color: fade($rowGray, 20%);
  220. }
  221. td {
  222. padding: 0.556vh 0;
  223. color: $rowGray;
  224. text-align: center;
  225. font-size: 16px;
  226. white-space: nowrap;
  227. overflow: hidden;
  228. text-overflow: ellipsis;
  229. &.light,
  230. &.always-light {
  231. color: $green !important;
  232. }
  233. &.num {
  234. font-family: "Bicubik";
  235. font-weight: 400;
  236. }
  237. }
  238. }
  239. }
  240. .el-pagination {
  241. color: $gray;
  242. .el-pagination__total {
  243. color: $gray;
  244. }
  245. button {
  246. &.btn-next,
  247. &.btn-prev {
  248. background: center center no-repeat fade($gray, 20);
  249. color: $gray-l;
  250. }
  251. &:disabled {
  252. color: $gray-l;
  253. background-color: fade($gray, 20);
  254. cursor: not-allowed;
  255. }
  256. }
  257. .el-pager li {
  258. color: $gray-l;
  259. background: fade($gray, 20);
  260. &.active {
  261. color: $green;
  262. }
  263. }
  264. .el-input__inner {
  265. color: $gray-l;
  266. background: fade($gray, 20);
  267. border: 1px solid fade($gray, 20);
  268. }
  269. }
  270. }
  271. </style>