This commit is contained in:
MaxKey
2022-05-17 16:10:58 +08:00
parent 5a97385c50
commit 8fb35b33d6
11 changed files with 277 additions and 44 deletions

View File

@@ -22,6 +22,7 @@ import { environment } from '@env/environment';
import { CONSTS } from 'src/app/shared/consts';
import { AuthnService } from '../../service/authn.service';
import { knowHost } from '../../shared/utils/knowhost';
import { LayoutDefaultOptions } from '../../theme/layout-default';
@Component({
@@ -109,8 +110,9 @@ import { LayoutDefaultOptions } from '../../theme/layout-default';
<theme-btn></theme-btn>
`
})
export class LayoutBasicComponent {
export class LayoutBasicComponent implements OnInit {
version = CONSTS.VERSION;
inst: any;
options: LayoutDefaultOptions = {
logoExpanded: `./assets/logo-full.svg`,
logoCollapsed: `./assets/logo.svg`,
@@ -129,5 +131,15 @@ export class LayoutBasicComponent {
changePassword(): void {
this.router.navigateByUrl('/config/password');
}
constructor(private settingsService: SettingsService, private router: Router) { }
ngOnInit(): void {
this.inst = this.authnService.getInst();
if (this.inst == null) {
this.authnService.initInst().subscribe(res => {
this.authnService.setInst(res.data, !knowHost());
this.inst = this.authnService.getInst();
});
}
}
constructor(private authnService: AuthnService, private settingsService: SettingsService, private router: Router) { }
}

View File

@@ -1,30 +1,38 @@
<div class="container">
<div nz-row style="border-bottom: 1px solid #e5e5e5; min-height: 60px; text-shadow: 0 1px 0 #fff">
<div nz-col nzMd="2"></div>
<div nz-col nzMd="2" style="text-align: right"> <img style="margin-top: 6px" class="logo" src="./assets/logo.jpg" /></div>
<div nz-col nzMd="2" style="text-align: right">
<img *ngIf="this.inst == null || !inst.custom" style="margin-top: 6px" class="logo" src="./assets/logo.jpg" />
<img *ngIf="inst.custom" style="margin-top: 6px" class="logo" src="{{ inst.logo }}" />
</div>
<div nz-col nzMd="10">
<div class="title">{{ 'mxk.login.title' | i18n }}{{ 'mxk.title' | i18n }}</div>
<div *ngIf="!inst.custom" class="title">Max<span style="color: #ffd700">Key</span>{{ 'mxk.title' | i18n }}</div>
<div *ngIf="inst.custom" class="title">{{ inst.title }}</div>
</div>
<div nz-col nzMd="6"></div>
<div nz-col nzXs="0" nzSm="0" nzMd="2"><header-i18n showLangText="false" class="langs"></header-i18n></div>
<div nz-col nzXs="0" nzSm="0" nzMd="2">
<header-i18n showLangText="false" class="langs"></header-i18n>
</div>
<div nz-col nzMd="2"></div>
</div>
<div class="wrap">
<div class="top" nz-col nzXs="0" nzSm="0" nzMd="24">
<div class="desc"
><b>{{ 'mxk.login.title.sub' | i18n }}</b></div
>
<div class="desc" *ngIf="!inst.custom">
<b>{{ 'mxk.login.title.sub' | i18n }}</b>
</div>
</div>
<router-outlet></router-outlet>
<global-footer style="border-top: 1px solid #e5e5e5; min-height: 60px; text-shadow: 0 1px 0 #fff">
<div style="margin-top: 20px">
MaxKey {{ version }}<br />
Copyright
<i nz-icon nzType="copyright"></i> 2022 <a href="//www.maxkey.top" target="_blank">http://www.maxkey.top</a><br />
<i nz-icon nzType="copyright"></i>
2022
<a href="//www.maxkey.top" target="_blank"> http://www.maxkey.top </a><br />
Licensed under the Apache License, Version 2.0
</div>
</global-footer>
</div>
</div>
<theme-btn></theme-btn>
<theme-btn></theme-btn>

View File

@@ -19,6 +19,9 @@ import { ActivatedRoute } from '@angular/router';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { CONSTS } from 'src/app/shared/consts';
import { AuthnService } from '../../service/authn.service';
import { knowHost } from '../../shared/utils/knowhost';
@Component({
selector: 'layout-passport',
templateUrl: './passport.component.html',
@@ -26,6 +29,8 @@ import { CONSTS } from 'src/app/shared/consts';
})
export class LayoutPassportComponent implements OnInit {
version = CONSTS.VERSION;
inst: any;
links = [
{
title: '帮助',
@@ -37,7 +42,19 @@ export class LayoutPassportComponent implements OnInit {
}
];
constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private route: ActivatedRoute) { }
constructor(
private authnService: AuthnService,
@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
private route: ActivatedRoute
) { }
ngOnInit(): void { }
ngOnInit(): void {
this.inst = this.authnService.getInst();
if (this.inst == null) {
this.authnService.initInst().subscribe(res => {
this.authnService.setInst(res.data, !knowHost());
this.inst = this.authnService.getInst();
});
}
}
}

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { HttpClient } from '@angular/common/http';
import { Injectable, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { StartupService } from '@core';
@@ -37,6 +38,7 @@ export class AuthnService {
private settingsService: SettingsService,
private cookieService: CookieService,
private startupService: StartupService,
private client: HttpClient,
@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
private http: _HttpClient
) { }
@@ -103,13 +105,24 @@ export class AuthnService {
jwtAuth(authParam: any) {
return this.http.get(`/login/jwt/trust?_allow_anonymous=true`, authParam);
}
setInst(inst: any) {
localStorage.setItem(CONSTS.INST, JSON.stringify({ id: inst.id, name: inst.name, title: inst.frontTitle, logo: inst.logo }));
setInst(inst: any, custom: boolean) {
localStorage.setItem(
CONSTS.INST,
JSON.stringify({ custom: custom, id: inst.id, name: inst.name, title: inst.frontTitle, logo: inst.logo })
);
}
getInst() {
return JSON.parse(`${localStorage.getItem(CONSTS.INST)}`);
let strInst = `${localStorage.getItem(CONSTS.INST)}`;
if (strInst == null || strInst === '') {
return null;
} else {
return JSON.parse(strInst);
}
}
initInst() {
return this.http.get(`/inst/get?_allow_anonymous=true`);
}
setRoles(aclService: ACLService | null): string[] {

View File

@@ -0,0 +1,9 @@
export function knowHost() {
let hostArray: string[] = new Array('localhost', 'sso.maxkey.top', 'mgt.maxkey.top', 'sso.maxsso.net', 'mgt.maxsso.net');
for (var i = 0; i < hostArray.length; i++) {
if (hostArray[i] == location.hostname) {
return true;
}
}
return false;
}

View File

@@ -13,7 +13,101 @@
<script src="./assets/transform.js"></script>
<!-- Apple Touch Icon -->
<!-- <link rel="apple-touch-icon" href="custom-icon.png"> -->
<style type="text/css">.preloader{position:fixed;top:0;left:0;z-index:9999;width:100%;height:100%;overflow:hidden;background:#49a9ee;transition:opacity .65s}.preloader-hidden-add{display:block;opacity:1}.preloader-hidden-add-active{opacity:0}.preloader-hidden{display:none}.cs-loader{position:absolute;top:0;left:0;width:100%;height:100%}.cs-loader-inner{position:absolute;top:50%;width:100%;color:#fff;text-align:center;transform:translateY(-50%)}.cs-loader-inner label{display:inline-block;font-size:20px;opacity:0}@keyframes lol{0%{transform:translateX(-300px);opacity:0}33%{transform:translateX(0);opacity:1}66%{transform:translateX(0);opacity:1}100%{transform:translateX(300px);opacity:0}}.cs-loader-inner label:nth-child(6){animation:lol 3s infinite ease-in-out}.cs-loader-inner label:nth-child(5){animation:lol 3s .1s infinite ease-in-out}.cs-loader-inner label:nth-child(4){animation:lol 3s .2s infinite ease-in-out}.cs-loader-inner label:nth-child(3){animation:lol 3s .3s infinite ease-in-out}.cs-loader-inner label:nth-child(2){animation:lol 3s .4s infinite ease-in-out}.cs-loader-inner label:nth-child(1){animation:lol 3s .5s infinite ease-in-out}</style>
<style type="text/css">
.preloader {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
width: 100%;
height: 100%;
overflow: hidden;
background: #49a9ee;
transition: opacity .65s
}
.preloader-hidden-add {
display: block;
opacity: 1
}
.preloader-hidden-add-active {
opacity: 0
}
.preloader-hidden {
display: none
}
.cs-loader {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}
.cs-loader-inner {
position: absolute;
top: 50%;
width: 100%;
color: #fff;
text-align: center;
transform: translateY(-50%)
}
.cs-loader-inner label {
display: inline-block;
font-size: 20px;
opacity: 0
}
@keyframes lol {
0% {
transform: translateX(-300px);
opacity: 0
}
33% {
transform: translateX(0);
opacity: 1
}
66% {
transform: translateX(0);
opacity: 1
}
100% {
transform: translateX(300px);
opacity: 0
}
}
.cs-loader-inner label:nth-child(6) {
animation: lol 3s infinite ease-in-out
}
.cs-loader-inner label:nth-child(5) {
animation: lol 3s .1s infinite ease-in-out
}
.cs-loader-inner label:nth-child(4) {
animation: lol 3s .2s infinite ease-in-out
}
.cs-loader-inner label:nth-child(3) {
animation: lol 3s .3s infinite ease-in-out
}
.cs-loader-inner label:nth-child(2) {
animation: lol 3s .4s infinite ease-in-out
}
.cs-loader-inner label:nth-child(1) {
animation: lol 3s .5s infinite ease-in-out
}
</style>
</head>
<body>
@@ -56,28 +150,28 @@
}
</script>
-->
<!--飞书-->
<!---->
<script src="http://sf3-cn.feishucdn.com/obj/static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.1.js"></script>
<script type="text/javascript">
<script type="text/javascript">
var fsredirectUri = "";
var QRLoginObj ;
var handleMessage = function (event) {
var origin = event.origin;
// 使用 matchOrigin 方法来判断 message 是否来自飞书页面
if( QRLoginObj && QRLoginObj.matchOrigin(origin) ) {
var loginTmpCode = event.data;
// 在授权页面地址上拼接上参数 tmp_code并跳转
fsredirectUri = fsredirectUri+"&tmp_code="+loginTmpCode;
window.top.location.href = fsredirectUri;
}
var QRLoginObj;
var handleMessage = function (event) {
var origin = event.origin;
// 使用 matchOrigin 方法来判断 message 是否来自飞书页面
if (QRLoginObj && QRLoginObj.matchOrigin(origin)) {
var loginTmpCode = event.data;
// 在授权页面地址上拼接上参数 tmp_code并跳转
fsredirectUri = fsredirectUri + "&tmp_code=" + loginTmpCode;
window.top.location.href = fsredirectUri;
}
};
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('message', handleMessage, false);}
else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('onmessage', handleMessage);
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('message', handleMessage, false);
}
else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('onmessage', handleMessage);
}
</script>
</html>
</html>