mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-20 02:55:08 +08:00
* fix: 修复列表配置项删除后保存为['']而非[]的问题 (#4297) * fix: 添加类型检查以处理非字符串列表项 * refactor: 移除 ExtensionPage 中重复的 cleanEmptyListItems 过滤逻辑已在 ListConfigItem.vue 源头处理,保存配置时无需再次过滤。
This commit is contained in:
@@ -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()
|
||||
@@ -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 {
|
||||
@@ -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() {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user