/** * * @author Ray * * @date 2022-10-11 * * @workspace ray-template * * @remark 今天也是元气满满撸代码的一天 */ import './index.scss' import { NMenu, NLayoutSider, NDrawer } from 'naive-ui' import SiderBarLogo from './components/SiderBarLogo' import { APP_MENU_CONFIG } from '@/app-config' import { useDevice } from '@/hooks' import { getVariableToRefs, setVariable } from '@/global-variable' import { useMenuGetters, useMenuActions } from '@/store' import type { MenuInst } from 'naive-ui' import type { NaiveMenuOptions } from '@/types' import type { AppMenuOption } from '@/types' export default defineComponent({ name: 'AppMenu', setup() { const menuRef = ref(null) const { changeMenuModelValue, collapsedMenu } = useMenuActions() const { getMenuOptions, getCollapsed, getMenuKey } = useMenuGetters() const modelMenuKey = computed({ get: () => { nextTick().then(() => { showMenuOption() }) return getMenuKey.value }, set: () => { if (isTabletOrSmaller.value) { setVariable('globalDrawerValue', false) } }, }) const { isTabletOrSmaller } = useDevice() const modelGlobalDrawerValue = computed({ get: () => getVariableToRefs('globalDrawerValue').value, set: (val) => { setVariable('globalDrawerValue', val) }, }) /** * * 手动展开当前激活菜单项 */ const showMenuOption = () => { const key = modelMenuKey.value as string nextTick().then(() => { menuRef.value?.showOption?.(key) }) } const BasicMenu = () => ( { changeMenuModelValue(key, op as unknown as AppMenuOption) }} accordion={APP_MENU_CONFIG.menuAccordion} /> ) return { isTabletOrSmaller, BasicMenu, modelGlobalDrawerValue, } }, render() { const { isTabletOrSmaller, BasicMenu } = this return !isTabletOrSmaller ? ( ) : ( ) }, })