HomeCard.vue 2.0 KB

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