CollapseTable.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="table__content">
  3. <div class="table__content_label">
  4. <div class="label-t" v-for="(item, index) in columns" :key="`svvhbcth-${index}`" :style="{ flexBasis }">{{ item.name }}</div>
  5. </div>
  6. <Collapse v-model:activeKey="avtiveCollapse" ghost class="table__content_list" :style="{ height: contentHeight }">
  7. <CollapsePanel
  8. v-for="(item, index) in data"
  9. :key="`svvhbct-${index}`"
  10. class="table__content_list_row"
  11. :showArrow="item.hideCollapses ? false : showArrow"
  12. >
  13. <template #header>
  14. <div v-for="(t, i) in columns" :key="`svvhbctr-${i}`" :style="{ flexBasis }">
  15. <slot :name="t.prop" :scope="item">
  16. <span>{{ get(item, t.prop) }}</span>
  17. </slot>
  18. </div>
  19. </template>
  20. <template v-if="!item.hideCollapses" #default>
  21. <p v-for="(t, i) in collapses" :key="`svvhbctc-${i}`" class="table__content_list_collapse"> {{ t.name }}:{{ get(item, t.prop) }} </p>
  22. </template>
  23. </CollapsePanel>
  24. </Collapse>
  25. </div>
  26. </template>
  27. <script lang="ts" setup>
  28. import { computed, defineProps, ref } from 'vue';
  29. import _ from 'lodash';
  30. import { Collapse, CollapsePanel } from 'ant-design-vue';
  31. let props = withDefaults(
  32. defineProps<{
  33. /** 列表表头配置,每个prop都有其对应的slot来提供定制化功能 */
  34. columns: { prop: string; name: string }[];
  35. collapses: { prop: string; name: string }[];
  36. data: any[];
  37. defaultValue: string;
  38. contentHeight: string;
  39. showArrow: boolean;
  40. /** 是否自动过滤折叠展开后无有效内容的项 */
  41. filterNil: boolean;
  42. }>(),
  43. {
  44. columns: () => [],
  45. collapses: () => [],
  46. data: () => [],
  47. defaultValue: '/',
  48. contentHeight: '220px',
  49. showArrow: true,
  50. filterNil: false,
  51. }
  52. );
  53. const avtiveCollapse = ref('svvhbct-0');
  54. const flexBasis = computed(() => {
  55. return Math.fround(100 / props.columns.length) + '%';
  56. });
  57. function get(o, p) {
  58. const d = _.get(o, p, props.defaultValue);
  59. return d === null ? props.defaultValue : d;
  60. }
  61. </script>
  62. <style lang="less" scoped>
  63. @font-face {
  64. font-family: 'douyuFont';
  65. src: url('@/assets/font/douyuFont.otf');
  66. }
  67. .table__content {
  68. height: 100%;
  69. width: 100%;
  70. box-sizing: border-box;
  71. display: flex;
  72. flex-direction: column;
  73. align-items: center;
  74. .table__content_label {
  75. width: 366px;
  76. height: 32px;
  77. display: flex;
  78. justify-content: space-around;
  79. align-items: center;
  80. background: url('@/assets/images/company/content-label.png') no-repeat;
  81. .label-t {
  82. color: #3df6ff;
  83. text-align: center;
  84. font-size: 14px;
  85. }
  86. }
  87. .table__content_list {
  88. height: calc(100% - 32px);
  89. width: 366px;
  90. display: flex;
  91. flex-direction: column;
  92. // justify-content: space-around;
  93. justify-content: flex-start;
  94. padding: 5px 0px;
  95. box-sizing: border-box;
  96. overflow-y: auto;
  97. .table__content_list_row {
  98. // width: 100%;
  99. // display: flex;
  100. // justify-content: space-around;
  101. // align-items: flex-start;
  102. background: url('@/assets/images/company/content-text.png') no-repeat;
  103. background-size: 100% auto;
  104. color: @white;
  105. padding: 5px 0;
  106. // span {
  107. // display: inline-block;
  108. // text-align: center;
  109. // }
  110. }
  111. .table__content_list_collapse {
  112. text-align: left;
  113. color: @white;
  114. margin-left: 10px;
  115. }
  116. }
  117. }
  118. .table__content :deep(.zxm-collapse > .zxm-collapse-item > .zxm-collapse-header) {
  119. padding: 0;
  120. color: @white;
  121. }
  122. :deep(.zxm-collapse > .zxm-collapse-item > .zxm-collapse-header .zxm-collapse-arrow) {
  123. position: absolute;
  124. top: 3px;
  125. }
  126. </style>