index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <el-card :body-class="bodyClass" :body-style="bodyStyle" class="vab-card" :shadow="shadow" :title="title">
  3. <template v-if="$slots.header || title" #header>
  4. <slot v-if="$slots.header" name="header"></slot>
  5. <template v-else>
  6. {{ title }}
  7. </template>
  8. </template>
  9. <el-skeleton v-if="skeleton" animated :loading="skeletonShow" :rows="skeletonRows">
  10. <template #default>
  11. <slot></slot>
  12. </template>
  13. </el-skeleton>
  14. <slot v-else></slot>
  15. <template v-if="$slots.footer" #footer>
  16. <slot name="footer"></slot>
  17. </template>
  18. </el-card>
  19. </template>
  20. <script lang="ts" setup>
  21. import { ElCard } from 'element-plus'
  22. defineOptions({
  23. name: 'VabCard',
  24. })
  25. defineProps({
  26. ...ElCard.props,
  27. shadow: {
  28. type: String,
  29. default: 'never',
  30. },
  31. skeleton: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. skeletonRows: {
  36. type: Number,
  37. default: 5, //显示的数量会比传入的数量多 1
  38. },
  39. title: {
  40. type: String,
  41. default: '',
  42. },
  43. calss: {
  44. type: String,
  45. default: '',
  46. },
  47. })
  48. const skeletonShow = ref<boolean>(true)
  49. const timer: any = setTimeout(() => {
  50. skeletonShow.value = false
  51. }, 500)
  52. onBeforeUnmount(() => {
  53. if (timer) clearTimeout(timer)
  54. })
  55. </script>
  56. <style lang="scss" scoped>
  57. .vab-card {
  58. :deep() {
  59. .el-card__header {
  60. font-weight: 500;
  61. [class*='ri-'] {
  62. background-image: linear-gradient(120deg, #bd34fe 30%, var(--el-color-primary));
  63. background-clip: text;
  64. -webkit-text-fill-color: transparent;
  65. }
  66. }
  67. .el-skeleton {
  68. height: 100%;
  69. overflow: hidden;
  70. }
  71. }
  72. }
  73. </style>