diff --git a/src/app/AbstractRoute.ts b/src/app/AbstractRoute.ts index fcafe99..50617d6 100644 --- a/src/app/AbstractRoute.ts +++ b/src/app/AbstractRoute.ts @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import {Observable} from 'rxjs'; -import {NavigationStart, Router} from '@angular/router'; +import {NavigationEnd, Router} from '@angular/router'; import {filter} from 'rxjs/operators'; import {environment} from '../environments/environment'; import {CookieService} from 'ngx-cookie-service'; @@ -14,26 +14,22 @@ import {RouteInterface} from './RouteInterface'; }) export class AbstractRoute { - // 登陆状态 - isLogin = false; - // 当前登陆账户 - managerName = null; - - navStart: Observable; + navStart: Observable; constructor( private router: Router, private cookieService: CookieService ) { this.navStart = router.events.pipe( - filter(evt => evt instanceof NavigationStart) - ) as Observable; + filter(evt => evt instanceof NavigationEnd) + ) as Observable; } - checkUser(routeInterface: RouteInterface): void { - this.isLogin = this.cookieService.check(environment.tokenKey); - this.managerName = this.cookieService.get(environment.managerKey); + isLogin(): boolean { + return this.cookieService.check(environment.tokenKey); + } - this.navStart.subscribe(evt => routeInterface.doNavigationStart(evt, this.isLogin, this.managerName)); + checkUser(routeInterface: RouteInterface): void { + this.navStart.subscribe(evt => routeInterface.doNavigationStart(evt, this.isLogin(), this.cookieService.get(environment.managerKey))); } } diff --git a/src/app/account/account/account.module.ts b/src/app/account/account/account.module.ts index 91e07e2..09152ff 100644 --- a/src/app/account/account/account.module.ts +++ b/src/app/account/account/account.module.ts @@ -8,9 +8,12 @@ import {RegisterComponent} from '../register/register.component'; import {ResetpwdComponent} from '../resetpwd/resetpwd.component'; import {TranslateModule} from '@ngx-translate/core'; import {RouterModule} from '@angular/router'; -import {ReactiveFormsModule} from '@angular/forms'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // 提示框组件 import {MessageComponent} from '../../message/message.component'; +import {ScoreComponent} from '../score/score.component'; +import {PageModule} from '../../page/page/page.module'; + // import {InputComponent} from '../../input/input.component'; @@ -18,12 +21,14 @@ import {MessageComponent} from '../../message/message.component'; * 账号管理模块 */ @NgModule({ - declarations: [LoginComponent, RegisterComponent, ResetpwdComponent, MessageComponent], + declarations: [LoginComponent, RegisterComponent, ResetpwdComponent, ScoreComponent, MessageComponent], imports: [ CommonModule, TranslateModule, RouterModule, ReactiveFormsModule, + FormsModule, + PageModule ] }) export class AccountModule { diff --git a/src/app/account/login/login.component.ts b/src/app/account/login/login.component.ts index 7f4891c..4af937b 100644 --- a/src/app/account/login/login.component.ts +++ b/src/app/account/login/login.component.ts @@ -7,6 +7,7 @@ import {Result} from '../../interface/Result'; import {environment} from '../../../environments/environment'; import {CookieService} from 'ngx-cookie-service'; import {MessageInterface, MessageUtil} from '../../message/message.service'; +import {AbstractRoute} from '../../AbstractRoute'; @Component({ selector: 'app-login', @@ -28,14 +29,12 @@ export class LoginComponent extends Commons implements OnInit, MessageInterface private router: Router, private loginService: LoginService, private cookieService: CookieService, - private messageUtil: MessageUtil - + private messageUtil: MessageUtil, + private abstractRoute: AbstractRoute ) { super(); } - ngOnInit(): void { - } // 登陆方法 login() { @@ -49,7 +48,7 @@ export class LoginComponent extends Commons implements OnInit, MessageInterface time.setTime(r.managerToken.useTime); this.cookieService.set(environment.managerKey, r.managerToken.managerName, time); this.cookieService.set(environment.tokenKey, r.managerToken.token, time); - location.href = '/forum'; + this.router.navigateByUrl('/forum'); } else { this.messageUtil.danger(this.prefix(r.message)); } @@ -57,6 +56,13 @@ export class LoginComponent extends Commons implements OnInit, MessageInterface } + + ngOnInit(): void { + if (this.abstractRoute.isLogin()) { + this.router.navigateByUrl('/forum'); + } + } + form(): FormGroup { return this.loginForm; } diff --git a/src/app/account/register/register.component.ts b/src/app/account/register/register.component.ts index ab0b6c1..85aaa1f 100644 --- a/src/app/account/register/register.component.ts +++ b/src/app/account/register/register.component.ts @@ -77,14 +77,9 @@ export class RegisterComponent extends Commons implements OnInit, MessageInterfa } ngOnInit(): void { - this.validForm = {}; - for (const key of Object.keys(this.registerForm.value)) { - this.validForm[key] = { - flag: false - }; - } } + form(): FormGroup { return this.registerForm; } diff --git a/src/app/account/resetpwd/resetpwd.component.ts b/src/app/account/resetpwd/resetpwd.component.ts index c2815d6..3c45867 100644 --- a/src/app/account/resetpwd/resetpwd.component.ts +++ b/src/app/account/resetpwd/resetpwd.component.ts @@ -49,11 +49,6 @@ export class ResetpwdComponent extends Commons implements OnInit, MessageInterfa super(); } - // - ngOnInit(): void { - - } - // 检查邮箱 checkEmail() { @@ -154,4 +149,7 @@ export class ResetpwdComponent extends Commons implements OnInit, MessageInterfa prefix(key: string): string { return 'server.resetpwd.' + key; } + + ngOnInit(): void { + } } diff --git a/src/app/account/score/score.component.html b/src/app/account/score/score.component.html new file mode 100644 index 0000000..5ec5134 --- /dev/null +++ b/src/app/account/score/score.component.html @@ -0,0 +1,110 @@ + +
+
+ +
+
+ {{ prefix('username') | translate }} +
+ + +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + +
{{prefix('username')|translate}}{{prefix('score')|translate}}{{prefix('action')|translate}}
{{user.username}}{{user.creditScore}} +
+ +
+
+ + +
+ + + diff --git a/src/app/account/score/score.component.scss b/src/app/account/score/score.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/account/score/score.component.spec.ts b/src/app/account/score/score.component.spec.ts new file mode 100644 index 0000000..d3a6c43 --- /dev/null +++ b/src/app/account/score/score.component.spec.ts @@ -0,0 +1,25 @@ +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; + +import {ScoreComponent} from './score.component'; + +describe('ScoreComponent', () => { + let component: ScoreComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ScoreComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ScoreComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/account/score/score.component.ts b/src/app/account/score/score.component.ts new file mode 100644 index 0000000..5373df1 --- /dev/null +++ b/src/app/account/score/score.component.ts @@ -0,0 +1,86 @@ +import {Component, OnInit} from '@angular/core'; +import {Commons} from '../../commons'; +import {FormBuilder, FormGroup, Validators} from '@angular/forms'; +import {ScoreService} from './score.service'; +import {MessageInterface, MessageUtil} from '../../message/message.service'; +import {Page} from '../../interface/Page'; +import {Info} from '../../interface/Info'; + +@Component({ + selector: 'app-score', + templateUrl: './score.component.html', + styleUrls: ['./score.component.scss'] +}) +export class ScoreComponent extends Commons implements OnInit, MessageInterface { + + scoreFrom = this.fb.group({ + // 用户名 + username: this.fb.control('', [Validators.required]), + // 是否模糊查询 + like: this.fb.control(true, [Validators.required]), + }); + + editForm = this.fb.group({ + // 用户名 + username: this.fb.control('', [Validators.required]), + // 修改分数 + score: this.fb.control('', [Validators.required]), + // 用户分数 + beforeScore: this.fb.control('', [Validators.required]), + // 备注信息 + notes: this.fb.control('', [Validators.required]), + }); + + currentPage = 1; + + constructor( + private fb: FormBuilder, + private scoreService: ScoreService, + private messageUtil: MessageUtil + ) { + super(); + } + + // 用户信息 + users: Page; + + // 加载用户信息 + loadAll($currentPage) { + this.currentPage = $currentPage; + this.scoreService.loadAll(Object.assign(this.scoreFrom.value, {currentPage: $currentPage})) + .subscribe(res => { + // this.messageUtil.alert(this.prefix(res.message)); + this.users = res.myInfos; + }); + } + + // 修改信用分 + editScore() { + this.scoreService.editScore(this.editForm.value).subscribe( + res => { + this.editForm.reset(); + this.messageUtil.alert(this.prefix(res.message)); + this.loadAll(1); + } + ); + } + + ngOnInit(): void { + this.loadAll(this.currentPage); + } + + prefix(key: string): string { + return 'score.' + key; + } + + changePage() { + if (this.currentPage > this.users.totalPage) { + this.currentPage = this.users.currentPage; + } + } + + form(): FormGroup { + return this.scoreFrom; + } + +} diff --git a/src/app/account/score/score.service.spec.ts b/src/app/account/score/score.service.spec.ts new file mode 100644 index 0000000..e71f469 --- /dev/null +++ b/src/app/account/score/score.service.spec.ts @@ -0,0 +1,16 @@ +import {TestBed} from '@angular/core/testing'; + +import {ScoreService} from './score.service'; + +describe('ScoreService', () => { + let service: ScoreService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ScoreService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/account/score/score.service.ts b/src/app/account/score/score.service.ts new file mode 100644 index 0000000..169f512 --- /dev/null +++ b/src/app/account/score/score.service.ts @@ -0,0 +1,36 @@ +import {Injectable} from '@angular/core'; +import {JSONRequest} from '../../interface/JSONRequest'; +import {Observable} from 'rxjs'; +import {UserResponse} from '../../interface/Response'; +import {HttpClient} from '@angular/common/http'; +import {HttpInterface} from '../../interface/HttpInterface'; +import {catchError} from 'rxjs/operators'; + +/** + * 信用分管理服务 + */ +@Injectable({ + providedIn: 'root' +}) +export class ScoreService extends JSONRequest { + + constructor(private http: HttpClient) { + super(); + } + + // 加载所有用户 + loadAll(body): Observable { + return this.http.get(HttpInterface.user, Object.assign(this.httpOptions, { + params: body + })).pipe( + catchError(this.handleError('加载访客信息')) + ); + } + + // 修改信用分 + editScore(body): Observable { + return this.http.post(HttpInterface.score, body, this.httpOptions).pipe( + catchError(this.handleError('修改信用分')) + ); + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 83b0420..c44f01f 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -6,6 +6,7 @@ import {ResetpwdComponent} from './account/resetpwd/resetpwd.component'; import {ForumComponent} from './forum/forum/forum.component'; import {NoticeComponent} from './forum/notice/notice.component'; import {VisitorComponent} from './visitor/visitor/visitor.component'; +import {ScoreComponent} from './account/score/score.component'; // 路由配置 export const routes: Routes = [ @@ -21,6 +22,8 @@ export const routes: Routes = [ {path: 'notice', component: NoticeComponent}, // 访客管理 {path: 'visitor', component: VisitorComponent}, + // 信用分管理 + {path: 'score', component: ScoreComponent}, // 自动重定向到登陆 {path: '', redirectTo: 'login', pathMatch: 'full'} ]; diff --git a/src/app/app.component.html b/src/app/app.component.html index 8e30e90..b5c0ce5 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,25 +1,36 @@ -