You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.9 KiB

2 years ago
  1. <template>
  2. <el-table
  3. :data="tableData"
  4. size="medium"
  5. fit
  6. :header-cell-style="{
  7. height: '40px',
  8. padding: '0',
  9. background: '#f7f9fa',
  10. 'font-size': '16px',
  11. color: '#8590a6',
  12. }"
  13. ref="multipleTable"
  14. @sort-change="handleSort"
  15. highlight-current-row
  16. @filter-change="filterHandler"
  17. @row-click="handleRowClick"
  18. >
  19. <el-table-column
  20. v-for="(th, key) in tableHeader"
  21. :key="key"
  22. :prop="th.prop"
  23. :label="th.label"
  24. :fixed="th.fixed"
  25. :sortable="th.sortable ? 'custom' : false"
  26. :filters="th.filters"
  27. :column-key="th.columnKey"
  28. :filtered-value="th.filteredValue"
  29. :filter-multiple="th.filterMultiple"
  30. :min-width="th.minWidth"
  31. >
  32. <template slot-scope="scope">
  33. <ex-slot
  34. v-if="th.render"
  35. :render="th.render"
  36. :row="scope.row"
  37. :index="scope.$index"
  38. :column="th"
  39. />
  40. <span v-else>{{ scope.row[th.prop] || "" }}</span>
  41. </template>
  42. <template>
  43. <el-tag
  44. class="move"
  45. style="cursor: move; margin-left: 15px"
  46. draggable="true"
  47. >
  48. <i class="el-icon-d-caret" style="width: 1rem; height: 1rem"></i>
  49. </el-tag>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. </template>
  54. <script>
  55. // 自定义内容的组件
  56. var exSlot = {
  57. functional: true,
  58. props: {
  59. row: Object,
  60. render: Function,
  61. index: Number,
  62. column: {
  63. type: Object,
  64. default: null,
  65. },
  66. },
  67. render: (h, data) => {
  68. const params = {
  69. row: data.props.row,
  70. index: data.props.index,
  71. };
  72. if (data.props.column) params.column = data.props.column;
  73. return data.props.render(h, params);
  74. },
  75. };
  76. export default {
  77. name: "comp-table",
  78. components: { exSlot },
  79. props: {
  80. // 表格数据
  81. tableData: {
  82. type: Array,
  83. default: function () {
  84. return [];
  85. },
  86. },
  87. // 表头数据
  88. tableHeader: {
  89. type: Array,
  90. default: function () {
  91. return [];
  92. },
  93. },
  94. },
  95. methods: {
  96. // 排序事件
  97. handleSort(sort) {
  98. this.$emit("sort-events", sort);
  99. },
  100. // 筛选事件
  101. filterHandler(filters) {
  102. this.$emit("filter-events", filters);
  103. },
  104. // 某一行被点击
  105. handleRowClick(row) {
  106. // 点击选中是的颜色改变我给你看文档吧? 你这不是可以是的但是那个我用封装的就不行那边那个
  107. // 你封装的那个js文件在哪里没有JS就是封装成组件调用
  108. // 你现在是哪里不行 现在效果不是出来了?是的row可以传递过去拿的到你点击列表看看
  109. // 你看我点击了哪个row那边传过去了 然后呢就选中效果没显示这一个问题背景没变
  110. this.$refs.multipleTable.setCurrentRow(row);
  111. // multipleTable.
  112. console.log("row", row);
  113. this.$emit("clickevents", row);
  114. },
  115. },
  116. };
  117. </script>