Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions dashboard/src/components/shared/ListConfigItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</template>

<script setup>
import { ref, computed, watch } from 'vue'
import { ref, computed, watch, nextTick } from 'vue'
import { useI18n } from '@/i18n/composables'

const { t } = useI18n()
Expand Down Expand Up @@ -205,8 +205,13 @@ const isSingleItemMode = computed(() => (props.modelValue?.length ?? 0) <= 1 &&
const singleItemValue = computed({
get: () => props.modelValue?.[0] ?? '',
set: (value) => {
const newItems = [...(props.modelValue || [])]
// 如果值为空或只有空白字符,emit 空数组
if (value.trim() === '') {
emit('update:modelValue', [])
return
}

const newItems = [...(props.modelValue || [])]
if (newItems.length === 0) {
newItems.push(value)
} else {
Expand All @@ -232,9 +237,20 @@ const batchImportPreviewCount = computed(() => {
.length
})

// 监听 modelValue 变化,同步到 localItems
// 监听 modelValue 变化,同步到 localItems,并清理空字符串
watch(() => props.modelValue, (newValue) => {
localItems.value = [...(newValue || [])]

// 自动清理只包含空字符串的数组
if (newValue && newValue.length > 0) {
const filtered = newValue.filter(item => typeof item === 'string' ? item.trim() !== '' : true)
if (filtered.length !== newValue.length) {
// 使用 nextTick 确保父组件已准备好接收更新
nextTick(() => {
emit('update:modelValue', filtered)
})
}
}
}, { immediate: true })

function openDialog() {
Expand Down Expand Up @@ -275,7 +291,9 @@ function cancelEdit() {
}

function confirmDialog() {
emit('update:modelValue', [...localItems.value])
// 过滤空字符串,同时处理非字符串类型
const filteredItems = localItems.value.filter(item => typeof item === 'string' ? item.trim() !== '' : true)
emit('update:modelValue', filteredItems)
dialog.value = false
}

Expand Down