feat: 列表页搜索框增加即时搜索与防抖机制
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
placeholder="请输入名称、规格搜索..."
|
||||
class="filter-item-input"
|
||||
clearable
|
||||
@input="handleInputSearch"
|
||||
@clear="fetchData"
|
||||
@keyup.enter="fetchData"
|
||||
style="width: 200px;"
|
||||
@ -31,6 +32,7 @@
|
||||
placeholder="请输入SKU搜索..."
|
||||
class="filter-item-input"
|
||||
clearable
|
||||
@input="handleInputSearch"
|
||||
@clear="fetchData"
|
||||
@keyup.enter="fetchData"
|
||||
style="width: 160px;"
|
||||
@ -534,6 +536,17 @@ import { getLabelPreview, executePrint } from '@/api/common/print'
|
||||
import { getWarehouseTree } from '@/api/common/warehouse'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
// ------------------------------------
|
||||
// 防抖函数
|
||||
// ------------------------------------
|
||||
const debounce = (fn: Function, delay: number = 500) => {
|
||||
let timer: ReturnType<typeof setTimeout> | null = null
|
||||
return (...args: any[]) => {
|
||||
if (timer) clearTimeout(timer)
|
||||
timer = setTimeout(() => fn(...args), delay)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// v-loadmore
|
||||
// ------------------------------------
|
||||
@ -954,8 +967,8 @@ const handleManagerSelect = (item: any) => {
|
||||
const fetchData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = {
|
||||
...queryParams,
|
||||
const params = {
|
||||
...queryParams,
|
||||
statuses: queryParams.statuses.join(','),
|
||||
orderByColumn: queryParams.orderByColumn,
|
||||
isAsc: queryParams.isAsc,
|
||||
@ -967,6 +980,16 @@ const fetchData = async () => {
|
||||
} finally { loading.value = false }
|
||||
}
|
||||
|
||||
// 防抖即时搜索
|
||||
const debouncedSearch = debounce(() => {
|
||||
queryParams.page = 1
|
||||
fetchData()
|
||||
}, 500)
|
||||
|
||||
const handleInputSearch = () => {
|
||||
debouncedSearch()
|
||||
}
|
||||
|
||||
const fetchOptions = async () => {
|
||||
try {
|
||||
const res: any = await getFilterOptions()
|
||||
|
||||
Reference in New Issue
Block a user