Blame view

frontend/manage/src/api/menu.js 1.11 KB
8d73e917   陈威   初始化提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import menuData from "@/api/mock/menu-data.js";
import store from "@/store";

export default {
    getMenus() {
        return menuData.getMenus();
    },
    getMenuByAlias(alias, cb) {
        let r = null;
        let _menu = store.state.menu.menus;
        if(!_menu || _menu.length==0 ){
          let storageMenus = sessionStorage.getItem("currentMenus");
          if(storageMenus &&  storageMenus !='undefined'){
              _menu = JSON.parse(storageMenus);
          } 
        }
        _menu.forEach( function(x) {
          if((!r || r.length==0 ) && x.children){
            r = x.children.filter(m => m.alias == alias);
            if(r && r.length==1){
                r[0].parent = x;
            }else{
              x.children.forEach(function(z) {
                if((!r || r.length==0) && z.children){
                    r = z.children.filter(m => m.alias == alias);
                    if(r&&r.length==1){
                        z.parent = x;
                        r[0].parent = z;
                    }
                }
              })
            }
          }
        });
        cb(r&&r[0]);
    },
}