CustomTable.vue 6.7 KB

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