item.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="hc-card-item-box"
  3. :class="[
  4. (isSlotHeader || title || isSlotExtra || extraText)?'is-header':'',
  5. isSlotAction ? 'is-action' : '', ui
  6. ]">
  7. <div class="hc-card-item-header" v-if="isSlotHeader || title || isSlotExtra || extraText">
  8. <div class="item-header">
  9. <span v-if="!isSlotHeader && title">{{ title }}</span>
  10. <slot v-if="isSlotHeader" name='header'/>
  11. </div>
  12. <div class="item-extra" v-if="isSlotExtra || extraText">
  13. <span v-if="!isSlotExtra && extraText">{{ extraText }}</span>
  14. <slot v-if="isSlotExtra" name='extra'/>
  15. </div>
  16. </div>
  17. <div class="hc-card-item-body">
  18. <template v-if="scrollbar">
  19. <el-scrollbar>
  20. <slot></slot>
  21. </el-scrollbar>
  22. </template>
  23. <template v-else>
  24. <slot></slot>
  25. </template>
  26. </div>
  27. <div class="hc-card-item-action" v-if="isSlotAction">
  28. <slot name='action'/>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup>
  33. import {ref,useSlots} from "vue";
  34. const props = defineProps({
  35. ui: {
  36. type: String,
  37. default: ''
  38. },
  39. title: {
  40. type: [String,Number],
  41. default: ''
  42. },
  43. extraText: {
  44. type: [String,Number],
  45. default: ''
  46. },
  47. scrollbar: {
  48. type: Boolean,
  49. default: false
  50. },
  51. })
  52. const slots = useSlots()
  53. //判断<slot>是否有传值
  54. const isSlotHeader = ref(!!slots.header);
  55. const isSlotExtra = ref(!!slots.extra);
  56. const isSlotAction = ref(!!slots.action);
  57. </script>
  58. <style lang="scss" scoped>
  59. .hc-card-item-box {
  60. position: relative;
  61. height: 100%;
  62. background: #E7EEF4;
  63. border-radius: 10px;
  64. padding: 14px;
  65. .hc-card-item-header {
  66. position: relative;
  67. font-weight: bold;
  68. display: flex;
  69. align-items: center;
  70. height: 32px;
  71. margin-bottom: 14px;
  72. color: var(--el-color-primary-dark-2);
  73. .item-header {
  74. flex: 1;
  75. position: relative;
  76. display: flex;
  77. align-items: center;
  78. }
  79. .item-extra {
  80. position: relative;
  81. display: flex;
  82. align-items: center;
  83. margin-left: 120px;
  84. }
  85. }
  86. .hc-card-item-body {
  87. position: relative;
  88. height: 100%;
  89. overflow: hidden;
  90. }
  91. .hc-card-item-action {
  92. position: relative;
  93. margin-top: 18px;
  94. height: 32px;
  95. }
  96. &.is-header:not(.is-action),
  97. &.is-action:not(.is-header) {
  98. .hc-card-item-body {
  99. height: calc(100% - 46px);
  100. }
  101. }
  102. &.is-header.is-action .hc-card-item-body {
  103. height: calc(100% - 46px - 50px);
  104. }
  105. }
  106. </style>