index.js 1.01 KB
Newer Older
1
export { default as langUtil } from './langUtils';
水落(YangLei)'s avatar
水落(YangLei) committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15
export * from './requestUtil';

const USERID_KEY = 'userId';
export function getUserId() {
    return window.sessionStorage.getItem(USERID_KEY) || '';
}

export function setUserId(val) {
    window.sessionStorage.setItem(USERID_KEY, val);
}

/**
 * 转变菜单列表为tree结构
 * @param {Array} menuList 菜单列表
16
 * @param {Boolean} filterMenu 是否过滤掉菜单,只保留目录
水落(YangLei)'s avatar
水落(YangLei) committed
17
 */
18 19 20 21 22
export function convertListToTree(menuList, filterMenu = false) {
    let tempMenu = [...menuList];
    if (filterMenu) {
        tempMenu = tempMenu.filter(m => m.menuType !== 'MENU');
    }
水落(YangLei)'s avatar
水落(YangLei) committed
23 24 25 26 27 28 29
    for (const menu of menuList) {
        if (menu.parentMenuId === 0) continue;
        const parent = menuList.find(m => m.menuId === menu.parentMenuId);
        parent.children ? parent.children.push(menu) : (parent.children = [menu]);
    }
    return tempMenu.filter(m => m.parentMenuId === 0);
}
30 31

export function EMPTY_FUN() {}
32 33

export const isFunction = val => typeof val === 'function';