CardLayout.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!--
  2. * @since: 2024-12-30
  3. * CardLayout.vue
  4. -->
  5. <template>
  6. <div class="layout">
  7. <section class="header" v-if="title">
  8. <header class="card-title">
  9. {{ title }}
  10. <span class="mandatory" v-if="mandatory">*</span>
  11. </header>
  12. <slot name="actions"></slot>
  13. </section>
  14. <slot></slot>
  15. <div class="flex items-center cursor-pointer new-action w-[70px]" v-if="!isViewMode && showAddNewButton" @click="$emit('handleAddNew')">
  16. <el-button type="primary" :icon="Plus" circle size="small" />
  17. <span style="margin-left: 10px; padding-top: 2px">新增</span>
  18. </div>
  19. </div>
  20. </template>
  21. <script setup lang="ts">
  22. import { inject } from 'vue';
  23. import { Plus } from '@element-plus/icons-vue';
  24. interface LayoutSetting {
  25. title?: string;
  26. mandatory?: boolean;
  27. showAddNewButton?: boolean;
  28. isShowWraning?: boolean;
  29. }
  30. withDefaults(defineProps<LayoutSetting>(), {
  31. mandatory: false,
  32. showAddNewButton: false,
  33. isShowWraning: false,
  34. });
  35. const isViewMode = inject('isViewMode', false);
  36. defineEmits<{
  37. (event: 'handleAddNew'): void;
  38. }>();
  39. </script>
  40. <style scoped lang="scss">
  41. .layout {
  42. margin-bottom: 20px;
  43. border-bottom: 4px solid #d3eafe;
  44. }
  45. .layout:last-child {
  46. border: none;
  47. }
  48. .header {
  49. margin-bottom: 20px;
  50. padding-right: 20px;
  51. display: flex;
  52. justify-content: space-between;
  53. align-items: center;
  54. .card-title {
  55. height: 20px;
  56. line-height: 20px;
  57. font-size: 16px;
  58. font-weight: bold;
  59. &::before {
  60. content: ' ';
  61. display: inline;
  62. padding: 2px;
  63. margin-right: 10px;
  64. background-color: #409eff;
  65. height: 80%;
  66. }
  67. }
  68. }
  69. .mandatory {
  70. color: var(--el-color-danger);
  71. }
  72. .new-action {
  73. margin-bottom: 20px;
  74. }
  75. .warningTip {
  76. margin-left: 10px;
  77. }
  78. </style>