table.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div>
  3. <el-input v-if="isInput !== false" style="width:200px;" :placeholder="$t('搜索')" :suffix-icon="param.content.where.condition?param.content.where.condition.length > 0?'':'':'el-icon-search'" v-model="param.content.where.condition" @keyup.native.enter="listData(param.content.pageNumber = 1)" @clear="listData(param.content.pageNumber = 1)" size="small" class="input-with-select inline-16 layout_search__panel" clearable>
  4. </el-input>
  5. <el-table ref="table" :fit="tool.calculatedColumnWidth($refs.table,layout)" :row-class-name="tableClassName" highlight-current-row :data="list" size="mini" :height="height ? height : list.length <= 5?'280px':'calc(100vh - 268px)'" @row-click="rowClick" style="width:100%;margin-top: 10px" :header-cell-style="{height:'40px',color:'#606266',fontWeight:'400',fontSize:'14px'}"
  6. :cell-style="{height:'40px',color:'#666666',fontWeight:'400'}" border @selection-change="selectionChange" :row-key="rowKey">
  7. <el-table-column
  8. type="selection"
  9. width="35" fixed v-if="checkbox" :reserve-selection="reserveSelection">
  10. </el-table-column>
  11. <el-table-column ref="table" show-overflow-tooltip v-for="(col,index) in layout" :key="col.tablecolid" :prop="col.columnname" :label="col.title" :min-width="col.width || 150" :fixed="fixedName ? fixedName.indexOf(col.columnname)!= -1?redirect ? redirect : 'right' :false : false">
  12. <template v-slot:header="{ column,$index }" v-if="customHeader">
  13. <slot name="header" :data="column"></slot>
  14. </template>
  15. <template slot-scope="scope">
  16. <div class="table-panel">
  17. <!-- 自定义表格显示内容 -->
  18. <slot v-if="custom" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
  19. <!-- 否则就是默认 -->
  20. <span v-else>{{scope.row[col.columnname]}}</span>
  21. <!-- 操作结构内容 -->
  22. <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
  23. </div>
  24. </template>
  25. </el-table-column>
  26. </el-table>
  27. <div class="container normal-panel" style="text-align:right;padding-bottom: 5px !important;" v-if="isPagination !== false">
  28. <el-pagination
  29. background
  30. @size-change="handleSizeChange"
  31. @current-change="handleCurrentChange"
  32. :current-page="currentPage"
  33. :page-sizes="[20, 50, 100, 200]"
  34. :page-size="20"
  35. layout="total,sizes, prev, pager, next, jumper"
  36. :total="total">
  37. </el-pagination>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. name: "table",
  44. props:['layout','custom','param','height','fixedName','width','checkbox','redirect','customHeader','prop','isInput','isPagination', 'rowKey', 'reserveSelection'],
  45. data () {
  46. return {
  47. list:[],
  48. currentPage:0,
  49. total:0
  50. }
  51. },
  52. watch:{
  53. list(val){
  54. this.doLayout()
  55. }
  56. },
  57. methods:{
  58. async listData(){
  59. const res = await this.$api.requested(this.param)
  60. this.list = res.data
  61. this.total = res.total
  62. this.currentPage = res.pageNumber
  63. this.$emit('listData',this.list)
  64. },
  65. rowClick (row) {
  66. this.$emit('rowClick',row)
  67. },
  68. tableClassName ({row,rowIndex}) {
  69. row.index = rowIndex
  70. },
  71. selectionChange(row){
  72. this.$emit('selectionChange',row)
  73. },
  74. doLayout(){
  75. if (this.$refs.table){
  76. this.$nextTick(()=>{
  77. this.$refs.table.doLayout()
  78. })
  79. }
  80. },
  81. handleSizeChange(val) {
  82. // console.log(`每页 ${val} 条`);
  83. this.param.content.pageSize = val
  84. this.listData()
  85. },
  86. handleCurrentChange(val) {
  87. // console.log(`当前页: ${val}`);
  88. this.param.content.pageNumber = val
  89. this.listData()
  90. },
  91. },
  92. mounted () {
  93. }
  94. }
  95. </script>
  96. <style scoped>
  97. </style>