mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 01:10:16 +08:00
feat: 更新搜索逻辑
现在更换app类别时将默认清空搜索。
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
id="searchBox"
|
||||
v-model="localSearchQuery"
|
||||
class="w-full rounded-2xl border border-slate-200/70 bg-white/80 py-3 pl-12 pr-4 text-sm text-slate-700 shadow-sm outline-none transition placeholder:text-slate-400 focus:border-brand/50 focus:ring-4 focus:ring-brand/10 dark:border-slate-800/70 dark:bg-slate-900/60 dark:text-slate-200"
|
||||
placeholder="搜索应用名 / 包名 / 标签"
|
||||
@input="debounceSearch"
|
||||
placeholder="搜索应用名 / 包名 / 标签,按回车键搜索"
|
||||
@keydown.enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -30,6 +30,7 @@ import TopActions from "./TopActions.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
searchQuery: string;
|
||||
activeCategory: string;
|
||||
appsCount: number;
|
||||
}>();
|
||||
|
||||
@@ -40,13 +41,9 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const localSearchQuery = ref(props.searchQuery || "");
|
||||
const timeoutId = ref<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const debounceSearch = () => {
|
||||
if (timeoutId.value) clearTimeout(timeoutId.value);
|
||||
timeoutId.value = setTimeout(() => {
|
||||
emit("update-search", localSearchQuery.value);
|
||||
}, 220);
|
||||
const handleSearch = () => {
|
||||
emit("update-search", localSearchQuery.value);
|
||||
};
|
||||
|
||||
watch(
|
||||
@@ -55,4 +52,11 @@ watch(
|
||||
localSearchQuery.value = newVal || "";
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.activeCategory,
|
||||
() => {
|
||||
localSearchQuery.value = "";
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user