index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <el-card class="hc-card-box" shadow="never"
  3. :class="[
  4. (isSlotHeader || title || isSlotExtra || extraText)?'is-header':'',
  5. isSlotSearchBar?'is-search-bar':'',
  6. `is-action-${actionSize}`,
  7. ui
  8. ]"
  9. >
  10. <template #header v-if="isSlotHeader || title || isSlotExtra || extraText">
  11. <div class="hc-card-header-box">
  12. <div class="hc-card-header">
  13. <div class="title text-lg" v-if="!isSlotHeader && title">{{ title }}</div>
  14. <slot v-if="isSlotHeader" name='header'/>
  15. </div>
  16. <div class="hc-card-header-extra" v-if="isSlotExtra || extraText">
  17. <div class="extra" v-if="!isSlotExtra && extraText">{{ extraText }}</div>
  18. <slot v-if="isSlotExtra" name='extra'/>
  19. </div>
  20. </div>
  21. </template>
  22. <div class="hc-card-search-bar" v-if="isSlotSearchBar">
  23. <slot name='search'/>
  24. </div>
  25. <div class="hc-card-main-box" :id="idRef" :class="isSlotAction?'is-action':''">
  26. <template v-if="scrollbar">
  27. <el-scrollbar>
  28. <slot></slot>
  29. </el-scrollbar>
  30. </template>
  31. <template v-else>
  32. <slot></slot>
  33. </template>
  34. </div>
  35. <div class="hc-card-action-box" v-if="isSlotAction">
  36. <slot name='action'/>
  37. </div>
  38. </el-card>
  39. </template>
  40. <script setup>
  41. import {ref,useSlots} from "vue";
  42. const props = defineProps({
  43. ui: {
  44. type: String,
  45. default: ''
  46. },
  47. title: {
  48. type: [String,Number],
  49. default: ''
  50. },
  51. extraText: {
  52. type: [String,Number],
  53. default: ''
  54. },
  55. scrollbar: {
  56. type: Boolean,
  57. default: true
  58. },
  59. actionSize: {
  60. type: [String,Number],
  61. default: 'df'
  62. },
  63. idRef: {
  64. type: [String,Number],
  65. default: ''
  66. },
  67. })
  68. const slots = useSlots()
  69. //判断<slot>是否有传值
  70. const isSlotHeader = ref(!!slots.header);
  71. const isSlotExtra = ref(!!slots.extra);
  72. const isSlotAction = ref(!!slots.action);
  73. const isSlotSearchBar = ref(!!slots.search);
  74. </script>
  75. <style lang="scss">
  76. .hc-card-box.el-card {
  77. height: 100%;
  78. position: relative;
  79. --el-card-padding: 24px;
  80. --el-card-bg-color: #f1f5f8;
  81. --el-card-border-radius: 10px;
  82. --el-text-color-primary: #1A1A1A;
  83. box-shadow: -2px 0 10px 0 rgba(32,37,50,0.03), 0 10px 21px 20px rgba(32,37,50,0.03);
  84. border: 0;
  85. .el-card__header {
  86. height: 70px;
  87. padding: 14px 24px;
  88. border-bottom: 1px solid #e9e9e9;
  89. }
  90. .hc-card-header-box {
  91. position: relative;
  92. display: flex;
  93. align-items: center;
  94. .hc-card-header {
  95. position: relative;
  96. flex: 1;
  97. display: flex;
  98. align-items: center;
  99. }
  100. .hc-card-header-extra {
  101. position: relative;
  102. display: flex;
  103. align-items: center;
  104. }
  105. }
  106. .el-card__body {
  107. position: relative;
  108. height: 100%;
  109. .hc-card-search-bar {
  110. position: relative;
  111. margin-bottom: 20px;
  112. }
  113. .hc-card-main-box {
  114. position: relative;
  115. height: 100%;
  116. }
  117. .hc-card-action-box {
  118. position: absolute;
  119. height: auto;
  120. margin: -24px;
  121. width: 100%;
  122. bottom: 24px;
  123. padding: 20px 24px;
  124. border-top: 1px solid #e9e9e9;
  125. background-color: #f1f5f8;
  126. }
  127. }
  128. &.is-header .el-card__body {
  129. height: calc(100% - 70px);
  130. }
  131. &.is-header .el-card__body .hc-card-main-box:not(.is-action) {
  132. height: 100%;
  133. }
  134. &.is-action-df .el-card__body .hc-card-main-box.is-action {
  135. height: calc(100% - 63.5px);
  136. }
  137. &.is-action-lg .el-card__body .hc-card-main-box.is-action {
  138. height: calc(100% - 80px);
  139. }
  140. &.is-search-bar.is-action-df .el-card__body .hc-card-main-box {
  141. height: calc(100% - 40px);
  142. &.is-action {
  143. height: calc(100% - 124px);
  144. }
  145. }
  146. &.is-search-bar.is-action-lg .el-card__body .hc-card-main-box {
  147. height: calc(100% - 40px);
  148. &.is-action {
  149. height: calc(100% - 124px);
  150. }
  151. }
  152. }
  153. .hc-card-box.el-card:not(.is-header) {
  154. .el-card__body {
  155. height: 100%;
  156. }
  157. }
  158. </style>