table.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="bs-table" :style="{height:height?height:'calc(100vh - 330px)'}">
  3. <el-table border stripe ref="tables" :row-class-name="tableClassName" :header-cell-style="{background:'#fafafafa',height:'40px','color':'#000000'}" highlight-current-row :data="data" size="mini" @row-click="rowClick" height="100%" style="width:100%;" @selection-change="handleSelectionChange" >
  4. <!-- <div slot="empty">
  5. <el-empty :image="require('../../../assets/empty.svg')" :image-size="250">
  6. </el-empty>
  7. </div> -->
  8. <el-table-column
  9. type="selection"
  10. width="45"
  11. align="center"
  12. @handleSelectionChange="handleSelectionChange">
  13. </el-table-column>
  14. <el-table-column show-overflow-tooltip v-for="(col) in layout" :key="col.tablecolid" :prop="col.columnname" :label="col.title" :min-width="col.width === 0 ? 150 : col.width" :fixed="checkFixed(col.columnname)">
  15. <template slot-scope="scope">
  16. <slot v-if="col.columnname !== 'operation'" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
  17. <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
  18. </template>
  19. </el-table-column>
  20. <!-- <el-table-column v-for="(col) in layout" :key="col.tablecolid">
  21. <template #header>
  22. <el-input v-if="col.filter === 1" size="mini" v-model="col.value" @change="inputChange" @keyup.native.enter="headerSearch(col.columnname)" @clear="headerSearch(col.columnname)" clearable/>
  23. <slot v-if="col.filter === 2" name="temp" :data="col.columnname"></slot>
  24. </template>
  25. <el-table-column :prop="col.columnname" :label="col.title" :width="col.width ? col.width : 0" :min-width="col.width === 0 ? 150 : col.width" :fixed="checkFixed(col.columnname)">
  26. <template slot-scope="scope">
  27. <slot v-if="col.columnname !== 'operation'" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
  28. <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
  29. </template>
  30. </el-table-column>
  31. </el-table-column> -->
  32. </el-table>
  33. </div>
  34. </template>
  35. <script>
  36. import {mapGetters} from "vuex"
  37. export default {
  38. /*
  39. layout:表结构数据;
  40. data:表渲染数据;
  41. custom:是否启用自定义结构;
  42. opwidth:操作列宽度
  43. */
  44. props:['data','tableName','custom','layout','fixRightData','fixLeftData','height'],
  45. data () {
  46. return {
  47. list:[],
  48. act_column:'',
  49. value:'',
  50. show:false
  51. }
  52. },
  53. computed:{
  54. ...mapGetters({
  55. loading:'loading'
  56. })
  57. },
  58. watch:{
  59. tableName () {
  60. this.$nextTick(() => {
  61. this.$refs.tables.doLayout()
  62. });
  63. },
  64. data(){
  65. this.$nextTick(() => {
  66. this.$refs.tables.doLayout()
  67. });
  68. }
  69. },
  70. methods:{
  71. rowClick (row) {
  72. this.$emit('rowClick',row)
  73. },
  74. tableClassName ({row,rowIndex}) {
  75. row.index = rowIndex
  76. },
  77. handleSelectionChange(val) {
  78. this.$emit('checkboxCallBack',val)
  79. },
  80. checkFixed (columnname) {
  81. let isRight = this.fixRightData.some(item=>item === columnname)
  82. let isLeft = this.fixLeftData.some(item=>item === columnname)
  83. if (isRight) return 'right'
  84. if (isLeft) return 'left'
  85. },
  86. headerSearch (columnname) {
  87. this.show = false
  88. this.$emit('headerSearch',columnname,this.value)
  89. },
  90. inputChange (val) {
  91. this.value = val
  92. }
  93. },
  94. mounted () {
  95. }
  96. }
  97. </script>
  98. <style>
  99. /* .bs-table .el-table {
  100. display: flex;
  101. flex-direction: column;
  102. } */
  103. </style>
  104. <style scoped>
  105. .search-icon:hover{
  106. font-weight: bold;
  107. background: #f1f2f3;
  108. cursor: pointer;
  109. }
  110. /deep/.ellipsis {
  111. display:-webkit-box;
  112. text-overflow:ellipsis;
  113. overflow:hidden;
  114. -webkit-line-clamp: 2;
  115. -webkit-box-orient:vertical;
  116. }
  117. /deep/.el-table--mini .el-table__cell {
  118. padding: 0 !important;
  119. }
  120. /deep/.el-table .el-table__cell {
  121. padding: 0 !important;
  122. }
  123. </style>