diff --git a/index/src/app/components/admin-header/admin-header.component.html b/index/src/app/components/admin-header/admin-header.component.html
index 0fb20c9..2cd9cd6 100644
--- a/index/src/app/components/admin-header/admin-header.component.html
+++ b/index/src/app/components/admin-header/admin-header.component.html
@@ -10,21 +10,9 @@
-
+
-
-
-
-
+
{{user.displayName}}
diff --git a/index/src/app/components/admin-header/admin-header.component.less b/index/src/app/components/admin-header/admin-header.component.less
index d6794f8..96d0ba1 100644
--- a/index/src/app/components/admin-header/admin-header.component.less
+++ b/index/src/app/components/admin-header/admin-header.component.less
@@ -23,14 +23,16 @@ a {
#landr, #loged {
position: absolute;
- right: 20px;
+ right: 60px;
top: 20px;
+ cursor: pointer;
}
#blogTitle, #desc {
display: block;
margin-left: 15px;
+ max-width: 300px;
}
#blogTitle {
@@ -40,5 +42,6 @@ a {
#desc {
font-size: 10px;
+
}
diff --git a/index/src/app/services/global-user.service.ts b/index/src/app/services/global-user.service.ts
index 91e287f..904fa2b 100644
--- a/index/src/app/services/global-user.service.ts
+++ b/index/src/app/services/global-user.service.ts
@@ -41,22 +41,8 @@ export class GlobalUserService {
// 不符合 请求网络数据并更新缓存
// 向订阅者传数据
this.lastRequestTime = Date.now();
- const subscription = this.apiService.userInfo().subscribe({
- next: o => {
- this.localStorageService.setUser(o.result);
- this.userObserverArray.forEach(ob => ob.next(o));
- },
- error: err => {
- // console.debug('登录过期 token错误 等等');
- if (err.code === -1) {
- // 请求重复
- return
- }
- this.localStorageService.removeToken();
- this.userObserverArray.forEach(ob => ob.next(new Response
(null)));
- this.userObserverArray.forEach(ob => ob.error(err));
- }
- });
+ // 获取数据
+ const subscription = this.getUserInfoFromServer();
return {
unsubscribe() {
observer.complete();
@@ -65,6 +51,11 @@ export class GlobalUserService {
}
}
+ // 刷新用户信息
+ refreshUserInfo(): void {
+ this.getUserInfoFromServer();
+ }
+
login(loginReq: LoginReq, observer: Observer>) {
const oob = new Observable>(o => observer = o);
const subscription = this.apiService.login(loginReq).subscribe({
@@ -107,4 +98,23 @@ export class GlobalUserService {
}
})
}
+
+ private getUserInfoFromServer() {
+ return this.apiService.userInfo().subscribe({
+ next: o => {
+ this.localStorageService.setUser(o.result);
+ this.userObserverArray.forEach(ob => ob.next(o));
+ },
+ error: err => {
+ // console.debug('登录过期 token错误 等等');
+ if (err.code === -1) {
+ // 请求重复
+ return
+ }
+ this.localStorageService.removeToken();
+ this.userObserverArray.forEach(ob => ob.next(new Response(null)));
+ this.userObserverArray.forEach(ob => ob.error(err));
+ }
+ });
+ }
}
diff --git a/index/src/app/view/admin/admin.component.html b/index/src/app/view/admin/admin.component.html
index 725b33b..0700ffe 100644
--- a/index/src/app/view/admin/admin.component.html
+++ b/index/src/app/view/admin/admin.component.html
@@ -1,4 +1,4 @@
-
+
© 小海博客 - Design by 小海
+
+ 您最近一次登录是在:
+ {{user.recentlyLandedDate}}
+
+
+
+
+ {{user.email}}
+
+
+
+
+ {{user.displayName}}
+
+
+
+
+ {{user.desc}}
+
+
+
+
+
+
+
+
+
+
+
+
+ {{sayHelloContent}}
+
+
diff --git a/index/src/app/view/admin/admin.component.less b/index/src/app/view/admin/admin.component.less
index 5d83457..c609a9d 100644
--- a/index/src/app/view/admin/admin.component.less
+++ b/index/src/app/view/admin/admin.component.less
@@ -28,6 +28,14 @@ nz-content {
height: 100%;
}
+.icon {
+ margin-right: 5px;
+}
+.edit-icon{
+ margin-left: 10px;
+ cursor: pointer;
+}
+
nz-footer {
text-align: center;
}
diff --git a/index/src/app/view/admin/admin.component.ts b/index/src/app/view/admin/admin.component.ts
index b6af547..1049c9c 100644
--- a/index/src/app/view/admin/admin.component.ts
+++ b/index/src/app/view/admin/admin.component.ts
@@ -1,4 +1,6 @@
import {Component, OnInit} from '@angular/core';
+import {FormControl, FormGroup} from '@angular/forms';
+import {NzMessageService} from 'ng-zorro-antd';
import {GlobalUserService} from '../../services/global-user.service';
import {User} from '../../class/User';
import {ApiService} from '../../api/api.service';
@@ -10,13 +12,17 @@ import {ApiService} from '../../api/api.service';
})
export class AdminComponent implements OnInit {
- constructor(public gUserService: GlobalUserService, private apiService: ApiService) {
+ constructor(public gUserService: GlobalUserService, private apiService: ApiService, private messageService: NzMessageService) {
}
user: User;
isCollapsed: boolean = false;
infoDrawerVisible: boolean = false;
sayHelloContent: string;
+ editInfoModalVisible: boolean = false;
+ editInfoFormGroup: FormGroup;
+
+ showInfoDrawer = () => this.infoDrawerVisible = !this.infoDrawerVisible;
ngOnInit(): void {
this.gUserService.watchUserInfo({
@@ -28,6 +34,15 @@ export class AdminComponent implements OnInit {
}
}
)
+ this.editInfoFormGroup = new FormGroup({
+ desc: new FormControl(),
+ displayName: new FormControl(),
+ email: new FormControl()
+ });
+ this.initHelloWords()
+ }
+
+ private initHelloWords() {
const hours = new Date().getHours();
if (hours < 6) {
this.sayHelloContent = `夜深了,注意早点休息哦!${this.user.displayName}`
@@ -44,7 +59,24 @@ export class AdminComponent implements OnInit {
}
}
- showInfoDrawer() {
- this.infoDrawerVisible = !this.infoDrawerVisible;
+ showEditInfoModal() {
+ this.editInfoModalVisible = true;
+ this.editInfoFormGroup.patchValue(this.user);
+ }
+
+ modalConfirm() {
+ const desc = this.editInfoFormGroup.value.desc;
+ const displayName = this.editInfoFormGroup.value.displayName;
+ this.apiService.updateUserInfo(desc, displayName).subscribe({
+ next: data => {
+ this.messageService.success('修改信息成功')
+ this.gUserService.refreshUserInfo();
+ },
+ error: err => {
+ this.messageService.error(err.msg);
+ },
+ complete: null
+ });
+ this.editInfoModalVisible = false;
}
}
diff --git a/index/src/app/view/admin/admin.module.ts b/index/src/app/view/admin/admin.module.ts
index 7d62c4e..0ab942c 100644
--- a/index/src/app/view/admin/admin.module.ts
+++ b/index/src/app/view/admin/admin.module.ts
@@ -5,6 +5,7 @@ import {AdminComponent} from './admin.component';
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";
@NgModule({
@@ -16,7 +17,8 @@ import {AdminHeaderComponent} from '../../components/admin-header/admin-header.c
CommonModule,
AdminRoutingModule,
NgZorroAntdModule,
- NzSpaceModule
+ NzSpaceModule,
+ ReactiveFormsModule
]
})
export class AdminModule {