CustomTable.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 ref="scrollRef" 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, ref } from 'vue';
  19. import _ from 'lodash';
  20. import { useAutoScroll } from '/@/hooks/core/useAutoScroll';
  21. let props = withDefaults(
  22. defineProps<{
  23. /** B | C */
  24. type: string;
  25. autoScroll: boolean;
  26. /** 列表表头配置,每个prop都有其对应的slot来提供定制化功能 */
  27. columns: { prop: string; name: string }[];
  28. data: any[];
  29. defaultValue: string;
  30. }>(),
  31. {
  32. type: 'B',
  33. autoScroll: false,
  34. columns: () => [],
  35. data: () => [],
  36. defaultValue: '-',
  37. }
  38. );
  39. const scrollRef = ref(null);
  40. if (props.autoScroll) {
  41. useAutoScroll(scrollRef);
  42. }
  43. const flexBasis = computed(() => {
  44. return Math.fround(100 / props.columns.length) + '%';
  45. });
  46. function get(o, p) {
  47. const d = _.get(o, p);
  48. return _.isNil(d) ? props.defaultValue : d === '' ? props.defaultValue : d;
  49. }
  50. </script>
  51. <style lang="less" scoped>
  52. @import '/@/design/theme.less';
  53. @import '@/design/theme.less';
  54. @font-face {
  55. font-family: 'douyuFont';
  56. src: url('/@/assets/font/douyuFont.otf');
  57. }
  58. @{theme-green} {
  59. .table__content {
  60. --image-content-label: url(/@/assets/images/themify/green/company/content-label.png);
  61. --image-content-text: url('/@/assets/images/themify/green/company/content-text.png');
  62. --image-list-head: url('/@/assets/images/themify/green/home-container/configurable/firehome/list-head.png');
  63. }
  64. }
  65. @{theme-deepblue} {
  66. .table__content {
  67. --image-content-label: url(/@/assets/images/themify/deepblue/company/content-label.png);
  68. --image-content-text: url('/@/assets/images/themify/deepblue/company/content-text.png');
  69. --image-list-head: url('/@/assets/images/themify/deepblue/home-container/configurable/firehome/list-head.png');
  70. }
  71. }
  72. .table__content {
  73. --image-content-label: url(/@/assets/images/company/content-label.png);
  74. --image-content-text: url('/@/assets/images/company/content-text.png');
  75. --image-list-head: url('/@/assets/images/home-container/configurable/firehome/list-head.png');
  76. --image-content-label-d: url(/@/assets/images/home-container/configurable/minehome/content-label.png);
  77. --image-content-body-d: url('/@/assets/images/home-container/configurable/minehome/content-body.png');
  78. height: 100%;
  79. box-sizing: border-box;
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. padding: 5px 0;
  84. .table__content_label {
  85. width: 400px;
  86. height: 32px;
  87. display: flex;
  88. justify-content: space-around;
  89. align-items: center;
  90. .label-t {
  91. text-align: center;
  92. font-size: 14px;
  93. }
  94. }
  95. .table__content_label_A {
  96. background-image: var(--image-content-label);
  97. background-size: 100% 100%;
  98. background-repeat: no-repeat;
  99. color: #31b9ef;
  100. }
  101. .table__content_label_B {
  102. background-image: linear-gradient(to top, #04698c, #04698c00);
  103. background-size: 100% 100%;
  104. background-repeat: no-repeat;
  105. color: #31b9ef;
  106. }
  107. .table__content_label_C {
  108. background-position: center 100%;
  109. background-size: 100% 25px;
  110. background-repeat: no-repeat;
  111. background-image: var(--image-content-text);
  112. height: 40px;
  113. .label-t {
  114. background-repeat: no-repeat;
  115. background-size: 80% auto;
  116. background-position: center;
  117. background-image: var(--image-list-head);
  118. }
  119. }
  120. .table__content_list {
  121. height: calc(100% - 32px);
  122. width: 400px;
  123. display: flex;
  124. flex-direction: column;
  125. padding: 5px 0;
  126. box-sizing: border-box;
  127. overflow-y: auto;
  128. .table__content_list_row {
  129. width: 100%;
  130. display: flex;
  131. justify-content: space-around;
  132. align-items: center;
  133. color: #fff;
  134. margin-bottom: 5px;
  135. span {
  136. display: inline-block;
  137. text-align: center;
  138. }
  139. }
  140. }
  141. .table__content_list_A {
  142. .table__content_list_row {
  143. background-size: 100% auto;
  144. background-repeat: no-repeat;
  145. background-position: center bottom;
  146. background-image: var(--image-content-text);
  147. }
  148. }
  149. .table__content_list_C {
  150. .table__content_list_row {
  151. min-height: 50px;
  152. background-size: 100% auto;
  153. background-repeat: no-repeat;
  154. background-position: center bottom;
  155. background-image: var(--image-content-text);
  156. }
  157. }
  158. .table__content_label_D {
  159. width: calc(100% - 10px);
  160. background-image: var(--image-content-label-d);
  161. background-size: 100% 100%;
  162. background-repeat: no-repeat;
  163. color: #fff;
  164. }
  165. .table__content_list_D {
  166. width: calc(100% - 10px);
  167. background-image: var(--image-content-body-d);
  168. background-size: 100% 100%;
  169. padding: 5px;
  170. .table__content_list_row {
  171. height: 20%;
  172. margin: 0;
  173. }
  174. /* 奇数行背景颜色 */
  175. .table__content_list_row:nth-child(odd) {
  176. background: #061b24;
  177. }
  178. /* 偶数行背景颜色 */
  179. .table__content_list_row:nth-child(even) {
  180. background: #092b3a;
  181. }
  182. }
  183. }
  184. </style>