CommonTable.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="table">
  3. <div class="table__content">
  4. <div class="table__content_label">
  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">
  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 }">
  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. /** 列表表头配置,每个prop都有其对应的slot来提供定制化功能 */
  25. columns: { prop: string; name: string }[];
  26. data: any[];
  27. defaultValue: string;
  28. }>(),
  29. {
  30. columns: () => [],
  31. data: () => [],
  32. defaultValue: '/',
  33. }
  34. );
  35. const flexBasis = computed(() => {
  36. return Math.fround(100 / props.columns.length) + '%';
  37. });
  38. function get(o, p) {
  39. const d = _.get(o, p, props.defaultValue);
  40. return d === null ? props.defaultValue : d;
  41. }
  42. </script>
  43. <style lang="less" scoped>
  44. @font-face {
  45. font-family: 'douyuFont';
  46. src: url('@/assets/font/douyuFont.otf');
  47. }
  48. .table__content {
  49. height: 100%;
  50. box-sizing: border-box;
  51. display: flex;
  52. flex-direction: column;
  53. align-items: center;
  54. .table__content_label {
  55. width: 366px;
  56. height: 32px;
  57. display: flex;
  58. justify-content: space-around;
  59. align-items: center;
  60. background: url('@/assets/images/company/content-label.png') no-repeat;
  61. .label-t {
  62. color: #3df6ff;
  63. text-align: center;
  64. font-size: 14px;
  65. }
  66. }
  67. .table__content_list {
  68. height: calc(100% - 32px);
  69. width: 378px;
  70. display: flex;
  71. flex-direction: column;
  72. // justify-content: space-around;
  73. justify-content: flex-start;
  74. padding: 5px 0px;
  75. box-sizing: border-box;
  76. overflow-y: auto;
  77. .table__content_list_row {
  78. width: 100%;
  79. height: 28px;
  80. display: flex;
  81. justify-content: space-around;
  82. align-items: flex-start;
  83. background: url('@/assets/images/company/content-text.png') no-repeat;
  84. color: #fff;
  85. margin-bottom: 5px;
  86. span {
  87. display: inline-block;
  88. text-align: center;
  89. }
  90. }
  91. }
  92. }
  93. </style>