|
|
@ -8,6 +8,9 @@ import { |
|
|
|
DigiMiddlewareAuthUser, |
|
|
|
} from "app/config/app-auth-token"; |
|
|
|
import { CommonService } from "../service/common.service"; |
|
|
|
import { log } from "console"; |
|
|
|
import { menuData } from './../menu/model/menu.model'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: "app-layout", |
|
|
|
templateUrl: "./layout.component.html", |
|
|
@ -16,142 +19,114 @@ import { CommonService } from "../service/common.service"; |
|
|
|
export class LayoutComponent implements OnInit { |
|
|
|
// 登出: https://iam-test.digiwincloud.com.cn/api/iam/v2/identity/logout
|
|
|
|
userToken: string; |
|
|
|
systemList = {}; |
|
|
|
systemMaps = {}; |
|
|
|
user_info = { |
|
|
|
userId: "", // 当前用户账号
|
|
|
|
tenantId: "", // 当前用户租户id
|
|
|
|
productKey: "", // json字段的头部
|
|
|
|
}; |
|
|
|
queryDisplayList = []; |
|
|
|
constructor(private commonService: CommonService) {} |
|
|
|
constructor(private commonService: CommonService) { } |
|
|
|
ngOnInit(): void { |
|
|
|
this.systemList = systemList; |
|
|
|
this.getSystem(); |
|
|
|
} |
|
|
|
toLinkSystem(type?) { |
|
|
|
// 1. 通过获取user_token获取单点登录链接
|
|
|
|
// 请求获取user_token
|
|
|
|
switch (type) { |
|
|
|
case "DMP": |
|
|
|
this.getUserToken(type, this.systemList["DMP"]); |
|
|
|
break; |
|
|
|
case "chatFile": |
|
|
|
this.getUserToken(type, this.systemList["chatFile"]); |
|
|
|
break; |
|
|
|
case "KMO": |
|
|
|
this.getUserToken(type, this.systemList["KMO"]); |
|
|
|
break; |
|
|
|
case "EIP": |
|
|
|
this.getUserToken(type, this.systemList["EIP"]); |
|
|
|
break; |
|
|
|
case "AIOT": |
|
|
|
this.getUserToken(type, this.systemList["AIOT"]); |
|
|
|
break; |
|
|
|
case "equipmentCloud": |
|
|
|
this.getUserToken(type, this.systemList["equipmentCloud"]); |
|
|
|
break; |
|
|
|
case "partsCloud": |
|
|
|
this.getUserToken(type, this.systemList["partsCloud"]); |
|
|
|
break; |
|
|
|
case "E10229": |
|
|
|
this.getUserToken(type, this.systemList["E10229"]); |
|
|
|
break; |
|
|
|
case "T100bs": |
|
|
|
this.getUserToken(type, this.systemList["T100bs"]); |
|
|
|
break; |
|
|
|
} |
|
|
|
this.systemMaps = systemList; |
|
|
|
this.initSystemBySemcSSO(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 通过请求queryDisplayList接口登录 |
|
|
|
*/ |
|
|
|
getSystem() { |
|
|
|
initSystemBySemcSSO() { |
|
|
|
const headers = { |
|
|
|
"Digi-Middleware-Auth-App": DigiMiddlewareAuthApp, |
|
|
|
"Digi-Middleware-Auth-User": DigiMiddlewareAuthUser, |
|
|
|
}; |
|
|
|
this.commonService |
|
|
|
.getRequestWithHeaders( |
|
|
|
this.commonService.semcUrl + "/tenant/semc/applink/queryDisplayList", |
|
|
|
headers |
|
|
|
) |
|
|
|
.then((res) => { |
|
|
|
this.queryDisplayList = res.response; |
|
|
|
console.log("queryDisplayList", this.queryDisplayList); |
|
|
|
}) |
|
|
|
.catch((error) => console.error(error)); |
|
|
|
const url = this.commonService.semcUrl + "/tenant/semc/applink/queryDisplayList"; |
|
|
|
this.commonService.getRequestWithHeaders(url, headers).then((res) => { |
|
|
|
this.queryDisplayList = res.response; |
|
|
|
this.queryDisplayList.forEach(item => { |
|
|
|
this.systemMaps["SSO_" + item.id] = { |
|
|
|
key: item.id, |
|
|
|
id: item.id, |
|
|
|
title: item.name, |
|
|
|
mockLogin: false, |
|
|
|
ssoLogin: true, |
|
|
|
callBackUrl: item.callBackUrl, |
|
|
|
url: item.cloudwebsite, |
|
|
|
applicationAppId: item.applicationAppId |
|
|
|
}; |
|
|
|
}); |
|
|
|
console.log("systemMaps", this.systemMaps); |
|
|
|
}).catch((error) => console.error(error)); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 三种方式的url拼接 |
|
|
|
*/ |
|
|
|
async getUserToken(type, item) { |
|
|
|
console.log("item", item); |
|
|
|
|
|
|
|
|
|
|
|
jumpToSystem(key: string) { |
|
|
|
|
|
|
|
console.log(this.systemMaps); |
|
|
|
if (this.systemMaps[key] == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const item = this.systemMaps[key]; |
|
|
|
|
|
|
|
// 免密跳转
|
|
|
|
if (item.linkLogin) { |
|
|
|
window.open(item.url,'_blank'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const DwUserInfo = JSON.parse(sessionStorage.getItem("DwUserInfo")); |
|
|
|
|
|
|
|
const headers = { |
|
|
|
"Digi-Middleware-Auth-App": DigiMiddlewareAuthApp, |
|
|
|
"Digi-Middleware-Auth-User": DigiMiddlewareAuthUser, |
|
|
|
}; |
|
|
|
|
|
|
|
// 单点登录
|
|
|
|
if (item.ssoLogin) { |
|
|
|
// 单点登录跳转 queryDisplayList接口的数据 底部 e10 t100
|
|
|
|
// 需要拼applicationAppId
|
|
|
|
console.log("单点登录跳转的方式", type); |
|
|
|
let url = ""; |
|
|
|
const queryDisplayList = this.queryDisplayList.filter((arr) => { |
|
|
|
return arr.code === type; |
|
|
|
|
|
|
|
this.commonService.postWithHeaders(this.commonService.iamUrl + "/api/iam/v2/oauth2/authorize", |
|
|
|
{ |
|
|
|
"appId": item.applicationAppId, |
|
|
|
"callbackUrl": item.callBackUrl |
|
|
|
}, |
|
|
|
headers |
|
|
|
).then(res => { |
|
|
|
if (res && res.data && res.data.code) { |
|
|
|
window.open(item.url + "&code=" + res.data.code); |
|
|
|
} |
|
|
|
}); |
|
|
|
// console.log("queryDisplayList111", queryDisplayList);
|
|
|
|
if ( |
|
|
|
queryDisplayList.length > 0 && |
|
|
|
queryDisplayList[0]?.applicationAppId |
|
|
|
) { |
|
|
|
url = |
|
|
|
queryDisplayList[0]["cloudwebsite"] + |
|
|
|
"&code=" + |
|
|
|
queryDisplayList[0].applicationAppId; |
|
|
|
} else { |
|
|
|
url = queryDisplayList[0]["cloudwebsite"]; |
|
|
|
} |
|
|
|
console.log("单点登录url", url); |
|
|
|
window.open(url); |
|
|
|
} else if (item.mockLogin) { |
|
|
|
console.log("模拟登录的方式", type); |
|
|
|
// 通过书康哥接口请求 模拟登录
|
|
|
|
const DwUserInfo = JSON.parse(sessionStorage.getItem("DwUserInfo")); |
|
|
|
console.log("DwUserInfo", DwUserInfo); |
|
|
|
this.user_info.userId = DwUserInfo["userId"]; |
|
|
|
this.user_info.tenantId = DwUserInfo["tenantId"]; |
|
|
|
this.user_info.productKey = type; |
|
|
|
console.log("user_info", this.user_info); |
|
|
|
let getUrl = ""; |
|
|
|
getUrl = |
|
|
|
this.commonService.apiUrl + "/restful/standard/demo/api/default/login"; |
|
|
|
this.commonService |
|
|
|
.postWithHeaders(getUrl, this.user_info, {}) |
|
|
|
.then((res) => { |
|
|
|
// console.log("res", res);
|
|
|
|
if (res && res.response) { |
|
|
|
this.userToken = res.response.user_token; |
|
|
|
const url = item.url + "/sso-login?userToken=" + this.userToken; |
|
|
|
window.open(url); |
|
|
|
} |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 模拟登录
|
|
|
|
if (item.mockLogin) { |
|
|
|
|
|
|
|
this.commonService.postWithHeaders(this.commonService.apiUrl + "/restful/standard/demo/api/default/login", |
|
|
|
{ |
|
|
|
userId: DwUserInfo.userId, |
|
|
|
tenantId: DwUserInfo.tenantId, |
|
|
|
productKey: item.id |
|
|
|
}, headers |
|
|
|
).then(res => { |
|
|
|
if (res && res.response) { |
|
|
|
window.open(item.url + "/sso-login?userToken=" + res.response.user_token); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("切换租户的方式", type); |
|
|
|
// 接口 refresh/tenant 切换租户方式
|
|
|
|
const getUrl = |
|
|
|
this.commonService.iamUrl + "/api/iam/v2/identity/token/refresh/tenant"; |
|
|
|
console.log("iamUrl", this.commonService.iamUrl); |
|
|
|
const headers = { |
|
|
|
"Digi-Middleware-Auth-App": DigiMiddlewareAuthApp, |
|
|
|
"Digi-Middleware-Auth-User": DigiMiddlewareAuthUser, |
|
|
|
}; |
|
|
|
const data = { |
|
|
|
tenantSid: item.sid, |
|
|
|
}; |
|
|
|
this.userToken = await this.commonService |
|
|
|
.postWithHeaders(getUrl, data, headers) |
|
|
|
.then((res) => { |
|
|
|
// console.log("res", res);
|
|
|
|
return res.user_token; |
|
|
|
}); |
|
|
|
let url = ""; |
|
|
|
url = item.url + "/sso-login?userToken=" + this.userToken; |
|
|
|
console.log("切换租户的方式url", url); |
|
|
|
window.open(url); |
|
|
|
|
|
|
|
// 切换租户登录
|
|
|
|
this.commonService.postWithHeaders(this.commonService.iamUrl + "/api/iam/v2/identity/token/refresh/tenant", |
|
|
|
{ tenantSid: item.sid }, |
|
|
|
headers |
|
|
|
).then(res => { |
|
|
|
if (res) { |
|
|
|
window.open(item.url + "/sso-login?userToken=" + res.user_token); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |