1234567891011121314151617181920212223242526272829 |
- import {TreeRoleMenuData} from '@models';
- import {MENU_STORAGE} from '@utils';
- import {createStore} from 'zustand/vanilla';
- type State = {menus: TreeRoleMenuData[]};
- type Action = {
- setMenu(state: TreeRoleMenuData[]): void;
- clear(): void;
- };
- export const menuStore = createStore<State & Action>(function (set) {
- const menusStorage = sessionStorage.getItem(MENU_STORAGE);
- const menus = menusStorage
- ? (JSON.parse(menusStorage) as TreeRoleMenuData[])
- : [];
- return {
- menus,
- setMenu(menus) {
- sessionStorage.setItem(MENU_STORAGE, JSON.stringify(menus));
- set({menus});
- },
- clear() {
- set({menus: []});
- },
- };
- });
|