index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div
  3. v-loading="options.loading"
  4. class="l-flex__auto l-flex--col c-table"
  5. >
  6. <div
  7. v-if="hasHeader"
  8. class="l-flex__none l-flex--row c-table__header"
  9. >
  10. <div class="l-flex__greedy">
  11. <slot
  12. name="header"
  13. :condition="options.params"
  14. :total-count="options.totalCount"
  15. />
  16. <template v-if="buttons">
  17. <button
  18. v-for="(button, index) in buttons"
  19. :key="index"
  20. class="o-button"
  21. @click="onClickButton(button)"
  22. >
  23. <i
  24. v-if="button.icon"
  25. class="o-button__icon"
  26. :class="button.icon"
  27. />
  28. {{ button.label }}
  29. </button>
  30. </template>
  31. </div>
  32. <template v-if="filters">
  33. <div
  34. v-for="filter in filters"
  35. :key="filter.key"
  36. class="l-flex__none l-flex--row c-sibling-item"
  37. >
  38. <schema-select
  39. v-if="filter.type === 'select'"
  40. v-model="options.params[filter.key]"
  41. class="o-select"
  42. :schema="filter"
  43. @change="onChange"
  44. />
  45. <template v-if="filter.type === 'switch'">
  46. <span class="c-sibling-item">{{ filter.placeholder }}</span>
  47. <el-switch
  48. v-model="options.params[filter.key]"
  49. class="c-sibling-item"
  50. active-color="#13ce66"
  51. inactive-color="#ff4949"
  52. @change="onChange"
  53. />
  54. </template>
  55. <template v-if="filter.type === 'search'">
  56. <search-input
  57. v-model.trim="options.params[filter.key]"
  58. class="c-sibling-item"
  59. :placeholder="filter.placeholder"
  60. @search="onChange"
  61. />
  62. <button
  63. class="c-sibling-item o-button"
  64. @click="onChange"
  65. >
  66. 搜索
  67. </button>
  68. </template>
  69. </div>
  70. </template>
  71. </div>
  72. <status-wrapper
  73. v-if="isAbnormal"
  74. :error="options.error"
  75. @click="onPagination"
  76. />
  77. <template v-else>
  78. <grid-table-body
  79. :data="tableData"
  80. :item-render="itemRender"
  81. v-bind="$attrs"
  82. />
  83. <pagination
  84. :total="options.totalCount"
  85. :page.sync="options.params.pageNum"
  86. :limit.sync="options.params.pageSize"
  87. v-bind="paginationConfig"
  88. @pagination="onPagination"
  89. />
  90. </template>
  91. <slot />
  92. </div>
  93. </template>
  94. <script>
  95. import tableMixin from '../mixins/table'
  96. import GridTableBody from './GridTableBody'
  97. export default {
  98. name: 'GridTable',
  99. components: {
  100. GridTableBody
  101. },
  102. mixins: [tableMixin],
  103. data () {
  104. return {
  105. itemRender: null
  106. }
  107. },
  108. computed: {
  109. pageSize () {
  110. return this.schema.pageSize || 8
  111. },
  112. isAbnormal () {
  113. const options = this.options
  114. return options.error || !options.loading && options.totalCount === 0
  115. }
  116. },
  117. methods: {
  118. setItemRender (render) {
  119. this.itemRender = render
  120. }
  121. }
  122. }
  123. </script>