index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div
  3. v-loading="options.loading"
  4. class="l-flex__auto l-flex--col c-table"
  5. :class="{ 'prevent-copy': preventCopy }"
  6. >
  7. <div
  8. v-if="hasHeader"
  9. class="l-flex__none c-table__header"
  10. >
  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. v-if="filters"
  33. class="l-flex__fill c-table__filters"
  34. >
  35. <div
  36. v-for="filter in filters"
  37. :key="filter.key"
  38. class="l-flex--row"
  39. >
  40. <schema-select
  41. v-if="filter.type === 'select'"
  42. v-model="options.params[filter.key]"
  43. :class="{ 'o-select': !filter.remote || filter.simple }"
  44. :schema="filter"
  45. @change="onChange"
  46. />
  47. <template v-if="filter.type === 'switch'">
  48. <span class="c-sibling-item">{{ filter.placeholder }}</span>
  49. <el-switch
  50. v-model="options.params[filter.key]"
  51. class="c-sibling-item"
  52. active-color="#13ce66"
  53. inactive-color="#ff4949"
  54. @change="onChange"
  55. />
  56. </template>
  57. <template v-if="filter.type === 'search'">
  58. <search-input
  59. v-model.trim="options.params[filter.key]"
  60. class="c-sibling-item"
  61. :placeholder="filter.placeholder"
  62. @search="onChange"
  63. />
  64. <button
  65. class="c-sibling-item o-button"
  66. @click="onChange"
  67. >
  68. 搜索
  69. </button>
  70. </template>
  71. </div>
  72. </div>
  73. </div>
  74. <el-table
  75. ref="table"
  76. class="l-flex__self l-flex--col c-table__main"
  77. :class="{ 'with-content': tableData.length }"
  78. :data="tableData"
  79. v-bind="tableProps"
  80. v-on="$listeners"
  81. >
  82. <schema-table-column
  83. v-for="(col, index) in cols"
  84. :key="index"
  85. :schema="col"
  86. />
  87. <status-wrapper
  88. slot="empty"
  89. :error="options.error"
  90. @click="onPagination"
  91. />
  92. </el-table>
  93. <slot
  94. v-if="isNeedPagination"
  95. name="pagination"
  96. :options="options"
  97. :pagination="onPagination"
  98. >
  99. <pagination
  100. :total="options.totalCount"
  101. :page.sync="options.params.pageNum"
  102. :limit.sync="options.params.pageSize"
  103. v-bind="paginationConfig"
  104. @pagination="onPagination"
  105. />
  106. </slot>
  107. <slot />
  108. </div>
  109. </template>
  110. <script>
  111. import tableMixin from '../mixins/table'
  112. import SchemaTableColumn from './Column'
  113. export default {
  114. name: 'SchemaTable',
  115. components: {
  116. SchemaTableColumn
  117. },
  118. mixins: [tableMixin],
  119. computed: {
  120. tableProps () {
  121. return {
  122. ...this.$attrs,
  123. ...this.schema.props
  124. }
  125. },
  126. pageSize () {
  127. return this.schema.pageSize || 10
  128. },
  129. preventCopy () {
  130. return !!this.$listeners['row-dblclick']
  131. },
  132. cols () {
  133. return this.schema.cols.filter(Boolean)
  134. }
  135. }
  136. }
  137. </script>