123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <HcCard class="hc-new-card-box">
- <template v-if="isSlotHeader || titles || isSlotExtra || extraText">
- <div class="hc-card-header-box">
- <div class="hc-card-header">
- <div v-if="!isSlotHeader && titles" class="title">{{ titles }}</div>
- <slot v-if="isSlotHeader" name="header" />
- </div>
- <div v-if="isSlotExtra || extraText" class="hc-card-header-extra">
- <div v-if="!isSlotExtra && extraText" class="extra">{{ extraText }}</div>
- <slot v-if="isSlotExtra" name="extra" />
- </div>
- </div>
- </template>
- <div v-if="isSlotSearchBar" class="hc-card-search-bar">
- <slot name="search" />
- </div>
- <div class="hc-card-main">
- <div class="hc-card-main-body">
- <template v-if="scrollbar">
- <el-scrollbar>
- <slot />
- </el-scrollbar>
- </template>
- <template v-else>
- <slot />
- </template>
- </div>
- </div>
- <div v-if="isSlotAction" class="hc-card-action">
- <slot name="action" />
- </div>
- </HcCard>
- </template>
- <script setup>
- import { ref, useSlots, watch } from 'vue'
- const props = defineProps({
- ui: {
- type: String,
- default: '',
- },
- title: {
- type: [String, Number],
- default: '',
- },
- extraText: {
- type: [String, Number],
- default: '',
- },
- scrollbar: {
- type: Boolean,
- default: false,
- },
- actionSize: {
- type: [String, Number],
- default: 'lg',
- },
- idRef: {
- type: [String, Number],
- default: '',
- },
- bodyUi: {
- type: String,
- default: '',
- },
- actionUi: {
- type: String,
- default: '',
- },
- })
- const titles = ref(props.title)
- //监听
- watch(() => props.title, (val) => {
- titles.value = val ?? ''
- })
- //判断<slot>是否有传值
- const slots = useSlots()
- const isSlotHeader = ref(!!slots.header)
- const isSlotExtra = ref(!!slots.extra)
- const isSlotAction = ref(!!slots.action)
- const isSlotSearchBar = ref(!!slots.search)
- </script>
- <style lang="scss">
- .el-card.hc-new-card-box {
- background: white;
- --el-card-padding: 10px;
- .hc-card-main-box {
- display: flex;
- flex-direction: column;
- }
- .hc-card-header-box {
- position: relative;
- display: flex;
- align-items: center;
- flex-shrink: 0;
- height: auto;
- border-bottom: 1px solid #E9E9E9;
- margin-bottom: 10px;
- .hc-card-header {
- position: relative;
- flex: 1;
- display: flex;
- align-items: center;
- .title {
- }
- }
- .hc-card-header-extra {
- position: relative;
- display: flex;
- align-items: center;
- margin-left: 24px;
- .extra {
- }
- }
- }
- .hc-card-search-bar {
- position: relative;
- display: flex;
- align-items: center;
- flex-shrink: 0;
- }
- .hc-card-main {
- position: relative;
- flex: 1;
- flex-basis: auto;
- .hc-card-main-body {
- position: absolute;
- inset: 0;
- }
- }
- .hc-card-action {
- position: relative;
- display: flex;
- align-items: center;
- flex-shrink: 0;
- }
- }
- </style>
|