diff --git a/src/config/storage.js b/src/config/storage.js index 8b73a55..e325177 100644 --- a/src/config/storage.js +++ b/src/config/storage.js @@ -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'; diff --git a/src/views/NavView/NavView.vue b/src/views/NavView/NavView.vue index a9dd1e4..6d29327 100644 --- a/src/views/NavView/NavView.vue +++ b/src/views/NavView/NavView.vue @@ -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 : ''; }