Skip to content
sidebar.component.ts 1.37 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { Http } from "@angular/http";
import { LayoutService } from "../layout.service";
import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
wangqinghua's avatar
wangqinghua committed
import {ToTree} from '../../shared/common/toTree';
wangqinghua's avatar
wangqinghua committed


@Component({
  selector: 'jhi-sidebar',
  templateUrl: './sidebar.component.html',
wangqinghua's avatar
wangqinghua committed
  styles: [
      ` span i{
          margin-right: 10px;
      } `
  ]
wangqinghua's avatar
wangqinghua committed
})
export class SidebarComponent implements OnInit {
    token: boolean;

  constructor(public router: Router, private http: Http,
              public layoutSer:LayoutService,
wangqinghua's avatar
wangqinghua committed
              public toTreeSer:ToTree,
wangqinghua's avatar
wangqinghua committed
              private $localStorage: LocalStorageService,
              private $sessionStorage: SessionStorageService) {
  }

  menuList = [];

  ngOnInit() {
         this.getMenu();
  }

  getMenu(){
      this.layoutSer.getMenu().subscribe(
          (res)=>{
wangqinghua's avatar
wangqinghua committed
              if(res.errCode == 10000){
wangqinghua's avatar
wangqinghua committed
                  this.menuList =this.toTreeSer.listToTree('id','parentId',res.data);
wangqinghua's avatar
wangqinghua committed
              }
wangqinghua's avatar
wangqinghua committed
          }
      )
  }

    //简单使用

    openHandler(value: string): void {
        for (const key in this.menuList) {
            if (key !== value) {
                this.menuList[ key ].checked = false;
            }
        }
    }

    goTo(route){
        this.router.navigate([route]);
    }
}