table.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <script setup name="table">
  2. import { ref, computed, defineProps, defineEmits } 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 - 12 : 739;
  36. });
  37. </script>
  38. <template>
  39. <div
  40. ref="tableRef"
  41. class=""
  42. :style="{
  43. height:
  44. typeof props.height === 'string' ? props.height : props.height + 'px',
  45. }"
  46. >
  47. <!-- <div class="flex justify-between items-center pb-[10px]"> -->
  48. <!-- <h3>{{props.tableName}}</h3> -->
  49. <!-- <el-button size="small" type="primary" @click="funExport" :disabled="!props.tableId">数据导出</el-button> -->
  50. <!-- </div> -->
  51. <el-table
  52. :data="props.data"
  53. stripe
  54. size="small"
  55. v-loading="props.loading"
  56. :height="height"
  57. :style="{ width: '100%' }"
  58. >
  59. <el-table-column
  60. header-align="center"
  61. :align="index < 2 ? 'center' : 'right'"
  62. show-overflow-tooltip
  63. v-for="(item, index) in props.column"
  64. :key="item.prop"
  65. :prop="item.prop"
  66. :label="item.label"
  67. sortable
  68. resizable
  69. :min-width="item.width ? item.width : 80"
  70. />
  71. </el-table>
  72. </div>
  73. </template>