|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import { HttpClient } from "@angular/common/http"; |
|
|
|
|
import { ActivatedRoute } from "@angular/router"; |
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router"; |
|
|
|
|
import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core"; |
|
|
|
|
import { FormBuilder, FormGroup } from "@angular/forms"; |
|
|
|
|
import { NzFormatEmitEvent } from "ng-zorro-antd/tree"; |
|
|
|
|
import { TreeService } from "src/app/service/tree.service"; |
|
|
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
|
|
@Component({ |
|
|
|
|
selector: "app-singlelogin", |
|
|
|
|
templateUrl: "./singlelogin.component.html", |
|
|
|
@ -14,38 +15,89 @@ export class SingleloginComponent implements OnInit {
|
|
|
|
|
public route: ActivatedRoute, |
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
private http: HttpClient, |
|
|
|
|
private toTree: TreeService |
|
|
|
|
private toTree: TreeService, |
|
|
|
|
private router: Router, |
|
|
|
|
private message: NzMessageService |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
sinToken; |
|
|
|
|
async ngOnInit(): Promise<void> { |
|
|
|
|
console.log("查询参数", this.route.snapshot.queryParams.page); |
|
|
|
|
this.bindingUser(); |
|
|
|
|
// await this.getCurrentUserInfo();
|
|
|
|
|
// await this.getAuthOrganInfos();
|
|
|
|
|
if (this.CurrentUserInfo && this.AuthOrganInfos) { |
|
|
|
|
// await this.getSinochemUsers(this.CurrentUserInfo.name);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let userdata = JSON.parse(sessionStorage.getItem("userdata")); |
|
|
|
|
if (userdata.userName == "admin") { |
|
|
|
|
//是superadmin,是内部制作账号
|
|
|
|
|
this.isAdmin = true; |
|
|
|
|
let obj = { |
|
|
|
|
SAG_USER_TOKEN: |
|
|
|
|
"1zLWxc5737RBqu267e2ek8S0jlvfckggVYuWmu_9uvxvPeX7-RtQl0nrft90zq5w==", |
|
|
|
|
}; |
|
|
|
|
this.setCookie(obj); |
|
|
|
|
|
|
|
|
|
let token = this.getCookie("SAG_USER_TOKEN"); |
|
|
|
|
if (!token) { |
|
|
|
|
alert("获取失败!"); |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
this.isAdmin = false; |
|
|
|
|
this.sinToken = token; |
|
|
|
|
console.log("token"); |
|
|
|
|
alert("token获取成功:" + token); |
|
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
// this.bindingUser();
|
|
|
|
|
await this.getCurrentUserInfo(); |
|
|
|
|
await this.getAuthOrganInfos(); |
|
|
|
|
if (this.CurrentUserInfo && this.AuthOrganInfos) { |
|
|
|
|
// await this.getSinochemUsers(this.CurrentUserInfo.name);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let userdata = JSON.parse(sessionStorage.getItem("userdata")); |
|
|
|
|
if (userdata.userName == "admin") { |
|
|
|
|
//是superadmin,是内部制作账号
|
|
|
|
|
this.isAdmin = true; |
|
|
|
|
} else { |
|
|
|
|
this.isAdmin = false; |
|
|
|
|
} |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
search: [null], |
|
|
|
|
}); |
|
|
|
|
this.level = JSON.parse( |
|
|
|
|
sessionStorage.getItem("userdata") |
|
|
|
|
).organization.level; |
|
|
|
|
|
|
|
|
|
this.getAllUrl = "/api/services/app/User/GetAll"; |
|
|
|
|
this.CountsByOrganizations = |
|
|
|
|
"/api/services/app/User/GetCountsByOrganizations"; |
|
|
|
|
|
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
} |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
search: [null], |
|
|
|
|
}); |
|
|
|
|
this.level = JSON.parse( |
|
|
|
|
sessionStorage.getItem("userdata") |
|
|
|
|
).organization.level; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//设置cookie
|
|
|
|
|
setCookie(obj) { |
|
|
|
|
for (let key in obj) { |
|
|
|
|
document.cookie = key + "=" + obj[key]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.getAllUrl = "/api/services/app/User/GetAll"; |
|
|
|
|
this.CountsByOrganizations = |
|
|
|
|
"/api/services/app/User/GetCountsByOrganizations"; |
|
|
|
|
//读取cookie
|
|
|
|
|
getCookie(key) { |
|
|
|
|
console.log( |
|
|
|
|
document.cookie.match(new RegExp("(^|\\s)" + key + "=([^;]+)(;|$)")) |
|
|
|
|
); |
|
|
|
|
let arr = document.cookie.match( |
|
|
|
|
new RegExp("(^|\\s)" + key + "=([^;]+)(;|$)") |
|
|
|
|
); |
|
|
|
|
if (arr && arr.length !== 0) { |
|
|
|
|
return document.cookie.match( |
|
|
|
|
new RegExp("(^|\\s)" + key + "=([^;]+)(;|$)") |
|
|
|
|
)[2]; |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
//删除cookie
|
|
|
|
|
removeCookie(key) { |
|
|
|
|
this.setCookie({ [key]: "" }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CurrentUserInfo; |
|
|
|
|
AuthOrganInfos; |
|
|
|
|
//获取当前登录用户信息
|
|
|
|
@ -54,8 +106,7 @@ export class SingleloginComponent implements OnInit {
|
|
|
|
|
this.http |
|
|
|
|
.get("/p3p/auth/getCurrentUserInfo", { |
|
|
|
|
params: { |
|
|
|
|
token: |
|
|
|
|
"czQre5c933Q_WgQaad1c8HFmLDV9SgiowfLLJgcZnuw8GdpKs6RwCbNdwLnVKmpQ==", |
|
|
|
|
token: this.sinToken, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
@ -76,8 +127,7 @@ export class SingleloginComponent implements OnInit {
|
|
|
|
|
this.http |
|
|
|
|
.get("/p3p/auth/getAuthOrganInfos", { |
|
|
|
|
params: { |
|
|
|
|
token: |
|
|
|
|
"czQre5c933Q_WgQaad1c8HFmLDV9SgiowfLLJgcZnuw8GdpKs6RwCbNdwLnVKmpQ==", |
|
|
|
|
token: this.sinToken, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
@ -137,6 +187,142 @@ export class SingleloginComponent implements OnInit {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enterPage(tokenData) { |
|
|
|
|
sessionStorage.setItem("token", tokenData.result.accessToken); |
|
|
|
|
sessionStorage.setItem( |
|
|
|
|
"encryptedAccessToken", |
|
|
|
|
tokenData.result.encryptedAccessToken |
|
|
|
|
); |
|
|
|
|
this.http |
|
|
|
|
.get("/api/services/app/Session/GetCurrentLoginInformations") |
|
|
|
|
.subscribe( |
|
|
|
|
async (data: any) => { |
|
|
|
|
console.log("当前登录账号的信息", data.result); |
|
|
|
|
if (data.result.user.menus.length == 0) { |
|
|
|
|
alert("当前用户未分配菜单"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!data.result.user.organization) { |
|
|
|
|
alert("当前用户没有组织机构信息"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (data.result.user.organization.isGasStation) { |
|
|
|
|
await this.getGasStationBaseInfo(); |
|
|
|
|
if ( |
|
|
|
|
data.result.user.menus[0].name == "数字油站" && |
|
|
|
|
data.result.user.menus.length == 1 && |
|
|
|
|
!this.init3D |
|
|
|
|
) { |
|
|
|
|
this.message.create( |
|
|
|
|
"error", |
|
|
|
|
`当前用户油站未开通3D且仅分配油站菜单` |
|
|
|
|
); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sessionStorage.setItem("userdata", JSON.stringify(data.result.user)); |
|
|
|
|
sessionStorage.setItem( |
|
|
|
|
"userdataOfgasstation", |
|
|
|
|
JSON.stringify(data.result.user) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
//跳转页面
|
|
|
|
|
this.toPage(data); |
|
|
|
|
}, |
|
|
|
|
(err) => { |
|
|
|
|
alert("获取用户信息错误"); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
menu1 = [ |
|
|
|
|
{ name: "首页", url: "/homepage" }, |
|
|
|
|
{ name: "数字油站", url: "/plan" }, |
|
|
|
|
{ name: "今日预警", url: "/todaywarning" }, |
|
|
|
|
{ name: "预警记录", url: "/records_nav" }, |
|
|
|
|
{ name: "证照管理", url: "/audit" }, |
|
|
|
|
]; |
|
|
|
|
menu2 = [ |
|
|
|
|
{ name: "数字油站", url: "/plan/petrolStation" }, |
|
|
|
|
{ name: "今日预警", url: "/todaywarning/petrolStation" }, |
|
|
|
|
{ name: "预警记录", url: "/records_nav/petrolStation" }, |
|
|
|
|
{ name: "证照管理", url: "/license/petrolStation" }, |
|
|
|
|
]; |
|
|
|
|
init3D; |
|
|
|
|
async getGasStationBaseInfo() { |
|
|
|
|
await new Promise((resolve, reject) => { |
|
|
|
|
let params = { |
|
|
|
|
organizationUnitId: JSON.parse( |
|
|
|
|
sessionStorage.getItem("userdataOfgasstation") |
|
|
|
|
).organization.id, |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.get("/api/services/app/GasStation/Get", { params: params }) |
|
|
|
|
.subscribe((data: any) => { |
|
|
|
|
resolve(data.result); |
|
|
|
|
|
|
|
|
|
sessionStorage.setItem("3dSceneData", JSON.stringify(data.result)); |
|
|
|
|
this.init3D = data.result.hasBuildingInfo; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
toPage(data) { |
|
|
|
|
if (data.result.user.organization.isGasStation) { |
|
|
|
|
sessionStorage.setItem("isGasStation", "true"); |
|
|
|
|
let userdata = sessionStorage.getItem("userdataOfgasstation"); |
|
|
|
|
let menuList = this.returnLastMenus(userdata, this.menu2); |
|
|
|
|
let isTrue = menuList.find((item) => { |
|
|
|
|
return item.name == "今日预警"; |
|
|
|
|
}); |
|
|
|
|
if (isTrue) { |
|
|
|
|
this.router.navigate(["/todaywarning/petrolStation"]); |
|
|
|
|
sessionStorage.setItem("selectedMenu", "今日预警"); |
|
|
|
|
} else if (data.result.user.menus[0].name == "数字油站" && !this.init3D) { |
|
|
|
|
this.router.navigate([menuList[1].url]); |
|
|
|
|
sessionStorage.setItem("selectedMenu", menuList[1].name); |
|
|
|
|
} else if (menuList.length == 0) { |
|
|
|
|
return this.message.create("warning", `当前用户未分配菜单`); |
|
|
|
|
} else { |
|
|
|
|
this.router.navigate([menuList[0].url]); |
|
|
|
|
sessionStorage.setItem("selectedMenu", menuList[0].name); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
sessionStorage.setItem("isGasStation", "false"); |
|
|
|
|
let a = sessionStorage.getItem("userdata"); |
|
|
|
|
let menuList = this.returnLastMenus(a, this.menu1); |
|
|
|
|
let isTrue = menuList.find((item) => { |
|
|
|
|
return item.name == "首页"; |
|
|
|
|
}); |
|
|
|
|
if (menuList.length == 0) { |
|
|
|
|
return this.message.create("warning", `当前用户未分配菜单`); |
|
|
|
|
} |
|
|
|
|
if (isTrue) { |
|
|
|
|
this.router.navigate(["/homepage"]); |
|
|
|
|
sessionStorage.setItem("selectedMenu", "首页"); |
|
|
|
|
} else { |
|
|
|
|
this.router.navigate([menuList[0].url]); |
|
|
|
|
sessionStorage.setItem("selectedMenu", menuList[0].name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
isVisible = false; |
|
|
|
|
//绑定我们自己的用户弹出框
|
|
|
|
|
bindingUser() { |
|
|
|
@ -197,7 +383,6 @@ export class SingleloginComponent implements OnInit {
|
|
|
|
|
this.getAllUsers(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取所有组织机构
|
|
|
|
|
nodes: any = []; |
|
|
|
|
organization; |
|
|
|
|