This commit is contained in:
MaxKey 2022-05-17 17:15:15 +08:00
parent 1e9c5ec317
commit 3f4af8fdd6
9 changed files with 84 additions and 26 deletions

View File

@ -37,13 +37,20 @@ import { LayoutDefaultOptions } from '../../theme/layout-default';
],
template: `
<layout-default [options]="options" [asideUser]="asideUserTpl" [content]="contentTpl" [customError]="null">
<layout-default-header-item direction="left">
<layout-default-header-item direction="left" *ngIf="!inst.custom">
<a href="#">
<img src="./assets/logo.jpg" alt="logo" style="height: 50px;height: 50px;float: left;" />
<div class="alain-default__header-title"> Max<span style="color: #FFD700;">Key</span>{{ 'mxk.title' | i18n }} </div>
</a>
</layout-default-header-item>
<layout-default-header-item direction="left" *ngIf="inst.custom">
<a href="#">
<img src="{{ inst.logo }}" alt="logo" style="height: 50px;height: 50px;float: left;" />
<div class="alain-default__header-title"> {{ inst.title }} </div>
</a>
</layout-default-header-item>
<layout-default-header-item direction="right" hidden="mobile">
<div layout-default-header-item-trigger (click)="profile()"> {{ user.name }}</div>
</layout-default-header-item>
@ -135,6 +142,7 @@ export class LayoutBasicComponent implements OnInit {
ngOnInit(): void {
this.inst = this.authnService.getInst();
if (this.inst == null) {
this.inst = { custom: false };
this.authnService.initInst().subscribe(res => {
this.authnService.setInst(res.data, !knowHost());
this.inst = this.authnService.getInst();

View File

@ -2,7 +2,7 @@
<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 *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="./assets/logo.jpg" />
<img *ngIf="inst.custom" style="margin-top: 6px" class="logo" src="{{ inst.logo }}" />
</div>
<div nz-col nzMd="10">

View File

@ -51,6 +51,7 @@ export class LayoutPassportComponent implements OnInit {
ngOnInit(): void {
this.inst = this.authnService.getInst();
if (this.inst == null) {
this.inst = { custom: false };
this.authnService.initInst().subscribe(res => {
this.authnService.setInst(res.data, !knowHost());
this.inst = this.authnService.getInst();

View File

@ -14,11 +14,13 @@
* limitations under the License.
*/
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { SettingsService, User } from '@delon/theme';
import { environment } from '@env/environment';
import { AuthnService } from 'src/app/service/authn.service';
import { CONSTS } from 'src/app/shared/consts';
import { knowHost } from '../../shared/utils/knowhost';
import { LayoutDefaultOptions } from '../../theme/layout-default';
@Component({
@ -33,7 +35,7 @@ import { LayoutDefaultOptions } from '../../theme/layout-default';
],
template: `
<layout-default [options]="options" [asideUser]="asideUserTpl" [content]="contentTpl" [customError]="null">
<layout-default-header-item direction="left">
<layout-default-header-item direction="left" *ngIf="!inst.custom">
<a href="#">
<img src="./assets/logo.jpg" alt="logo" style="height: 50px;height: 50px;float: left;" />
<div
@ -48,6 +50,21 @@ import { LayoutDefaultOptions } from '../../theme/layout-default';
</div>
</a>
</layout-default-header-item>
<layout-default-header-item direction="left" *ngIf="inst.custom">
<a href="#">
<img src="{{ inst.logo }}" alt="logo" style="height: 50px;height: 50px;float: left;" />
<div
class="alain-default__nav-item_title"
style="letter-spacing: 2px;
font-size: 20px;
font-weight: bolder;
width: 450px;
margin-top: 12px;"
>
{{ inst.title }}
</div>
</a>
</layout-default-header-item>
<layout-default-header-item direction="right" hidden="mobile">
<div layout-default-header-item-trigger>
@ -110,8 +127,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`,
@ -123,5 +141,16 @@ export class LayoutBasicComponent {
return this.settingsService.user;
}
constructor(private settingsService: SettingsService) { }
ngOnInit(): void {
this.inst = this.authnService.getInst();
if (this.inst == null) {
this.inst = { custom: false };
this.authnService.initInst().subscribe(res => {
this.authnService.setInst(res.data, !knowHost());
this.inst = this.authnService.getInst();
});
}
}
constructor(private settingsService: SettingsService, private authnService: AuthnService) { }
}

View File

@ -2,12 +2,13 @@
<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 *ngIf="!isTitle" style="margin-top: 6px" class="logo" src="./assets/logo.jpg" />
<img *ngIf="isTitle" style="margin-top: 6px" class="logo" src="{{ inst.logo }}" />
<img *ngIf="!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 *ngIf="!isTitle" class="title">Max<span style="color: #ffd700">Key</span>{{ 'mxk.title' | i18n }}</div>
<div *ngIf="isTitle" class="title">{{ inst.title }}</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">
@ -18,7 +19,7 @@
<div class="wrap">
<div class="top" nz-col nzXs="0" nzSm="0" nzMd="24">
<div class="desc">{{ 'mxk.login.title.sub' | i18n }}</div>
<div class="desc" *ngIf="inst == null || !inst.custom">{{ 'mxk.login.title.sub' | i18n }}</div>
</div>
<router-outlet></router-outlet>
<global-footer style="border-top: 1px solid #e5e5e5; min-height: 60px; text-shadow: 0 1px 0 #fff">

View File

@ -19,6 +19,8 @@ import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { AuthnService } from 'src/app/service/authn.service';
import { CONSTS } from 'src/app/shared/consts';
import { knowHost } from '../../shared/utils/knowhost';
@Component({
selector: 'layout-passport',
templateUrl: './passport.component.html',
@ -26,7 +28,6 @@ import { CONSTS } from 'src/app/shared/consts';
})
export class LayoutPassportComponent implements OnInit {
version = CONSTS.VERSION;
isTitle: boolean = false;
inst: any;
links = [
{
@ -42,15 +43,13 @@ export class LayoutPassportComponent implements OnInit {
constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private authnService: AuthnService) { }
ngOnInit(): void {
if (
window.location.hostname != 'localhost' &&
window.location.hostname != 'sso.maxkey.top' &&
window.location.hostname != 'mgt.maxkey.top'
) {
this.inst = this.authnService.getInst();
if (this.inst != null) {
this.isTitle = true;
}
this.inst = this.authnService.getInst();
if (this.inst == null) {
this.inst = { custom: false };
this.authnService.initInst().subscribe(res => {
this.authnService.setInst(res.data, !knowHost());
this.inst = this.authnService.getInst();
});
}
this.tokenService.clear();
}

View File

@ -94,8 +94,7 @@ export class UserLoginComponent implements OnInit, OnDestroy {
this.error = res.msg;
} else {
// 清空路由复用信息
console.log(res.data);
this.authnService.setInst(res.data.inst);
//console.log(res.data);
this.state = res.data.state;
//init image captcha
this.imageCaptchaService.captcha({ state: this.state }).subscribe(res => {

View File

@ -94,12 +94,24 @@ export class AuthnService {
this.tokenService.get()?.expired;
}
setInst(inst: any) {
localStorage.setItem(CONSTS.INST, JSON.stringify({ id: inst.id, name: inst.name, title: inst.consoleTitle, logo: inst.logo }));
setInst(inst: any, custom: boolean) {
localStorage.setItem(
CONSTS.INST,
JSON.stringify({ custom: custom, id: inst.id, name: inst.name, title: inst.consoleTitle, 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`);
}
navigate(authJwt: any) {

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;
}