@@ -2,25 +2,22 @@ import type { MenuItem } from '../config/menu';
22import type { DMenuItem } from '@react-devui/ui/components/menu' ;
33
44import { isObject , isUndefined } from 'lodash' ;
5+ import { useStore } from 'rcl-store' ;
56import React from 'react' ;
67import { useTranslation } from 'react-i18next' ;
78import { Link , useLocation } from 'react-router-dom' ;
89
9- import { createGlobalState , useMount } from '@react-devui/hooks' ;
10+ import { useMount } from '@react-devui/hooks' ;
1011
1112import { MENU } from '../config/menu' ;
13+ import { GlobalStore } from './store' ;
1214import { useACL } from './useACL' ;
1315
14- export interface MenuState {
15- expands ?: string [ ] ;
16- }
17- const useMenuState = createGlobalState < MenuState > ( { } ) ;
18-
1916export function useMenu ( ) {
2017 const acl = useACL ( ) ;
2118 const { t } = useTranslation ( ) ;
2219 const location = useLocation ( ) ;
23- const [ menuState , setMenuState ] = useMenuState ( ) ;
20+ const [ { appMenu } , { appMenu : setAppMenu } ] = useStore ( GlobalStore , [ 'appMenu' ] ) ;
2421
2522 const res : {
2623 active ?: { path : string ; parentSub : MenuItem [ ] } ;
@@ -78,8 +75,8 @@ export function useMenu() {
7875 ( location . pathname === '/' ? res . firstCanActive ?. parentSub : res . active ?. parentSub ) ?. map ( ( item ) => item . path ) ;
7976
8077 useMount ( ( ) => {
81- if ( isUndefined ( menuState . expands ) ) {
82- setMenuState ( ( draft ) => {
78+ if ( isUndefined ( appMenu . expands ) ) {
79+ setAppMenu ( ( draft ) => {
8380 draft . expands = getDefaultExpands ( ) ;
8481 } ) ;
8582 }
@@ -90,9 +87,8 @@ export function useMenu() {
9087 menu,
9188 active : location . pathname === '/' ? res . firstCanActive : res . active ,
9289 firstCanActive : res . firstCanActive ,
93- expands : menuState . expands ?? getDefaultExpands ( ) ,
90+ expands : appMenu . expands ?? getDefaultExpands ( ) ,
9491 } ,
95- setMenuState ,
92+ setAppMenu ,
9693 ] as const ;
9794}
98- useMenu . setState = useMenuState . setState ;
0 commit comments