naf-table.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <el-container class="container">
  3. <el-header height="36px" style="line-height:36px;">
  4. <div class="filter-box" v-if="filters && filters.length > 0">
  5. <el-input placeholder="请输入内容" class="input-with-select" :clearable="true" size="mini" v-model="fieldValue">
  6. <el-select slot="prepend" placeholder="请选择" width="110" v-model="fieldName">
  7. <el-option v-for="(item, index) in filters" :label="item" :value="item" :key="'filter' + index"></el-option>
  8. </el-select>
  9. <el-button slot="append" icon="el-icon-search" @click="query"></el-button>
  10. </el-input>
  11. </div>
  12. <el-button icon="el-icon-plus" type="primary" size="mini" v-if="showAction">添加</el-button>
  13. <slot name="actionBar"></slot>
  14. </el-header>
  15. <el-main>
  16. <el-table border style="width: 100%;overflow: auto;" size="mini">
  17. <slot></slot>
  18. </el-table>
  19. </el-main>
  20. <el-footer height="36px">
  21. <el-pagination
  22. background
  23. @size-change="handleSizeChange"
  24. @current-change="handleCurrentChange"
  25. :current-page="page"
  26. :page-sizes="[10, 20, 50, 100, 200]"
  27. :page-size="size"
  28. :total="total"
  29. layout="total, sizes, prev, pager, next, jumper"
  30. ></el-pagination>
  31. </el-footer>
  32. </el-container>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'naf-table',
  37. props: {
  38. dataSource: Array,
  39. fields: Array,
  40. filters: Array,
  41. readonly: Boolean,
  42. showQuery: Boolean,
  43. showPage: Boolean,
  44. total: Number,
  45. },
  46. data() {
  47. return {
  48. loading: false,
  49. // dataSource: [],
  50. // total: 0,
  51. page: 1,
  52. size: 20,
  53. fieldName: '',
  54. fieldValue: '',
  55. showAction: !this.readonly,
  56. };
  57. },
  58. mounted() {
  59. this.query();
  60. },
  61. methods: {
  62. async query() {
  63. this.loading = true;
  64. setTimeout(() => {
  65. this.loading = false;
  66. }, 1000);
  67. },
  68. handleSizeChange(val) {
  69. console.log(`每页 ${val} 条`);
  70. this.size = val;
  71. if (this.total === 0) return;
  72. const pages = Math.floor((this.total + val) / val);
  73. if (pages < this.page) this.page = pages;
  74. this.query();
  75. },
  76. handleCurrentChange(val) {
  77. console.log(`当前页: ${val}`);
  78. this.page = val;
  79. this.query();
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="less">
  85. .container {
  86. width: 100%;
  87. height: 100%;
  88. }
  89. .main {
  90. width: 100%;
  91. height: 100%;
  92. margin: 0 auto;
  93. }
  94. .el-table {
  95. height: 100%;
  96. overflow: auto;
  97. }
  98. .filter-box {
  99. width: 280px;
  100. display: inline-block;
  101. .el-select {
  102. width: 100px;
  103. }
  104. }
  105. </style>