refactor: ♻️ 菜单搜索移除历史记录
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div v-else class="text-center py-5">暂无历史记录</div>
|
<el-empty v-else description="暂无数据" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@@ -76,7 +76,6 @@ const searchInputRef = ref();
|
|||||||
const excludedRoutes = ref(["/redirect", "/login", "/401", "/404"]);
|
const excludedRoutes = ref(["/redirect", "/login", "/401", "/404"]);
|
||||||
const menuItems = ref<SearchItem[]>([]);
|
const menuItems = ref<SearchItem[]>([]);
|
||||||
const searchResults = ref<SearchItem[]>([]);
|
const searchResults = ref<SearchItem[]>([]);
|
||||||
const searchHistory = ref<SearchItem[]>([]);
|
|
||||||
const activeIndex = ref(-1);
|
const activeIndex = ref(-1);
|
||||||
|
|
||||||
interface SearchItem {
|
interface SearchItem {
|
||||||
@@ -115,12 +114,8 @@ function updateSearchResults() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示搜索结果或历史记录
|
// 显示搜索结果
|
||||||
const displayResults = computed(() => {
|
const displayResults = computed(() => searchResults.value);
|
||||||
return searchResults.value.length > 0
|
|
||||||
? searchResults.value
|
|
||||||
: searchHistory.value.slice(0, 3);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 执行搜索
|
// 执行搜索
|
||||||
function selectActiveResult() {
|
function selectActiveResult() {
|
||||||
@@ -146,16 +141,9 @@ function navigateResults(direction: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 跳转
|
// 跳转到
|
||||||
function navigateToRoute(item: SearchItem) {
|
function navigateToRoute(item: SearchItem) {
|
||||||
closeSearchModal();
|
closeSearchModal();
|
||||||
if (!searchHistory.value.some((history) => history.path === item.path)) {
|
|
||||||
searchHistory.value.unshift(item);
|
|
||||||
if (searchHistory.value.length > 3) {
|
|
||||||
searchHistory.value.pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isExternal(item.path)) {
|
if (isExternal(item.path)) {
|
||||||
window.open(item.path, "_blank");
|
window.open(item.path, "_blank");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user