index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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<{
  49. (e: "update:modelValue", modelValue: string): void;
  50. }>();
  51. const updateModelValue = (modelValue: string) => {
  52. if ("modelValue" in props) {
  53. console.log(modelValue, props);
  54. emit("update:modelValue", modelValue);
  55. } else {
  56. activeValue.value = modelValue;
  57. }
  58. };
  59. const show = ref(true);
  60. </script>
  61. <style lang="scss" scoped>
  62. .head-layer {
  63. background-color: #fff;
  64. border-radius: 4px;
  65. }
  66. .head-content-layer {
  67. padding: 16px 154px 16px 16px;
  68. position: relative;
  69. .head-content {
  70. overflow: hidden;
  71. height: 42px;
  72. }
  73. &.show {
  74. padding-bottom: 16px;
  75. .head-content {
  76. height: auto;
  77. }
  78. }
  79. .display {
  80. position: absolute;
  81. top: 16px;
  82. right: 16px;
  83. color: var(--primaryColor);
  84. font-size: 0.85rem;
  85. cursor: pointer;
  86. i {
  87. color: currentColor;
  88. font-size: 1em;
  89. margin-left: 5px;
  90. }
  91. }
  92. }
  93. </style>
  94. <style>
  95. .head-layer .el-tabs__nav-wrap {
  96. padding: 0 16px;
  97. }
  98. .head-layer .el-tabs__header {
  99. margin-bottom: 0;
  100. }
  101. .head-layer .el-form-item {
  102. margin-bottom: 0;
  103. }
  104. </style>