-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9329f9
commit 2d59dd6
Showing
13 changed files
with
249 additions
and
234 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
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ref, computed, watch } from 'vue'; | ||
import { useRoute } from 'vue-router'; | ||
import { useContext } from '@sa/hooks'; | ||
import { useRouteStore } from '@/store/modules/route'; | ||
|
||
export 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 | ||
}; | ||
} | ||
|
||
export const { setupStore: setupMixMenuContext, useStore: useMixMenuContext } = useContext('mix-menu', useMixMenu); |
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
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
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
import { createReusableTemplate } from '@vueuse/core'; | ||
import { SimpleScrollbar } from '@sa/materials'; | ||
import { transformColorWithOpacity } from '@sa/utils'; | ||
import { useAppStore } from '@/store/modules/app'; | ||
import { useRouteStore } from '@/store/modules/route'; | ||
import { useThemeStore } from '@/store/modules/theme'; | ||
defineOptions({ | ||
name: 'FirstLevelMenu' | ||
}); | ||
interface Props { | ||
activeMenuKey?: string; | ||
} | ||
defineProps<Props>(); | ||
interface Emits { | ||
(e: 'select', menu: App.Global.Menu): boolean; | ||
} | ||
const emit = defineEmits<Emits>(); | ||
const appStore = useAppStore(); | ||
const themeStore = useThemeStore(); | ||
const routeStore = useRouteStore(); | ||
interface MixMenuItemProps { | ||
/** | ||
* menu item label | ||
*/ | ||
label: App.Global.Menu['label']; | ||
/** | ||
* menu item icon | ||
*/ | ||
icon: App.Global.Menu['icon']; | ||
/** | ||
* active menu item | ||
*/ | ||
active: boolean; | ||
/** | ||
* mini size | ||
*/ | ||
isMini: boolean; | ||
} | ||
const [DefineMixMenuItem, MixMenuItem] = createReusableTemplate<MixMenuItemProps>(); | ||
const siderInverted = computed(() => !themeStore.darkMode && themeStore.sider.inverted); | ||
const selectedBgColor = computed(() => { | ||
const { darkMode, themeColor } = themeStore; | ||
const light = transformColorWithOpacity(themeColor, 0.1, '#ffffff'); | ||
const dark = transformColorWithOpacity(themeColor, 0.3, '#000000'); | ||
return darkMode ? dark : light; | ||
}); | ||
function handleClickMixMenu(menu: App.Global.Menu) { | ||
emit('select', menu); | ||
} | ||
</script> | ||
|
||
<template> | ||
<!-- define component: MixMenuItem --> | ||
<DefineMixMenuItem v-slot="{ label, icon, active, isMini }"> | ||
<div | ||
class="flex-vertical-center mx-4px mb-6px py-8px px-4px rounded-8px bg-transparent transition-300 cursor-pointer hover:bg-[rgb(0,0,0,0.08)]" | ||
:class="{ | ||
'text-primary selected-mix-menu': active, | ||
'text-white:65 hover:text-white': siderInverted, | ||
'!text-white !bg-primary': active && siderInverted | ||
}" | ||
> | ||
<component :is="icon" :class="[isMini ? 'text-icon-small' : 'text-icon-large']" /> | ||
<p | ||
class="w-full text-center ellipsis-text text-12px transition-height-300" | ||
:class="[isMini ? 'h-0 pt-0' : 'h-24px pt-4px']" | ||
> | ||
{{ label }} | ||
</p> | ||
</div> | ||
</DefineMixMenuItem> | ||
|
||
<!-- template --> | ||
<div class="flex-1-hidden flex-vertical-stretch h-full"> | ||
<slot></slot> | ||
<SimpleScrollbar> | ||
<MixMenuItem | ||
v-for="menu in routeStore.menus" | ||
:key="menu.key" | ||
:label="menu.label" | ||
:icon="menu.icon" | ||
:active="menu.key === activeMenuKey" | ||
:is-mini="appStore.siderCollapse" | ||
@click="handleClickMixMenu(menu)" | ||
/> | ||
</SimpleScrollbar> | ||
<MenuToggler | ||
arrow-icon | ||
:collapsed="appStore.siderCollapse" | ||
:class="{ 'text-white:88 !hover:text-white': siderInverted }" | ||
@click="appStore.toggleSiderCollapse" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.selected-mix-menu { | ||
background-color: v-bind(selectedBgColor); | ||
} | ||
</style> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.