index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="table2">
  3. <div
  4. :class="isStatus || isStatuser ? 'flex' : 'flex-end'"
  5. class="data-table-btn"
  6. >
  7. <div v-if="isStatus || isStatuser" class="vStatus">
  8. <slot name="header" />
  9. </div>
  10. <template v-if="isBtn">
  11. <template v-if="isAuth">
  12. <el-button size="default" plain class="btn-white">新增</el-button>
  13. </template>
  14. </template>
  15. </div>
  16. <el-auto-resizer>
  17. <template #default="{ height, width }">
  18. <el-table-v2
  19. :columns="columns"
  20. :data="data"
  21. :width="width"
  22. :height="height"
  23. fixed
  24. />
  25. </template>
  26. </el-auto-resizer>
  27. </div>
  28. </template>
  29. <script setup lang="ts">
  30. const props = defineProps({
  31. //是否显示新增按钮
  32. isBtn: {
  33. type: Boolean,
  34. default: true,
  35. },
  36. //是否启用权限按钮
  37. isAuth: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. //是否显示状态
  42. isStatus: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. //是否显示名称
  47. isStatuser: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. });
  52. const generateColumns = (length = 10, prefix = "column-", props?: any) =>
  53. Array.from({ length }).map((_, columnIndex) => ({
  54. ...props,
  55. key: `${prefix}${columnIndex}`,
  56. dataKey: `${prefix}${columnIndex}`,
  57. title: `Column ${columnIndex}`,
  58. width: 150,
  59. }));
  60. const generateData = (
  61. columns: ReturnType<typeof generateColumns>,
  62. length = 200,
  63. prefix = "row-"
  64. ) =>
  65. Array.from({ length }).map((_, rowIndex) => {
  66. return columns.reduce(
  67. (rowData, column, columnIndex) => {
  68. rowData[column.dataKey] = `Row ${rowIndex} - Col ${columnIndex}`;
  69. return rowData;
  70. },
  71. {
  72. id: `${prefix}${rowIndex}`,
  73. parentId: null,
  74. }
  75. );
  76. });
  77. const columns = generateColumns(10);
  78. const data = generateData(columns, 200);
  79. </script>
  80. <style lang="scss" scoped>
  81. .table2 {
  82. height: 100%;
  83. .data-table-btn {
  84. line-height: 32px;
  85. margin-bottom: 20px;
  86. }
  87. }
  88. </style>