Skip to content

Commit 65230f1

Browse files
committed
fix: normalize history search empty value
1 parent 508cf5d commit 65230f1

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/views/reorganize/TransferHistoryView.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ const dataList = ref<TransferHistory[]>([])
191191
// 搜索
192192
const search = ref(getRouteQueryString(route.query.search))
193193
194+
// 写入搜索值时统一把空字符串归一为 null,避免 VCombobox 把空字符串当作已有值。
195+
function setSearchValue(value: unknown) {
196+
search.value = typeof value === 'string' && value !== '' ? value : null
197+
}
198+
194199
// 搜索提示词列表
195200
const searchHintList = ref<string[]>([])
196201
@@ -348,7 +353,7 @@ const debouncedReloadPage = debounce(() => {
348353
349354
// 延迟同步搜索参数到地址栏,输入完成后再重置页码并刷新。
350355
const debouncedReloadSearchPage = debounce(() => {
351-
console.log('search: ' + search.value)
356+
console.log('search: ' + (search.value ?? ''))
352357
void reloadPage(true)
353358
}, 1000)
354359
@@ -398,7 +403,7 @@ async function fetchData(page = currentPage.value, count = itemsPerPage.value, o
398403
params: {
399404
page,
400405
count,
401-
title: search.value,
406+
title: search.value ?? '',
402407
},
403408
})
404409
if (requestSeed !== fetchDataRequestSeed) return
@@ -426,13 +431,13 @@ async function fetchData(page = currentPage.value, count = itemsPerPage.value, o
426431
}
427432
}
428433
429-
// 从路由查询参数中取出单值字符串,统一处理数组和空值场景
430-
function getRouteQueryString(value: unknown) {
434+
// 从路由查询参数中取出单值字符串,空搜索统一返回 null 以保持输入框 placeholder 可见
435+
function getRouteQueryString(value: unknown): string | null {
431436
if (Array.isArray(value)) {
432-
return value.find(item => typeof item === 'string') ?? ''
437+
return value.find(item => typeof item === 'string' && item !== '') ?? null
433438
}
434439
435-
return typeof value === 'string' ? value : ''
440+
return typeof value === 'string' && value !== '' ? value : null
436441
}
437442
438443
// 将当前路由查询参数同步回页面状态,并避免触发本地监听器反向写入地址栏。
@@ -925,7 +930,8 @@ onUnmounted(() => {
925930
<VCol cols="8" md="6" class="flex">
926931
<VCombobox
927932
key="search_navbar"
928-
v-model="search"
933+
:model-value="search"
934+
@update:model-value="setSearchValue"
929935
:items="searchHintList"
930936
@compositionstart="isComposing = true"
931937
@compositionend="isComposing = false"

0 commit comments

Comments
 (0)