enroll-table.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="enroll-table">
  3. <table class="w-full">
  4. <tr class="fx-row mt-10" :class="compact?'gap-10':'gap-20'">
  5. <th class="rounded text-2xs fx-row fx-cen-cen" :class="head.clazz||'flex-1'"
  6. v-for="(head, i) in headers">
  7. {{ head.label }}
  8. </th>
  9. </tr>
  10. <template v-if="data.length">
  11. <tr class="fx-row mt-10" :class="compact?'gap-10':'gap-20'" v-for="(item, i) in data">
  12. <td class="rounded text-2xs fx-row fx-cen-cen" v-for="hd in headers" :key="hd.prop"
  13. :class="hd.clazz||'flex-1'">
  14. <slot :name="hd.slotBody" v-bind="{display: item[hd.prop], item}">
  15. {{ item[hd.prop] || '-' }}
  16. </slot>
  17. </td>
  18. </tr>
  19. </template>
  20. <view v-else class="no-data mt-20 rounded text-2xs text-tips text-center">暂无数据</view>
  21. </table>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. headers: {
  28. type: Array,
  29. default: () => []
  30. },
  31. data: {
  32. type: Array,
  33. default: () => []
  34. },
  35. compact: {
  36. type: Boolean,
  37. default: false
  38. }
  39. }
  40. };
  41. </script>
  42. <style lang="scss" scoped>
  43. .enroll-table {
  44. th,
  45. td {
  46. min-height: 48rpx;
  47. padding: 6rpx 12rpx;
  48. }
  49. th {
  50. color: #2B68F6;
  51. background-color: #DAE4FD;
  52. }
  53. td {
  54. background-color: #F1F2F3;
  55. }
  56. .no-data {
  57. background-color: #F1F2F3;
  58. height: 70px;
  59. line-height: 70px;
  60. }
  61. }
  62. </style>