hc-new-card.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <HcCard class="hc-new-card-box">
  3. <template v-if="isSlotHeader || titles || isSlotExtra || extraText">
  4. <div class="hc-card-header-box">
  5. <div class="hc-card-header">
  6. <div v-if="!isSlotHeader && titles" class="title">{{ titles }}</div>
  7. <slot v-if="isSlotHeader" name="header" />
  8. </div>
  9. <div v-if="isSlotExtra || extraText" class="hc-card-header-extra">
  10. <div v-if="!isSlotExtra && extraText" class="extra">{{ extraText }}</div>
  11. <slot v-if="isSlotExtra" name="extra" />
  12. </div>
  13. </div>
  14. </template>
  15. <div v-if="isSlotSearchBar" class="hc-card-search-bar">
  16. <slot name="search" />
  17. </div>
  18. <div class="hc-card-main">
  19. <div class="hc-card-main-body">
  20. <template v-if="scrollbar">
  21. <el-scrollbar>
  22. <slot />
  23. </el-scrollbar>
  24. </template>
  25. <template v-else>
  26. <slot />
  27. </template>
  28. </div>
  29. </div>
  30. <div v-if="isSlotAction" class="hc-card-action">
  31. <slot name="action" />
  32. </div>
  33. </HcCard>
  34. </template>
  35. <script setup>
  36. import { ref, useSlots, watch } from 'vue'
  37. const props = defineProps({
  38. ui: {
  39. type: String,
  40. default: '',
  41. },
  42. title: {
  43. type: [String, Number],
  44. default: '',
  45. },
  46. extraText: {
  47. type: [String, Number],
  48. default: '',
  49. },
  50. scrollbar: {
  51. type: Boolean,
  52. default: false,
  53. },
  54. actionSize: {
  55. type: [String, Number],
  56. default: 'lg',
  57. },
  58. idRef: {
  59. type: [String, Number],
  60. default: '',
  61. },
  62. bodyUi: {
  63. type: String,
  64. default: '',
  65. },
  66. actionUi: {
  67. type: String,
  68. default: '',
  69. },
  70. })
  71. const titles = ref(props.title)
  72. //监听
  73. watch(() => props.title, (val) => {
  74. titles.value = val ?? ''
  75. })
  76. //判断<slot>是否有传值
  77. const slots = useSlots()
  78. const isSlotHeader = ref(!!slots.header)
  79. const isSlotExtra = ref(!!slots.extra)
  80. const isSlotAction = ref(!!slots.action)
  81. const isSlotSearchBar = ref(!!slots.search)
  82. </script>
  83. <style lang="scss">
  84. .el-card.hc-new-card-box {
  85. background: white;
  86. --el-card-padding: 10px;
  87. .hc-card-main-box {
  88. display: flex;
  89. flex-direction: column;
  90. }
  91. .hc-card-header-box {
  92. position: relative;
  93. display: flex;
  94. align-items: center;
  95. flex-shrink: 0;
  96. height: auto;
  97. border-bottom: 1px solid #E9E9E9;
  98. margin-bottom: 10px;
  99. .hc-card-header {
  100. position: relative;
  101. flex: 1;
  102. display: flex;
  103. align-items: center;
  104. .title {
  105. }
  106. }
  107. .hc-card-header-extra {
  108. position: relative;
  109. display: flex;
  110. align-items: center;
  111. margin-left: 24px;
  112. .extra {
  113. }
  114. }
  115. }
  116. .hc-card-search-bar {
  117. position: relative;
  118. display: flex;
  119. align-items: center;
  120. flex-shrink: 0;
  121. }
  122. .hc-card-main {
  123. position: relative;
  124. flex: 1;
  125. flex-basis: auto;
  126. .hc-card-main-body {
  127. position: absolute;
  128. inset: 0;
  129. }
  130. }
  131. .hc-card-action {
  132. position: relative;
  133. display: flex;
  134. align-items: center;
  135. flex-shrink: 0;
  136. }
  137. }
  138. </style>