CustomTable.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="table">
  3. <div class="table__content">
  4. <div class="table__content_label" :class="`table__content_label_${type}`">
  5. <div class="label-t" v-for="(item, index) in columns" :key="`svvhbcth-${index}`" :style="{ flexBasis }">{{ item.name }}</div>
  6. </div>
  7. <div class="table__content_list" :class="`table__content_list_${type}`">
  8. <div class="table__content_list_row" v-for="(item, index) in data" :key="`svvhbct-${index}`">
  9. <div v-for="(t, i) in columns" :key="`svvhbctr-${i}`" :style="{ flexBasis }" :class="`table__content__list_item_${type}`">
  10. <slot :name="t.prop" :scope="item">
  11. <span>{{ get(item, t.prop) }}</span>
  12. </slot>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script lang="ts" setup>
  20. import { computed, defineProps } from 'vue';
  21. import _ from 'lodash-es';
  22. let props = withDefaults(
  23. defineProps<{
  24. type: string;
  25. /** 列表表头配置,每个prop都有其对应的slot来提供定制化功能 */
  26. columns: { prop: string; name: string }[];
  27. data: any[];
  28. defaultValue: string;
  29. }>(),
  30. {
  31. type: 'B',
  32. columns: () => [],
  33. data: () => [],
  34. defaultValue: '/',
  35. }
  36. );
  37. const flexBasis = computed(() => {
  38. return Math.fround(100 / props.columns.length) + '%';
  39. });
  40. function get(o, p) {
  41. const d = _.get(o, p, props.defaultValue);
  42. return d === null ? props.defaultValue : d;
  43. }
  44. </script>
  45. <style lang="less" scoped>
  46. @import '@/design/vent/color.less';
  47. @font-face {
  48. font-family: 'douyuFont';
  49. src: url('@/assets/font/douyuFont.otf');
  50. }
  51. .table__content {
  52. height: 100%;
  53. box-sizing: border-box;
  54. display: flex;
  55. flex-direction: column;
  56. align-items: center;
  57. .table__content_label {
  58. width: 400px;
  59. height: 32px;
  60. display: flex;
  61. justify-content: space-around;
  62. align-items: center;
  63. // background: url('@/assets/images/company/content-label.png') no-repeat;
  64. .label-t {
  65. // color: #3df6ff;
  66. text-align: center;
  67. font-size: 14px;
  68. }
  69. }
  70. .table__content_label_B {
  71. // border: 1px solid @vent-gas-tab-border;
  72. background-image: linear-gradient(to top, #04698c, #04698c00);
  73. background-size: 100% 100%;
  74. background-repeat: no-repeat;
  75. color: #31b9ef;
  76. }
  77. .table__content_list {
  78. height: calc(100% - 32px);
  79. width: 400px;
  80. display: flex;
  81. flex-direction: column;
  82. // justify-content: space-around;
  83. justify-content: flex-start;
  84. padding: 5px 0px;
  85. box-sizing: border-box;
  86. overflow-y: auto;
  87. .table__content_list_row {
  88. width: 100%;
  89. height: 28px;
  90. display: flex;
  91. justify-content: space-around;
  92. align-items: flex-start;
  93. // background: url('@/assets/images/company/content-text.png') no-repeat;
  94. color: #fff;
  95. margin-bottom: 5px;
  96. span {
  97. display: inline-block;
  98. text-align: center;
  99. }
  100. }
  101. // .table__content__list_item_B {
  102. // border: 1px solid @vent-gas-tab-border;
  103. // }
  104. }
  105. }
  106. </style>