UnisKB/ui/src/components/card-box/index.vue

88 lines
2.1 KiB
Vue
Raw Normal View History

2023-10-25 10:35:28 +00:00
<template>
2023-11-02 01:56:14 +00:00
<el-card shadow="always" class="card-box" @mouseenter="cardEnter()" @mouseleave="cardLeave()">
2023-10-25 10:35:28 +00:00
<div class="card-header">
<slot name="header">
2023-10-26 10:37:13 +00:00
<div class="title flex align-center">
2023-11-27 10:08:58 +00:00
<AppAvatar v-if="!slots.icon && showIcon" class="mr-12" shape="square" :size="32">
2023-11-03 08:12:57 +00:00
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" />
2023-10-25 10:35:28 +00:00
</AppAvatar>
2023-11-27 10:08:58 +00:00
<slot v-else name="icon"> </slot>
2023-11-28 10:26:31 +00:00
<h4 class="ellipsis-1" style="width: 100%">{{ title }}</h4>
2023-10-25 10:35:28 +00:00
</div>
</slot>
</div>
2023-11-03 08:12:57 +00:00
<div class="description mt-12">
2023-10-25 10:35:28 +00:00
<slot name="description">
{{ description }}
</slot>
</div>
<slot />
<slot name="mouseEnter" v-if="$slots.mouseEnter && show" />
<div class="card-footer" v-if="$slots.footer">
<slot name="footer" />
</div>
</el-card>
</template>
<script setup lang="ts">
2023-11-27 10:08:58 +00:00
import { ref, useSlots } from 'vue'
const slots = useSlots()
2023-10-25 10:35:28 +00:00
defineOptions({ name: 'CardBox' })
2023-11-27 10:08:58 +00:00
const props = withDefaults(
defineProps<{
/**
* 标题
*/
title?: string
/**
* 描述
*/
description?: string
/**
* 是否展示icon
*/
showIcon?: boolean
}>(),
{ title: '标题', description: '', showIcon: true }
)
2023-10-25 10:35:28 +00:00
const show = ref(false)
function cardEnter() {
show.value = true
}
function cardLeave() {
show.value = false
}
</script>
<style lang="scss" scoped>
.card-box {
font-size: 14px;
position: relative;
2023-11-03 08:12:57 +00:00
min-height: var(--card-min-height);
2023-11-28 10:26:31 +00:00
min-width: var(--card-min-width);
2023-11-17 03:36:16 +00:00
border: 1px solid #ffffff;
2023-11-24 06:49:25 +00:00
border-radius: 8px;
2023-10-25 10:35:28 +00:00
.description {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
2023-11-28 10:26:31 +00:00
height: var(--app-card-box-description-height, 40px);
2023-11-03 08:12:57 +00:00
color: var(--app-text-color-secondary);
line-height: 22px;
font-weight: 400;
2023-10-25 10:35:28 +00:00
}
.card-footer {
position: absolute;
2023-11-03 08:12:57 +00:00
bottom: 8px;
2023-11-13 11:02:13 +00:00
left: 0;
2023-10-25 10:35:28 +00:00
min-height: 30px;
2023-11-03 08:12:57 +00:00
color: var(--app-text-color-secondary);
font-weight: 400;
2023-11-13 11:02:13 +00:00
padding: 0 16px;
width: 100%;
box-sizing: border-box;
2023-10-25 10:35:28 +00:00
}
}
</style>