CommonTable.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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}`">{{ 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}`">
  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 { 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. function get(o, p) {
  36. return _.get(o, p, props.defaultValue);
  37. }
  38. </script>
  39. <style lang="less" scoped>
  40. @font-face {
  41. font-family: 'douyuFont';
  42. src: url('@/assets/font/douyuFont.otf');
  43. }
  44. .table__content {
  45. height: 100%;
  46. box-sizing: border-box;
  47. display: flex;
  48. flex-direction: column;
  49. align-items: center;
  50. .table__content_label {
  51. width: 366px;
  52. height: 32px;
  53. display: flex;
  54. justify-content: space-around;
  55. align-items: center;
  56. background: url('@/assets/images/company/content-label.png') no-repeat;
  57. .label-t {
  58. color: #3df6ff;
  59. text-align: center;
  60. font-size: 14px;
  61. }
  62. }
  63. .table__content_list {
  64. height: calc(100% - 32px);
  65. width: 378px;
  66. display: flex;
  67. flex-direction: column;
  68. // justify-content: space-around;
  69. justify-content: flex-start;
  70. padding: 5px 0px;
  71. box-sizing: border-box;
  72. overflow-y: auto;
  73. .table__content_list_row {
  74. width: 100%;
  75. height: 28px;
  76. display: flex;
  77. justify-content: space-around;
  78. align-items: flex-start;
  79. background: url('@/assets/images/company/content-text.png') no-repeat;
  80. color: #fff;
  81. margin-bottom: 5px;
  82. span {
  83. display: inline-block;
  84. text-align: center;
  85. }
  86. }
  87. }
  88. }
  89. </style>