feat(网址导航): 记录最后一次选中的链接分类

This commit is contained in:
2024-09-08 21:01:30 +08:00
parent 1c87705166
commit de3cd7bb34
2 changed files with 33 additions and 3 deletions

View File

@@ -6,6 +6,9 @@ const PREFIX = 'frost-navigation/';
/** 导航链接侧边栏折叠状态 */
export const SKEY_NAV_LINK_ASIDE_COLLAPSED = PREFIX + 'nav-link-aside-collapsed';
/** 导航链接当前选中分类 */
export const SKEY_NAV_LINK_CATEGORY = PREFIX + 'nav-link-category';
/** 导航链接搜索类型 */
export const SKEY_NAV_LINK_SEARCH_TYPE = PREFIX + 'nav-link-search-type';

View File

@@ -145,6 +145,7 @@ import {
import {
SKEY_NAV_LINK_ASIDE_COLLAPSED,
SKEY_NAV_LINK_CATEGORY,
SKEY_NAV_LINK_SEARCH_TYPE,
} from '@/config/storage';
@@ -228,10 +229,36 @@ const searchTypes = [
*/
function changeList(data = null) {
let useData = data || navLinksAll[0] || null;
let useData = null;
let storedKey = '';
if (data) {
useData = data;
} else {
storedKey = localStorage.getItem(SKEY_NAV_LINK_CATEGORY)
}
if (storedKey) {
useData = navLinksAll.find((item) => {
return item.title === storedKey;
});
}
if (!useData) {
useData = navLinksAll[0] || null;
}
if (useData) {
localStorage.setItem(SKEY_NAV_LINK_CATEGORY, useData.title);
navLinksCurr.value = useData.children;
navLinksTitle.value = useData.title;
} else {
localStorage.setItem(SKEY_NAV_LINK_CATEGORY, '');
navLinksCurr.value = [];
navLinksTitle.value = '';
}
navLinksCurr.value = useData ? useData.children : [];
navLinksTitle.value = useData ? useData.title : '';
}