-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(projects): useMixMenuContext replace useMixMenu
- Loading branch information
1 parent
19e65c1
commit 1e14293
Showing
3 changed files
with
46 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,47 @@ | ||
import { computed, ref, watch } from 'vue'; | ||
import { useRoute } from 'vue-router'; | ||
import { useContext } from '@sa/hooks'; | ||
import { useMixMenu } from '../hooks'; | ||
import { useRouteStore } from '@/store/modules/route'; | ||
|
||
export const { setupStore: setupMixMenuContext, useStore: useMixMenuContext } = useContext('mix-menu', useMixMenu); | ||
|
||
function useMixMenu() { | ||
const route = useRoute(); | ||
const routeStore = useRouteStore(); | ||
|
||
const activeFirstLevelMenuKey = ref(''); | ||
|
||
function setActiveFirstLevelMenuKey(key: string) { | ||
activeFirstLevelMenuKey.value = key; | ||
} | ||
|
||
function getActiveFirstLevelMenuKey() { | ||
const { hideInMenu, activeMenu } = route.meta; | ||
const name = route.name as string; | ||
|
||
const routeName = (hideInMenu ? activeMenu : name) || name; | ||
|
||
const [firstLevelRouteName] = routeName.split('_'); | ||
|
||
setActiveFirstLevelMenuKey(firstLevelRouteName); | ||
} | ||
|
||
const menus = computed( | ||
() => routeStore.menus.find(menu => menu.key === activeFirstLevelMenuKey.value)?.children || [] | ||
); | ||
|
||
watch( | ||
() => route.name, | ||
() => { | ||
getActiveFirstLevelMenuKey(); | ||
}, | ||
{ immediate: true } | ||
); | ||
|
||
return { | ||
activeFirstLevelMenuKey, | ||
setActiveFirstLevelMenuKey, | ||
getActiveFirstLevelMenuKey, | ||
menus | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters