CustomTable.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="table__content">
  3. <div class="table__content_label" :class="`table__content_label_${type}`">
  4. <div class="label-t" v-for="(item, index) in columns" :key="`svvhbcth-${index}`" :style="{ flexBasis }">{{ item.name }}</div>
  5. </div>
  6. <div class="table__content_list" :class="`table__content_list_${type}`">
  7. <div class="table__content_list_row" v-for="(item, index) in data" :key="`svvhbct-${index}`">
  8. <div v-for="(t, i) in columns" :key="`svvhbctr-${i}`" :style="{ flexBasis }" :class="`table__content__list_item_${type}`">
  9. <slot :name="t.prop" :scope="item">
  10. <span>{{ get(item, t.prop) }}</span>
  11. </slot>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import { computed, defineProps } from 'vue';
  19. import _ from 'lodash';
  20. let props = withDefaults(
  21. defineProps<{
  22. /** B | C */
  23. type: string;
  24. /** 列表表头配置,每个prop都有其对应的slot来提供定制化功能 */
  25. columns: { prop: string; name: string }[];
  26. data: any[];
  27. defaultValue: string;
  28. }>(),
  29. {
  30. type: 'B',
  31. columns: () => [],
  32. data: () => [],
  33. defaultValue: '-',
  34. }
  35. );
  36. const flexBasis = computed(() => {
  37. return Math.fround(100 / props.columns.length) + '%';
  38. });
  39. function get(o, p) {
  40. const d = _.get(o, p);
  41. return _.isNil(d) ? props.defaultValue : d === '' ? props.defaultValue : d;
  42. }
  43. </script>
  44. <style lang="less" scoped>
  45. @import '/@/design/theme.less';
  46. @import '@/design/vent/color.less';
  47. @font-face {
  48. font-family: 'douyuFont';
  49. src: url('/@/assets/font/douyuFont.otf');
  50. }
  51. @{theme-deepblue} {
  52. .table__content {
  53. --image-content-label: url(/@/assets/images/themify/deepblue/company/content-label.png);
  54. --image-content-text: url('/@/assets/images/themify/deepblue/company/content-text.png');
  55. --image-list-head: url('/@/assets/images/themify/deepblue/configurable/firehome/list-head.png');
  56. --image-content-text: url('/@/assets/images/themify/deepblue/company/content-text.png');
  57. --image-content-text: url('/@/assets/images/themify/deepblue/company/content-text.png');
  58. }
  59. }
  60. .table__content {
  61. --image-content-label: url(/@/assets/images/company/content-label.png);
  62. --image-content-text: url('/@/assets/images/company/content-text.png');
  63. --image-list-head: url('/@/assets/images/home-container/configurable/firehome/list-head.png');
  64. --image-content-text: url('/@/assets/images/company/content-text.png');
  65. --image-content-text: url('/@/assets/images/company/content-text.png');
  66. height: 100%;
  67. box-sizing: border-box;
  68. display: flex;
  69. flex-direction: column;
  70. align-items: center;
  71. padding: 5px 0;
  72. .table__content_label {
  73. width: 400px;
  74. height: 32px;
  75. display: flex;
  76. justify-content: space-around;
  77. align-items: center;
  78. .label-t {
  79. text-align: center;
  80. font-size: 14px;
  81. }
  82. }
  83. .table__content_label_A {
  84. background-image: var(--image-content-label);
  85. background-size: 100% 100%;
  86. background-repeat: no-repeat;
  87. color: #31b9ef;
  88. }
  89. .table__content_label_B {
  90. background-image: linear-gradient(to top, #04698c, #04698c00);
  91. background-size: 100% 100%;
  92. background-repeat: no-repeat;
  93. color: #31b9ef;
  94. }
  95. .table__content_label_C {
  96. background-position: center 100%;
  97. background-size: 100% 25px;
  98. background-repeat: no-repeat;
  99. background-image: var(--image-content-text);
  100. height: 40px;
  101. .label-t {
  102. background-repeat: no-repeat;
  103. background-size: 80% auto;
  104. background-position: center;
  105. background-image: var(--image-list-head);
  106. }
  107. }
  108. .table__content_list {
  109. height: calc(100% - 32px);
  110. width: 400px;
  111. display: flex;
  112. flex-direction: column;
  113. padding: 5px 0;
  114. box-sizing: border-box;
  115. overflow-y: auto;
  116. .table__content_list_row {
  117. width: 100%;
  118. display: flex;
  119. justify-content: space-around;
  120. align-items: center;
  121. color: #fff;
  122. margin-bottom: 5px;
  123. span {
  124. display: inline-block;
  125. text-align: center;
  126. }
  127. }
  128. }
  129. .table__content_list_A {
  130. .table__content_list_row {
  131. background-size: 100% auto;
  132. background-repeat: no-repeat;
  133. background-position: center bottom;
  134. background-image: var(--image-content-text);
  135. }
  136. }
  137. .table__content_list_C {
  138. .table__content_list_row {
  139. min-height: 50px;
  140. background-size: 100% auto;
  141. background-repeat: no-repeat;
  142. background-position: center bottom;
  143. background-image: var(--image-content-text);
  144. }
  145. }
  146. }
  147. </style>