// ---------------- 异步组件导入 ---------------- 

const modules = import.meta.globEager('./../*views/**/*.vue');
// console.log(modules, modules)

// 根据 path 获取 component 
export const getComponentByPath = path => {
    const comPath = path.replace('/@/', './../')
    const module = modules[comPath];
    if(module) {
        return module.default;
    } else {
        console.warn('未能找到异步组件: ' + path);
        return undefined;
    }
};

// 将 componentPath 转化为 component 
export const pathToComponent = function (_menuList) {
    for (let menu of _menuList) {
        // 如果是一个父菜单，则递归解析
        if(menu.children) {
            pathToComponent(menu.children);
            continue;
        }

        if(menu.componentPath) {
            menu.component = getComponentByPath(menu.componentPath);
        }

    }
    return _menuList;
}

