diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index f095a49..bd20bbc 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -96,10 +96,6 @@ export class LoginComponent implements OnInit { { name: '预警记录', url: '/records_nav/petrolStation' }, { name: '证照管理', url: '/license/petrolStation' }, ] - userMenu = [] - tap = [] - menuList = [] - name="" submitForm(): void { if (!this.remember) { @@ -127,9 +123,8 @@ export class LoginComponent implements OnInit { (data: any) => { sessionStorage.setItem("token", data.result.accessToken); sessionStorage.setItem("encryptedAccessToken", data.result.encryptedAccessToken); - console.log('token', data.result) this.http.get('/api/services/app/Session/GetCurrentLoginInformations').subscribe((data: any) => { - console.log('GetCurrentLoginInformations', data.result) + // console.log('GetCurrentLoginInformations', data.result) if (data.result.user.menus.length == 0) { this.message.create('error', `当前用户未分配菜单`); this.isLoading = false @@ -147,66 +142,38 @@ export class LoginComponent implements OnInit { if (data.result.user.userName == 'admin') { sessionStorage.setItem("isGasStation", 'false'); this.router.navigate(['/system/organization']) - this.message.create('success', `登录成功`); } else { if (data.result.user.organization.isGasStation) { - let a = sessionStorage.getItem('userdataOfgasstation') - this.userMenu = JSON.parse(a).menus - for (let index = 0; index < this.userMenu.length; index++) { - let a = this.userMenu[index].name - this.tap.push(a) - } - for (let index = 0; index < this.menu2.length; index++) { - for (let k = 0; k < this.tap.length; k++) { - if (this.tap[k] == this.menu2[index].name) { - this.menuList.push(this.menu2[index]) - } - } - } - for (let index = 0; index < this.tap.length; index++) { - if(this.tap[index]=="今日预警") {this.name="今日预警"} - - } sessionStorage.setItem("isGasStation", 'true'); - if(this.name=="今日预警"){ + let a = sessionStorage.getItem('userdataOfgasstation') + let menuList = this.returnLastMenus(a, this.menu2) + let isTrue = menuList.find((item) => { + return item.name == "今日预警" + }); + if (isTrue) { this.router.navigate(['/todaywarning/petrolStation']) - this.message.create('success', `登录成功`); - sessionStorage.setItem('selectedMenu', '今日预警') - }else{ - this.router.navigate([this.menuList[0].url]) - this.message.create('success', `登录成功`); - sessionStorage.setItem('selectedMenu', this.menuList[0].name) + sessionStorage.setItem('selectedMenu', '今日预警') + } else { + this.router.navigate([menuList[0].url]) + sessionStorage.setItem('selectedMenu', menuList[0].name) } } else { - let a = sessionStorage.getItem('userdata') - this.userMenu = JSON.parse(a).menus - for (let index = 0; index < this.userMenu.length; index++) { - let a = this.userMenu[index].name - this.tap.push(a) - } - for (let index = 0; index < this.menu1.length; index++) { - for (let k = 0; k < this.tap.length; k++) { - if (this.tap[k] == this.menu1[index].name) { - this.menuList.push(this.menu1[index]) - } - } - } - for (let index = 0; index < this.tap.length; index++) { - if(this.tap[index]=="首页") {this.name="首页"} - - } sessionStorage.setItem("isGasStation", 'false'); - if(this.name=="首页"){ + let a = sessionStorage.getItem('userdata') + let menuList = this.returnLastMenus(a, this.menu1) + let isTrue = menuList.find((item) => { + return item.name == "首页" + }); + if (isTrue) { this.router.navigate(['/homepage']) - this.message.create('success', `登录成功`); - sessionStorage.setItem('selectedMenu', '首页') - }else{ - this.router.navigate([this.menuList[0].url]) - this.message.create('success', `登录成功`); - sessionStorage.setItem('selectedMenu', this.menuList[0].name) + sessionStorage.setItem('selectedMenu', '首页') + } else { + this.router.navigate([menuList[0].url]) + sessionStorage.setItem('selectedMenu', menuList[0].name) } } } + this.message.create('success', `登录成功`); }, err => { this.isLoading = false; }) @@ -217,7 +184,23 @@ export class LoginComponent implements OnInit { } ) } - + returnLastMenus(data, originalMenus) { + let userMenu = JSON.parse(data).menus + let tap = [] + let menuList = [] + for (let index = 0; index < userMenu.length; index++) { + let a = userMenu[index].name + tap.push(a) + } + for (let index = 0; index < originalMenus.length; index++) { + for (let k = 0; k < tap.length; k++) { + if (tap[k] == originalMenus[index].name) { + menuList.push(originalMenus[index]) + } + } + } + return menuList + } forget() { this.message.create('warning', `请联系管理员`); }