index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div class="head-layer">
  3. <el-tabs :modelValue="modelValue" @update:modelValue="(str: any) => updateModelValue(str)">
  4. <el-tab-pane v-for="item in options" :key="item.value" :label="item.name"
  5. :name="item.value">
  6. </el-tab-pane>
  7. </el-tabs>
  8. <div class="head-content-layer" :class="{ show: show }" v-if="!notContent">
  9. <div class="head-content">
  10. <slot />
  11. </div>
  12. <div class="display" @click="show = !show" v-if="showCtrl">
  13. <template v-if="show">
  14. <span>收起</span>
  15. <el-icon>
  16. <ArrowUp />
  17. </el-icon>
  18. </template>
  19. <template v-else>
  20. <span>展开</span>
  21. <el-icon>
  22. <ArrowDown />
  23. </el-icon>
  24. </template>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import { ref } from "vue";
  31. import { Options } from "./head";
  32. const props = withDefaults(
  33. defineProps<{
  34. options: Options;
  35. modelValue?: any;
  36. showCtrl?: boolean;
  37. notContent?: boolean;
  38. }>(),
  39. {
  40. notContent: false,
  41. showCtrl: false,
  42. }
  43. );
  44. const activeValue = ref(props.modelValue || props.options[0].value);
  45. const emit = defineEmits<{ (e: "update:modelValue", modelValue: string): void }>();
  46. const updateModelValue = (modelValue: string) => {
  47. if ("modelValue" in props) {
  48. emit("update:modelValue", modelValue);
  49. } else {
  50. activeValue.value = modelValue;
  51. }
  52. };
  53. const show = ref(true);
  54. </script>
  55. <style lang="scss" scoped>
  56. .head-layer {
  57. background-color: #fff;
  58. border-radius: 4px;
  59. }
  60. .head-content-layer {
  61. padding: 16px 154px 16px 16px;
  62. position: relative;
  63. .head-content {
  64. overflow: hidden;
  65. height: 42px;
  66. }
  67. &.show {
  68. padding-bottom: 16px;
  69. .head-content {
  70. height: auto;
  71. }
  72. }
  73. .display {
  74. position: absolute;
  75. top: 16px;
  76. right: 16px;
  77. color: var(--primaryColor);
  78. font-size: 0.85rem;
  79. cursor: pointer;
  80. i {
  81. color: currentColor;
  82. font-size: 1em;
  83. margin-left: 5px;
  84. }
  85. }
  86. }
  87. </style>
  88. <style>
  89. .head-layer .el-tabs__nav-wrap {
  90. padding: 0 16px;
  91. }
  92. .head-layer .el-tabs__header {
  93. margin-bottom: 0;
  94. }
  95. .head-layer .el-form-item {
  96. margin-bottom: 0;
  97. }
  98. </style>