CollapseTable.vue 3.9 KB

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