Skip to content
navbar.component.ts 3.69 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {AfterViewChecked, Component, ElementRef, OnChanges, OnInit, ViewChild} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import { Router } from '@angular/router';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';

import { ProfileService } from '../profiles/profile.service';
wangqinghua's avatar
wangqinghua committed
import { Principal, LoginService } from '../../shared';
wangqinghua's avatar
wangqinghua committed

import { VERSION } from '../../app.constants';
wangqinghua's avatar
wangqinghua committed
import {LocalStorageService} from 'ngx-webstorage';
wangqinghua's avatar
wangqinghua committed
import {SeparationComponent} from '../../system/modal/separation/separation.component';
wangqinghua's avatar
wangqinghua committed
import {BasicEditComponent} from '../../modal/basic-edit/basic-edit.component';
import {CreateGroupComponent} from '../../modal/create-group/create-group.component';
wangqinghua's avatar
wangqinghua committed
import {ModifyPasswordComponent} from '../../modal/modify-password/modify-password.component';
wangqinghua's avatar
wangqinghua committed
import {SystemService} from '../../system/system.service';
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'jhi-navbar',
    templateUrl: './navbar.component.html',
    styleUrls: [
        'navbar.css'
    ]
})
wangqinghua's avatar
wangqinghua committed
export class NavbarComponent implements OnInit ,AfterViewChecked{
    @ViewChild('parent') parent:ElementRef;
    @ViewChild('children') children:ElementRef;
wangqinghua's avatar
wangqinghua committed
    @ViewChild("smartSeparation") smartSeparation:SeparationComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('basicEdit') basicEdit:BasicEditComponent;
    @ViewChild('smartCreateGroup') smartCreateGroup:CreateGroupComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartModifyPassword') smartModifyPassword:ModifyPasswordComponent;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    inProduction: boolean;
    isNavbarCollapsed: boolean;
    languages: any[];
    swaggerEnabled: boolean;
    modalRef: NgbModalRef;
    version: string;
    token: boolean;
wangqinghua's avatar
wangqinghua committed
    roleType;
wangqinghua's avatar
wangqinghua committed

    isBool = false;
wangqinghua's avatar
wangqinghua committed
    user = {
        loginName:''
    }
wangqinghua's avatar
wangqinghua committed
    constructor(
        private loginService: LoginService,
        private principal: Principal,
        private profileService: ProfileService,
        private router: Router,
wangqinghua's avatar
wangqinghua committed
        private $localStorage:LocalStorageService,
        private systemSer:SystemService,
wangqinghua's avatar
wangqinghua committed
    ) {
        this.version = VERSION ? 'v' + VERSION : '';
        this.isNavbarCollapsed = true;
    }

    ngOnInit() {
wangqinghua's avatar
wangqinghua committed
        this.user = this.$localStorage.retrieve("userInfo");
wangqinghua's avatar
wangqinghua committed
        // this.profileService.getProfileInfo().then((profileInfo) => {
        //     this.inProduction = profileInfo.inProduction;
        //     this.swaggerEnabled = profileInfo.swaggerEnabled;
        // });
    }

wangqinghua's avatar
wangqinghua committed
    /**
     * 获取当前登录人角色
     * 1.系统管理员 2.安全管理员 3。二者都有
     */
    getCurrentRole(){
        this.systemSer.checkRole().subscribe(
            (res)=>{
                this.roleType = res.data;
            }
        )
    }

wangqinghua's avatar
wangqinghua committed
    ngAfterViewChecked(){
    }

wangqinghua's avatar
wangqinghua committed
    collapseNavbar() {
        this.isNavbarCollapsed = true;
    }

    isAuthenticated() {
        return this.principal.isAuthenticated();
    }

    logout() {
        this.collapseNavbar();
        this.loginService.logout();
    }

    toggleNavbar() {
        this.isNavbarCollapsed = !this.isNavbarCollapsed;
    }

    getImageUrl() {
        return this.isAuthenticated() ? this.principal.getImageUrl() : null;
    }
wangqinghua's avatar
wangqinghua committed

    transition(){
        if(!this.isBool){
            this.children.nativeElement.style.marginLeft = '0px';
            this.isBool = true;
        }else{
            this.children.nativeElement.style.marginLeft = "-300px";
            this.isBool = false;
        }
    }
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    //修改密码
    showPasswordModal(){
        this.smartModifyPassword.showModal();
    }

wangqinghua's avatar
wangqinghua committed
    //三员分立
    showSeparationModal(){
        this.smartSeparation.showModal("三员分立");
    }
wangqinghua's avatar
wangqinghua committed

    //添加资源  ,name-分组名称,id-分组id
    showBasicEditModal() {
        this.basicEdit.showModal();
    }

    //添加分组
    showGroupModal() {
        this.smartCreateGroup.showModal('添加分组');
    }
wangqinghua's avatar
wangqinghua committed
}