移除本地缓存用户信息
This commit is contained in:
@@ -30,6 +30,7 @@ export class AdminDashboardComponent implements OnInit {
|
||||
|
||||
dayVisitCount: number = 0;
|
||||
userInfo: User = new User();
|
||||
private isRequested: boolean = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
@@ -52,13 +53,14 @@ export class AdminDashboardComponent implements OnInit {
|
||||
getUserInfo = () => this.userService.watchUserInfo({
|
||||
next: data => {
|
||||
this.userInfo = data.result
|
||||
if (data.result && data.result.role === 'admin') {
|
||||
if (data.result && data.result.role === 'admin' && !this.isRequested) {
|
||||
this.getLog();
|
||||
this.getCounts();
|
||||
this.isRequested = true;
|
||||
this.getDayVisitCount();
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
complete: null
|
||||
error: () => null,
|
||||
complete: () => null
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,47 +8,47 @@ const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: AdminComponent,
|
||||
// canActivate: [AuthGuard],
|
||||
canActivate: [AuthGuard],
|
||||
children: [
|
||||
{
|
||||
path: 'article',
|
||||
loadChildren: () => import('./admin-article/admin-article.module').then(mod => mod.AdminArticleModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: 'comment',
|
||||
loadChildren: () => import('./admin-comment/admin-comment.module').then(mod => mod.AdminCommentModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: 'link',
|
||||
loadChildren: () => import('./admin-link/admin-link.module').then(mod => mod.AdminLinkModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: 'tag',
|
||||
loadChildren: () => import('./admin-tag/admin-tag.module').then(mod => mod.AdminTagModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: 'update',
|
||||
loadChildren: () => import('./admin-update/admin-update.module').then(mod => mod.AdminUpdateModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: 'user',
|
||||
loadChildren: () => import('./admin-user/admin-user.module').then(mod => mod.AdminUserModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: 'visitor',
|
||||
loadChildren: () => import('./admin-visitor/admin-visitor.module').then(mod => mod.AdminVisitorModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
},
|
||||
{
|
||||
path: '**',
|
||||
loadChildren: () => import('./admin-dashboard/admin-dashboard.module').then(mod => mod.AdminDashboardModule),
|
||||
canActivate: [AuthGuard]
|
||||
// canActivate: [AuthGuard]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -91,24 +91,24 @@
|
||||
<nz-drawer [nzClosable]="false" [nzVisible]="infoDrawerVisible" nzPlacement="right"
|
||||
[nzTitle]="sayHelloTemp" (nzOnClose)="infoDrawerVisible = false">
|
||||
<p>您最近一次登录是在:</p>
|
||||
<p>{{user.recentlyLandedDate}}</p>
|
||||
<p>{{user&&user.recentlyLandedDate}}</p>
|
||||
<nz-divider></nz-divider>
|
||||
<nz-descriptions [nzColumn]="1">
|
||||
<nz-descriptions-item nzTitle="邮箱">
|
||||
<div>
|
||||
<i nz-icon nzType="mail" class="icon" nzTheme="twotone"></i>
|
||||
<span>{{user.email}}</span>
|
||||
<span>{{user&&user.email}}</span>
|
||||
<i nz-icon nzType="edit" class="edit-icon" nzTheme="twotone" (click)="showEditInfoModal()"></i>
|
||||
</div>
|
||||
</nz-descriptions-item>
|
||||
<nz-descriptions-item nzTitle="昵称">
|
||||
<div>
|
||||
<i nz-icon nzType="crown" class="icon" nzTheme="twotone"></i>
|
||||
<span>{{user.displayName}}</span>
|
||||
<span>{{user&&user.displayName}}</span>
|
||||
<i nz-icon nzType="edit" class="edit-icon" nzTheme="twotone" (click)="showEditInfoModal()"></i>
|
||||
</div>
|
||||
</nz-descriptions-item>
|
||||
<nz-descriptions-item nzTitle="描述" *ngIf="user.desc">
|
||||
<nz-descriptions-item nzTitle="描述" *ngIf="user&&user.desc">
|
||||
<i nz-icon nzType="info-circle" class="icon" nzTheme="twotone"></i>
|
||||
<span nz-tooltip [nzTooltipTitle]="user.desc" nzTooltipPlacement="left" nz-typography [nzEllipsis]="true" [nzContent]="user.desc" style="max-width: 100px">{{user.desc}}</span>
|
||||
<i nz-icon nzType="edit" class="edit-icon" nzTheme="twotone" (click)="showEditInfoModal()"></i>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {NgZorroAntdModule} from 'ng-zorro-antd';
|
||||
import {NzSpaceModule} from 'ng-zorro-antd/space';
|
||||
import {AdminHeaderComponent} from '../../components/admin-header/admin-header.component';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import {AuthGuard} from './auth.guard';
|
||||
|
||||
|
||||
@NgModule({
|
||||
@@ -18,8 +19,9 @@ import {ReactiveFormsModule} from '@angular/forms';
|
||||
AdminRoutingModule,
|
||||
NgZorroAntdModule,
|
||||
NzSpaceModule,
|
||||
ReactiveFormsModule
|
||||
]
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
providers: [AuthGuard]
|
||||
})
|
||||
export class AdminModule {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router} from '@angular/router';
|
||||
import {
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
UrlTree,
|
||||
Router,
|
||||
CanActivateChild
|
||||
} from '@angular/router';
|
||||
import {Observable, Observer} from 'rxjs';
|
||||
import {User} from '../../class/User';
|
||||
import {GlobalUserService} from '../../services/global-user.service';
|
||||
@@ -10,7 +17,6 @@ import {GlobalUserService} from '../../services/global-user.service';
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
constructor(private userService: GlobalUserService, private router: Router) {
|
||||
// this.userService.refreshUserInfo();
|
||||
}
|
||||
|
||||
userInfo: User;
|
||||
@@ -34,11 +40,12 @@ export class AuthGuard implements CanActivate {
|
||||
|
||||
watchUserInfo(observer: Observer<boolean>) {
|
||||
this.userService.watchUserInfo({
|
||||
complete: null,
|
||||
complete: () => null,
|
||||
error: (err) => {
|
||||
// 请求重复
|
||||
if (err.code !== -1) {
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
this.router.navigateByUrl(this.loginPath);
|
||||
}
|
||||
},
|
||||
@@ -58,13 +65,15 @@ export class AuthGuard implements CanActivate {
|
||||
case '/admin/update':
|
||||
case '/admin/user':
|
||||
case '/admin/visitor':
|
||||
if (this.userInfo.role !== 'admin') {
|
||||
observer.next(false)
|
||||
if (this.userInfo && this.userInfo.role !== 'admin') {
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
if (this.visitCount === 1) this.router.navigateByUrl('/admin')
|
||||
return;
|
||||
}
|
||||
}
|
||||
observer.next(true);
|
||||
observer.complete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user