table.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <script setup name="table">
  2. import { computed, ref } from 'vue';
  3. const props = defineProps({
  4. height: {
  5. type: String,
  6. default: '800px'
  7. },
  8. data: {
  9. type: Array,
  10. default: () => ([]),
  11. },
  12. column: {
  13. type: Array,
  14. default: () => ([]),
  15. },
  16. tableName: {
  17. type: String,
  18. default: '',
  19. },
  20. tableId: {
  21. type: String,
  22. default: '',
  23. },
  24. loading: {
  25. type: Boolean,
  26. default: false,
  27. }
  28. })
  29. const emits = defineEmits(['export'])
  30. const funExport = () => {
  31. emits('export')
  32. }
  33. const tableRef = ref('')
  34. const tableHeight = computed(() => {
  35. return tableRef.value.offsetHeight? tableRef.value.offsetHeight - 46 : 739
  36. })
  37. </script>
  38. <template>
  39. <div ref="tableRef" class=""
  40. :style="{ height: typeof props.height === 'string' ? props.height : props.height + 'px' }">
  41. <div class="flex justify-between items-center pb-[10px]">
  42. <h3>{{ props.tableName }}</h3>
  43. <!-- <el-button size="small" type="primary" @click="funExport" :disabled="!props.tableId">数据导出</el-button> -->
  44. </div>
  45. <el-table stripe :data="props.data" size="small" v-loading="props.loading" :max-height="tableHeight"
  46. :style="{ width: '100%' }">
  47. <el-table-column align="center" show-overflow-tooltip v-for="item in props.column" :prop="item.prop"
  48. :label="item.label" sortable resizable :min-width="item.width ? item.width : 80" />
  49. </el-table>
  50. </div>
  51. </template>