CustomTable.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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>{{ getter(item, t.prop) }}</span>
  11. </slot>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import { computed } from 'vue';
  19. import { get, isNil } from 'lodash-es';
  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. autoScroll: false,
  32. columns: () => [],
  33. data: () => [],
  34. defaultValue: '-',
  35. }
  36. );
  37. const flexBasis = computed(() => {
  38. return Math.fround(100 / props.columns.length) + '%';
  39. });
  40. function getter(o, p) {
  41. const d = get(o, p);
  42. return isNil(d) ? props.defaultValue : d === '' ? props.defaultValue : d;
  43. }
  44. </script>
  45. <style lang="less" scoped>
  46. @import '/@/design/theme.less';
  47. @font-face {
  48. font-family: 'douyuFont';
  49. src: url('/@/assets/font/douyuFont.otf');
  50. }
  51. .table__content {
  52. --image-content-label-A: url('/@/assets/images/sealedGoaf/configurable/table/table-label-A.png');
  53. height: 100%;
  54. box-sizing: border-box;
  55. display: flex;
  56. flex-direction: column;
  57. align-items: center;
  58. padding: 5px 0;
  59. .table__content_label {
  60. width: 400px;
  61. height: 32px;
  62. display: flex;
  63. justify-content: space-around;
  64. align-items: center;
  65. .label-t {
  66. text-align: center;
  67. font-size: 14px;
  68. }
  69. }
  70. .table__content_list {
  71. height: calc(100% - 32px);
  72. width: 400px;
  73. display: flex;
  74. flex-direction: column;
  75. padding: 5px 0;
  76. box-sizing: border-box;
  77. overflow-y: auto;
  78. .table__content_list_row {
  79. width: 100%;
  80. display: flex;
  81. justify-content: space-around;
  82. align-items: center;
  83. color: #fff;
  84. margin-bottom: 5px;
  85. span {
  86. display: inline-block;
  87. text-align: center;
  88. }
  89. }
  90. }
  91. .table__content_label_A {
  92. background-image: var(--image-content-label-A);
  93. background-size: 100% 100%;
  94. background-repeat: no-repeat;
  95. color: #000000;
  96. width: 100%;
  97. padding-left: 10px;
  98. }
  99. .table__content_list_A {
  100. width: 100%;
  101. padding-left: 10px;
  102. font-weight: bold;
  103. font-size: 28px;
  104. }
  105. /* 第一个子元素:黑色 */
  106. .table__content_list_row .table__content__list_item_A:nth-child(1) {
  107. font-size: 14px;
  108. text-align: left;
  109. color: #000000;
  110. }
  111. /* 第二个子元素:蓝色 */
  112. .table__content_list_row .table__content__list_item_A:nth-child(2) {
  113. color: #0052cc;
  114. }
  115. /* 第三个子元素:黄色 */
  116. .table__content_list_row .table__content__list_item_A:nth-child(3) {
  117. color: #b39f01;
  118. }
  119. /* 第四个子元素:橙色 */
  120. .table__content_list_row .table__content__list_item_A:nth-child(4) {
  121. color: #e6a23d;
  122. }
  123. /* 第五个子元素:红色 */
  124. .table__content_list_row .table__content__list_item_A:nth-child(5) {
  125. color: #c45656;
  126. }
  127. .table__content_label_B {
  128. background-image: var(--image-content-label-A);
  129. background-size: 100% 100%;
  130. background-repeat: no-repeat;
  131. color: #000000;
  132. width: 100%;
  133. padding-left: 10px;
  134. }
  135. .table__content_list_B {
  136. width: 100%;
  137. padding-left: 10px;
  138. font-weight: bold;
  139. font-size: 28px;
  140. }
  141. /* 第一个子元素:黑色 */
  142. .table__content_list_row .table__content__list_item_B:nth-child(1) {
  143. font-size: 14px;
  144. text-align: left;
  145. color: #000000;
  146. }
  147. /* 第二个子元素:蓝色 */
  148. .table__content_list_row .table__content__list_item_B:nth-child(2) {
  149. color: #0052cc;
  150. }
  151. /* 第三个子元素:绿色 */
  152. .table__content_list_row .table__content__list_item_B:nth-child(3) {
  153. color: #4caf50;
  154. }
  155. /* 第四个子元素:橙色 */
  156. .table__content_list_row .table__content__list_item_B:nth-child(4) {
  157. color: #c97800;
  158. }
  159. /* 第五个子元素:红色 */
  160. .table__content_list_row .table__content__list_item_B:nth-child(5) {
  161. color: #c45656;
  162. }
  163. }
  164. .table__content_label_C {
  165. background-image: var(--image-content-label-A);
  166. background-size: 100% 100%;
  167. background-repeat: no-repeat;
  168. color: #000000;
  169. width: 100% !important;
  170. }
  171. .table__content_list_C {
  172. width: 100% !important;
  173. font-weight: bold;
  174. font-size: 15px;
  175. color: #000000;
  176. .table__content_list_row{
  177. color: #000000 !important;
  178. margin-bottom: 10px !important;
  179. }
  180. }
  181. // /* 第一个子元素:红色 */
  182. .table__content_list_row .table__content__list_item_C:nth-child(1) {
  183. color: #ff0000;
  184. }
  185. .table__content_label_D {
  186. background-image: var(--image-content-label-A);
  187. background-size: 100% 100%;
  188. background-repeat: no-repeat;
  189. color: #000000;
  190. width: 100% !important;
  191. }
  192. .table__content_list_D {
  193. width: 100% !important;
  194. font-weight: bold;
  195. font-size: 15px;
  196. color: #000000;
  197. text-align: center;
  198. }
  199. .table__content_list_row{
  200. color: #000000 !important;
  201. }
  202. .table__content_list_row .table__content__list_item_D:nth-child(1) {
  203. width: 50px;
  204. }
  205. .table__content_list_row .table__content__list_item_D:nth-child(3) {
  206. color: #2b6ff0;
  207. }
  208. .table__content_list_row .table__content__list_item_D:nth-child(4) {
  209. color: #107f30;
  210. }
  211. //
  212. .table__content_label_E {
  213. background-image: var(--image-content-label-A);
  214. background-size: 100% 100%;
  215. background-repeat: no-repeat;
  216. color: #000000;
  217. width: 100% !important;
  218. z-index: 10;
  219. }
  220. .table__content_list_E {
  221. width: 100% !important;
  222. font-weight: bold;
  223. font-size: 15px;
  224. color: #000000;
  225. text-align: center;
  226. z-index: 10;
  227. }
  228. .table__content_list_row{
  229. color: #000000 !important;
  230. }
  231. </style>