wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<script setup lang="ts">
import { ElCollapseItem, ElSwitch } from 'element-plus-secondary'
import { computed, PropType, ref, toRefs } from 'vue'
 
const props = defineProps({
  modelValue: {
    type: Boolean
  },
  changeModel: {
    type: Object
  },
  title: String,
  themes: {
    type: String as PropType<EditorTheme>,
    default: 'dark'
  },
  showSwitch: {
    type: Boolean,
    required: false,
    default: true
  }
})
const emit = defineEmits(['update:modelValue', 'modelChange'])
const { changeModel, title, themes } = toRefs(props)
 
const collapseItem = ref()
const onSwitchChange = () => {
  emit('modelChange', changeModel.value)
  if (!props.modelValue && !collapseItem.value.isActive) {
    collapseItem.value.handleHeaderClick()
  }
 
  if (props.modelValue && collapseItem.value.isActive) {
    collapseItem.value.handleHeaderClick()
  }
}
const switchValue = computed({
  get() {
    return props.modelValue
  },
  set(value) {
    emit('update:modelValue', value)
  }
})
</script>
<template>
  <el-collapse-item ref="collapseItem" :effect="themes" v-bind="$attrs">
    <template #title>
      <div class="collapse-header">
        <span>
          {{ title }}
        </span>
        <div>
          <el-switch
            v-show="showSwitch"
            v-model="switchValue"
            :effect="themes"
            size="small"
            @click.stop="onSwitchChange"
          />
        </div>
      </div>
    </template>
    <slot />
  </el-collapse-item>
</template>
<style scoped lang="less">
.collapse-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 10px;
  flex-grow: 1;
  :deep(.ed-switch.is-checked .ed-switch__core > .ed-switch__action) {
    left: calc(100% - 12px);
  }
  :deep(span.ed-switch__core) {
    min-width: 24px;
    border: none;
    height: 6px;
    border-radius: 3px;
    .ed-switch__action {
      left: 0;
      box-shadow: 0 2px 4px rgba(31, 35, 41, 0.12);
    }
  }
}
</style>