TableLayout.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <script setup lang="ts">
  2. interface tableProps {
  3. columns?: Array<Record<string, any>>
  4. data: Array<Record<string, any>>
  5. isLoading?: boolean
  6. }
  7. const props = defineProps<tableProps>()
  8. const emit = defineEmits<{
  9. (e: 'selection-change', d: any): void
  10. }>()
  11. const { data, isLoading } = toRefs(props)
  12. const tableRef: any = ref(null)
  13. const tableHeight: any = ref(0)
  14. const selectionChangeHandle = (data) => {
  15. emit('selection-change', data)
  16. }
  17. /** 初始化 */
  18. onMounted(() => {
  19. tableHeight.value = tableRef.value.clientHeight
  20. })
  21. </script>
  22. <template>
  23. <div class="table" ref="tableRef">
  24. <el-table
  25. v-loading="isLoading"
  26. :data="data"
  27. style="width: 100%; height: 100%"
  28. :cell-style="{ padding: '12px 0' }"
  29. :style="{ height: tableHeight + 'px' }"
  30. stripe
  31. :header-cell-style="{
  32. background: '#E5F0FB',
  33. color: '#233755',
  34. height: '50px'
  35. }"
  36. header-cell-class-name="cus-tab-header"
  37. @selection-change="selectionChangeHandle"
  38. >
  39. <slot></slot>
  40. </el-table>
  41. </div>
  42. </template>
  43. <style lang="scss">
  44. .cus-tab-header {
  45. .cell {
  46. white-space: nowrap;
  47. }
  48. }
  49. </style>