| @click="handleToggle" |
| 9 | > |
| 10 | <h3 class="section-title">{{ title }}</h3> |
| 11 | <div class="section-header-right"> |
| 12 | <span v-if="readonly && !hasValue" class="not-configured-badge"> |
| 13 | Not configured |
| 14 | </span> |
| 15 | <el-icon v-if="canToggle" class="collapse-arrow" :class="{ expanded }"> |
| 16 | <ArrowDown /> |
| 17 | </el-icon> |
| 18 | </div> |
| 19 | </div> |
| 20 | <div class="collapse-wrapper" :class="{ expanded }"> |
| 21 | <div class="collapse-inner"> |
| 22 | <div class="section-body"> |
| 23 | <slot /> |
| 24 | </div> |
| 25 | </div> |
| 26 | </div> |
| 27 | </template> |
| 28 |
| 29 | <!-- Non-collapsible: title and content in one area --> |
| 30 | <template v-else> |
| 31 | <div class="section-body"> |
| 32 | <h3 v-if="title" class="section-title section-title-inline">{{ title }}</h3> |
| 33 | <slot /> |
| 34 | </div> |
| 35 | </template> |
| 36 | </div> |
| 37 | </template> |
| 38 |
| 39 | <script setup lang="ts"> |
| 40 | import { ref, computed, watch } from 'vue' |
| 41 | import { ArrowDown } from '@element-plus/icons-vue' |
| 42 |
| 43 | const props = withDefaults( |
| 44 | defineProps<{ |
| 45 | title?: string |
| 46 | collapsible?: boolean |
| 47 | readonly?: boolean |
| 48 | hasValue?: boolean |
| 49 | }>(), |
| 50 | { |
| 51 | title: '', |
| 52 | collapsible: false, |
| 53 | readonly: false, |
| 54 | hasValue: true, |
| 55 | }, |
| 56 | ) |
| 57 |
| 58 | const computeInitial = () => { |
| 59 | if (!props.collapsible) return true |
| 60 | return props.hasValue |
| 61 | } |
| 62 |
| 63 | const expanded = ref(computeInitial()) |
| 64 |
| 65 | // Only auto-expand when hasValue goes from false to true (async data loaded) |
| 66 | // Never auto-collapse — don't override user interaction |
| 67 | watch( |
| 68 | () => props.hasValue, |
| 69 | (newVal, oldVal) => { |
| 70 | if (newVal && !oldVal && props.collapsible) { |
| 71 | expanded.value = true |
| 72 | } |
| 73 | }, |
| 74 | ) |
| 75 |
| 76 | const canToggle = computed(() => { |
| 77 | if (!props.collapsible) return false |
| 78 | if (props.readonly && !props.hasValue) return false |
| 79 | return true |
| 80 | }) |
| 81 |
| 82 | const handleToggle = () => { |
| 83 | if (canToggle.value) { |
| 84 | expanded.value = !expanded.value |
| 85 | } |
| 86 | } |
| 87 | </script> |
| 88 |
| 89 | <style scoped lang="scss"> |
| 90 | .config-section-card { |
| 91 | background: var(--el-bg-color); |
| 92 | border: 1px solid var(--color-border-lighter); |
| 93 | border-radius: 12px; |
| 94 | margin-bottom: 16px; |
| 95 | overflow: hidden; |
| 96 | } |
| 97 |
| 98 | /* Collapsible header */ |
| 99 | .section-header { |
| 100 | display: flex; |
| 101 | justify-content: space-between; |
| 102 | align-items: center; |
| 103 | padding: 10px 20px; |
| 104 | } |
| 105 |
| 106 | .section-header.clickable { |
| 107 | cursor: pointer; |
| 108 | transition: background 0.15s; |
| 109 | } |
| 110 |
| 111 | .section-header.clickable:hover { |
| 112 | background: var(--color-bg-hover); |
| 113 | } |
| 114 |
| 115 | .section-title { |
| 116 | font-size: 14px; |
| 117 | font-weight: 600; |
| 118 | color: var(--color-text-primary); |
| 119 | margin: 0; |
| 120 | } |
| 121 |
| 122 | /* Inline title for non-collapsible sections */ |
| 123 | .section-title-inline { |
| 124 | margin-bottom: 16px; |
| 125 | } |
| 126 |
| 127 | .section-header-right { |
| 128 | display: flex; |
| 129 | align-items: center; |
| 130 | gap: 8px; |
| 131 | } |
| 132 |
| 133 | .not-configured-badge { |
| 134 | font-size: 11px; |
| 135 | color: var(--color-text-light); |
| 136 | background: var(--color-bg-muted); |
| 137 | padding: 2px 8px; |
| 138 | border-radius: 4px; |
| 139 | } |
| 140 |
| 141 | .collapse-arrow { |
| 142 | transition: transform 0.3s; |
| 143 | color: var(--color-text-muted); |
| 144 | } |
| 145 |
| 146 | .collapse-arrow.expanded { |
| 147 | transform: rotate(-180deg); |
| 148 | } |
| 149 |
| 150 | /* Grid-based collapse animation */ |
| 151 | .collapse-wrapper { |
| 152 | display: grid; |
| 153 | grid-template-rows: 0fr; |
| 154 | transition: grid-template-rows 0.25s ease; |
| 155 | } |
| 156 |
| 157 | .collapse-wrapper.expanded { |
| 158 | grid-template-rows: 1fr; |
| 159 | } |
| 160 |
| 161 | .collapse-inner { |
| 162 | overflow: hidden; |
| 163 | } |
| 164 |
| 165 | .section-body { |
| 166 | padding: 20px 20px 12px; |
| 167 | display: flex; |
| 168 | flex-direction: column; |
| 169 | gap: 16px; |
| 170 | } |
| 171 |
| 172 | .section-body :deep(.el-form-item) { |
| 173 | margin-bottom: 0; |
| 174 | } |
| 175 |
| 176 | .section-body :deep(.config-field-readonly) { |
| 177 | margin-bottom: 0; |
| 178 | } |
| 179 |
| 180 | @include mobile { |
| 181 | .section-body { |
| 182 | padding: 16px; |
| 183 | } |
| 184 | } |
| 185 | </style> |