index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <el-table ref="table" :data="rows" v-bind="mergedAttrs" v-on="$listeners">
  3. <dynamic-table-column v-for="column in visibleColumns" :key="column.prop" :column="column"
  4. :default-setting="columnDefaultSetting">
  5. <template v-for="slot in Object.keys($scopedSlots)" #[slot]="scope">
  6. <slot :name="slot" v-bind="scope">
  7. {{ scope.display }}
  8. </slot>
  9. </template>
  10. </dynamic-table-column>
  11. </el-table>
  12. </template>
  13. <script>
  14. /*
  15. * NOTE:22.5.9 hht
  16. * 新的动态表格,支持多级嵌套与动态属性/事件
  17. * */
  18. import DynamicTableColumn from '@/components/dynamic-table/dynamic-table-column'
  19. export default {
  20. name: 'dynamic-table',
  21. components: { DynamicTableColumn },
  22. props: {
  23. rows: { type: Array, default: () => [] },
  24. columns: { type: Array, default: () => [] },
  25. tableDefaultSetting: { type: Object, default: () => ({}) },
  26. columnDefaultSetting: { type: Object, default: () => ({ align: 'center' }) }
  27. },
  28. computed: {
  29. mergedAttrs() {
  30. return { ...this.tableDefaultSetting, ...this.$attrs }
  31. },
  32. visibleColumns() {
  33. return this.columns.filter(col => col.hidden !== true)
  34. },
  35. tableCore() {
  36. return this.$refs.table
  37. }
  38. }
  39. }
  40. </script>
  41. <style scoped>
  42. </style>