From 5185cba9012546e12362f14c7e3bf2ec14845e30 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Mon, 20 Apr 2020 16:33:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E8=8F=9C=E5=8D=95=E4=BB=A4=E7=89=8C?= =?UTF-8?q?=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/account/score/score.component.ts | 12 ++++++++++-- src/app/forum/forum/forum.component.ts | 12 +++++++++--- src/app/forum/notice/notice.component.ts | 5 +++++ src/app/visitor/visitor/visitor.component.ts | 12 ++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/app/account/score/score.component.ts b/src/app/account/score/score.component.ts index 33352ef..0d8f859 100644 --- a/src/app/account/score/score.component.ts +++ b/src/app/account/score/score.component.ts @@ -5,6 +5,8 @@ import {ScoreService} from './score.service'; import {MessageInterface, MessageUtil} from '../../message/message.service'; import {Page} from '../../interface/Page'; import {Info} from '../../interface/Info'; +import {AbstractRoute} from '../../AbstractRoute'; +import {Router} from '@angular/router'; @Component({ selector: 'app-score', @@ -40,7 +42,9 @@ export class ScoreComponent extends Commons implements OnInit, MessageInterface constructor( private fb: FormBuilder, private scoreService: ScoreService, - private messageUtil: MessageUtil + private messageUtil: MessageUtil, + private abstractRoute: AbstractRoute, + private router: Router, ) { super(); } @@ -70,7 +74,11 @@ export class ScoreComponent extends Commons implements OnInit, MessageInterface } ngOnInit(): void { - this.loadAll(this.currentPage); + if (this.abstractRoute.isLogin()) { + this.loadAll(this.currentPage); + } else { + this.router.navigateByUrl('/login'); + } } prefix(key: string): string { diff --git a/src/app/forum/forum/forum.component.ts b/src/app/forum/forum/forum.component.ts index e33ad15..8942aa8 100644 --- a/src/app/forum/forum/forum.component.ts +++ b/src/app/forum/forum/forum.component.ts @@ -8,6 +8,7 @@ import {MessageInterface, MessageUtil} from '../../message/message.service'; import {NoticeService} from '../notice/notice.service'; import {TranslateService} from '@ngx-translate/core'; import {ForumNewResponse} from '../../interface/Response'; +import {AbstractRoute} from '../../AbstractRoute'; /** * 论坛组件 @@ -57,7 +58,8 @@ export class ForumComponent implements OnInit, MessageInterface { private forumService: ForumService, private noticeService: NoticeService, private messageUtil: MessageUtil, - private translate: TranslateService + private translate: TranslateService, + private abstractRoute: AbstractRoute ) { } @@ -129,8 +131,12 @@ export class ForumComponent implements OnInit, MessageInterface { } ngOnInit(): void { - this.getAllNotices(); - this.getAllPosts(this.currentPage); + if (this.abstractRoute.isLogin()) { + this.getAllNotices(); + this.getAllPosts(this.currentPage); + } else { + this.router.navigateByUrl('/login'); + } } prefix(key: string): string { diff --git a/src/app/forum/notice/notice.component.ts b/src/app/forum/notice/notice.component.ts index c31c747..21f0238 100644 --- a/src/app/forum/notice/notice.component.ts +++ b/src/app/forum/notice/notice.component.ts @@ -7,6 +7,7 @@ import {MessageInterface, MessageUtil} from '../../message/message.service'; import {CookieService} from 'ngx-cookie-service'; import {environment} from '../../../environments/environment'; import {Router} from '@angular/router'; +import {AbstractRoute} from '../../AbstractRoute'; @Component({ selector: 'app-notice', @@ -31,6 +32,7 @@ export class NoticeComponent extends Commons implements OnInit, MessageInterface private messageUtil: MessageUtil, private cookieService: CookieService, private router: Router, + private abstractRoute: AbstractRoute ) { super(); } @@ -56,6 +58,9 @@ export class NoticeComponent extends Commons implements OnInit, MessageInterface } ngOnInit(): void { + if (!this.abstractRoute.isLogin()) { + this.router.navigateByUrl('/login'); + } } diff --git a/src/app/visitor/visitor/visitor.component.ts b/src/app/visitor/visitor/visitor.component.ts index 029500f..58bfbb5 100644 --- a/src/app/visitor/visitor/visitor.component.ts +++ b/src/app/visitor/visitor/visitor.component.ts @@ -6,6 +6,8 @@ import {Visitor} from '../../interface/Visitor'; import {Page} from '../../interface/Page'; import {environment} from '../../../environments/environment'; import {CookieService} from 'ngx-cookie-service'; +import {AbstractRoute} from '../../AbstractRoute'; +import {Router} from '@angular/router'; @Component({ selector: 'app-visitor', @@ -16,7 +18,9 @@ export class VisitorComponent implements OnInit, MessageInterface { constructor(private visitorService: VisitorService, private messageUtil: MessageUtil, - private cookieService: CookieService + private cookieService: CookieService, + private abstractRoute: AbstractRoute, + private router: Router, ) { } @@ -55,7 +59,11 @@ export class VisitorComponent implements OnInit, MessageInterface { } ngOnInit(): void { - this.loadAll(this.currentPage); + if (this.abstractRoute.isLogin()) { + this.loadAll(this.currentPage); + } else { + this.router.navigateByUrl('/login'); + } } }