feat: 优化搜索

This commit is contained in:
alger
2024-09-12 17:28:51 +08:00
parent 0c156e2708
commit 791121ae06
3 changed files with 31 additions and 29 deletions
+7 -4
View File
@@ -14,7 +14,7 @@
</template>
<template #suffix>
<div class="w-20 px-3 flex justify-between items-center">
<div>{{ searchTypeOptions.find((item) => item.key === searchType)?.label }}</div>
<div>{{ searchTypeOptions.find((item) => item.key === store.state.searchType)?.label }}</div>
<n-dropdown trigger="hover" :options="searchTypeOptions" @select="selectSearchType">
<i class="iconfont icon-xiasanjiaoxing"></i>
</n-dropdown>
@@ -90,7 +90,6 @@ onMounted(() => {
// 搜索词
const searchValue = ref('');
const searchType = ref(1);
const search = () => {
const { value } = searchValue;
if (value === '') {
@@ -98,17 +97,21 @@ const search = () => {
return;
}
if (router.currentRoute.value.path === '/search') {
store.state.searchValue = value;
return;
}
router.push({
path: '/search',
query: {
keyword: value,
type: searchType.value,
},
});
};
const selectSearchType = (key: number) => {
searchType.value = key;
store.state.searchType = key;
};
const searchTypeOptions = ref(SEARCH_TYPES);