HomeCard.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <script setup lang="ts">
  2. import { toRefs, computed } from "vue";
  3. import _ from "lodash";
  4. const props = withDefaults(
  5. defineProps<{
  6. title?: string;
  7. color?: "info" | "skyblue" | "white";
  8. backgroundStyle?: Record<string, string>;
  9. }>(),
  10. {
  11. color: "info",
  12. backgroundStyle: { right: "16px", bottom: "24px" },
  13. }
  14. );
  15. const { title, color } = toRefs(props);
  16. const styles = computed(() => {
  17. return _.get(
  18. {
  19. info: {
  20. backgroundColor: "#f5f9ff",
  21. borderColor: "#e2eeff",
  22. },
  23. skyblue: {
  24. backgroundColor: "#f6fdff",
  25. borderColor: "#e3f8f4",
  26. },
  27. white: {
  28. borderColor: "#e2eeff",
  29. backgroundColor: "#fff",
  30. },
  31. },
  32. color.value
  33. );
  34. });
  35. </script>
  36. <template>
  37. <div class="card" :style="styles">
  38. <div v-if="$slots.background" class="background" :style="props.backgroundStyle">
  39. <slot name="background"> </slot>
  40. </div>
  41. <slot name="title">
  42. <h2 v-if="title">
  43. {{ title }}
  44. </h2>
  45. </slot>
  46. <el-row :gutter="20" tag="section">
  47. <slot></slot>
  48. </el-row>
  49. </div>
  50. </template>
  51. <style lang="scss" scoped>
  52. h2 {
  53. border: none;
  54. margin: 0;
  55. padding: 0;
  56. }
  57. .card {
  58. position: relative;
  59. display: flex;
  60. flex-direction: column;
  61. align-items: stretch;
  62. gap: 24px;
  63. border-radius: 20px;
  64. padding: 32px;
  65. background: #f5f9ff;
  66. border: 1px solid #e2eeff;
  67. min-height: 240px;
  68. :deep(.card) {
  69. min-height: 162px;
  70. }
  71. .background {
  72. position: absolute;
  73. }
  74. h2 {
  75. display: flex;
  76. align-items: center;
  77. .prefix {
  78. margin-right: 8px;
  79. }
  80. .suffix {
  81. width: 24px;
  82. height: 24px;
  83. margin-left: 8px;
  84. color: #00000042;
  85. }
  86. }
  87. .el-row {
  88. row-gap: 20px;
  89. align-items: stretch;
  90. }
  91. }
  92. </style>