1
0

index.vue 2.2 KB

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