TableBody.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <script setup lang="ts">
  2. import symbolKeys from "@@@/table/symbol"
  3. import BodyTr from "@@@/table/partials/body/BodyTr.vue"
  4. import BodyTreeTr from "@@@/table/partials/body/BodyTreeTr.vue"
  5. const propOpts = inject(symbolKeys.body, {
  6. isTree: false,
  7. childrenField: "children",
  8. bodyClass: "fw-semibold text-gray-600"
  9. })
  10. const depth = 0
  11. const rows = inject(symbolKeys.displayData, ref([]))
  12. const tbody = ref<HTMLElement>()
  13. const hasChildren = (row: any) => {
  14. return row[propOpts.childrenField] && row[propOpts.childrenField].length
  15. }
  16. </script>
  17. <template>
  18. <tbody v-if="rows?.length > 0" ref="tbody" :class="propOpts.bodyClass">
  19. <template v-for="(row, i) in rows" :key="i">
  20. <BodyTr :row="row" :depth="depth" :index="i + 1">
  21. <template v-for="(_, name) in $slots" #[name]="{ row }">
  22. <slot :name="name" :row="row" />
  23. </template>
  24. </BodyTr>
  25. <template v-if="propOpts.isTree && hasChildren(row)">
  26. <BodyTreeTr
  27. :index="i + 1"
  28. :rows="row[propOpts.childrenField]"
  29. :childrenField="propOpts.childrenField"
  30. :depth="depth + 1">
  31. <template v-for="(_, name) in $slots" #[name]="{ row }">
  32. <slot :name="name" :row="row" />
  33. </template>
  34. </BodyTreeTr>
  35. </template>
  36. </template>
  37. </tbody>
  38. </template>