From 2d788991b3ba1e0a1533dc7917bdf140030102c6 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sat, 29 Feb 2020 01:56:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E8=B4=A6=E5=8F=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E8=AE=BA=E5=9D=9B=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=99=BB=E9=99=86=E6=B3=A8=E5=86=8C=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新接口地址环境变量 --- package.json | 4 +- src/app/account/account/account.module.ts | 20 +++++ src/app/account/login/login.component.html | 29 +++--- src/app/account/login/login.component.spec.ts | 8 +- src/app/account/login/login.component.ts | 23 +++-- src/app/account/login/login.service.spec.ts | 16 ++++ src/app/account/login/login.service.ts | 59 ++++++++++++ .../account/register/register.component.html | 34 +++---- .../register/register.component.spec.ts | 8 +- .../account/register/register.component.ts | 27 +++--- .../account/register/register.service.spec.ts | 16 ++++ src/app/account/register/register.service.ts | 22 +++++ .../account/resetpwd/resetpwd.component.html | 24 +++-- .../resetpwd/resetpwd.component.spec.ts | 8 +- .../account/resetpwd/resetpwd.component.ts | 11 ++- src/app/app-routing.module.ts | 11 ++- src/app/app.component.html | 3 +- src/app/app.component.spec.ts | 6 +- src/app/app.component.ts | 37 +++++++- src/app/app.module.ts | 30 ++++--- src/app/commons.ts | 23 ++--- src/app/error/error.component.html | 1 + src/app/error/error.component.scss | 0 src/app/error/error.component.spec.ts | 25 ++++++ src/app/error/error.component.ts | 18 ++++ src/app/forum/forum.component.html | 89 ++++++++++--------- src/app/forum/forum.component.scss | 42 +++++---- src/app/forum/forum.component.spec.ts | 8 +- src/app/forum/forum.component.ts | 5 +- src/app/forum/forum/forum.module.ts | 16 ++++ src/app/interface/Http.ts | 5 ++ src/app/message/Message.ts | 26 ++++++ src/app/message/message.component.html | 7 ++ src/app/message/message.component.scss | 0 src/app/message/message.component.spec.ts | 25 ++++++ src/app/message/message.component.ts | 22 +++++ src/app/message/message.service.spec.ts | 16 ++++ src/app/message/message.service.ts | 48 ++++++++++ src/environments/environment.prod.ts | 6 +- src/environments/environment.ts | 7 +- yarn.lock | 76 +++------------- 41 files changed, 616 insertions(+), 245 deletions(-) create mode 100644 src/app/account/account/account.module.ts create mode 100644 src/app/account/login/login.service.spec.ts create mode 100644 src/app/account/login/login.service.ts create mode 100644 src/app/account/register/register.service.spec.ts create mode 100644 src/app/account/register/register.service.ts create mode 100644 src/app/error/error.component.html create mode 100644 src/app/error/error.component.scss create mode 100644 src/app/error/error.component.spec.ts create mode 100644 src/app/error/error.component.ts create mode 100644 src/app/forum/forum/forum.module.ts create mode 100644 src/app/interface/Http.ts create mode 100644 src/app/message/Message.ts create mode 100644 src/app/message/message.component.html create mode 100644 src/app/message/message.component.scss create mode 100644 src/app/message/message.component.spec.ts create mode 100644 src/app/message/message.component.ts create mode 100644 src/app/message/message.service.spec.ts create mode 100644 src/app/message/message.service.ts diff --git a/package.json b/package.json index acfb681..9a1f5f4 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "@ng-bootstrap/ng-bootstrap": "^6.0.0-rc.0", "@ngx-translate/core": "^12.1.1", "@ngx-translate/http-loader": "^4.0.0", - "angular2-cookie": "^1.2.6", "bootstrap": "^4.4.1", "jquery": "^3.4.1", + "ngx-cookie-service": "^2.3.0", "popper.js": "^1.16.1", "rxjs": "~6.5.4", "rxjs-compat": "^6.5.4", @@ -37,9 +37,9 @@ "@angular/cli": "~9.0.1", "@angular/compiler-cli": "~9.0.0", "@angular/language-service": "~9.0.0", - "@types/node": "^12.11.1", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", + "@types/node": "^12.11.1", "codelyzer": "^5.1.2", "jasmine-core": "~3.5.0", "jasmine-spec-reporter": "~4.2.1", diff --git a/src/app/account/account/account.module.ts b/src/app/account/account/account.module.ts new file mode 100644 index 0000000..09f9c52 --- /dev/null +++ b/src/app/account/account/account.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +// 登陆组件 +import {LoginComponent} from '../login/login.component'; +// 注册组件 +import {RegisterComponent} from '../register/register.component'; +// 重置密码组件 +import {ResetpwdComponent} from '../resetpwd/resetpwd.component'; + + +/** + * 账号管理模块 + */ +@NgModule({ + declarations: [LoginComponent, RegisterComponent, ResetpwdComponent], + imports: [ + CommonModule + ] +}) +export class AccountModule { } diff --git a/src/app/account/login/login.component.html b/src/app/account/login/login.component.html index 14d402c..df5a7b5 100644 --- a/src/app/account/login/login.component.html +++ b/src/app/account/login/login.component.html @@ -2,39 +2,38 @@
- +
{{ 'login.manager_name' | translate }}
- +
- +
{{ 'login.password' | translate }}
- +
- +
-
- + - - + +
-
-
{{message}}
- -
+ +
diff --git a/src/app/account/login/login.component.spec.ts b/src/app/account/login/login.component.spec.ts index d6d85a8..28a5704 100644 --- a/src/app/account/login/login.component.spec.ts +++ b/src/app/account/login/login.component.spec.ts @@ -1,6 +1,6 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; -import { LoginComponent } from './login.component'; +import {LoginComponent} from './login.component'; describe('LoginComponent', () => { let component: LoginComponent; @@ -8,9 +8,9 @@ describe('LoginComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ LoginComponent ] + declarations: [LoginComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/account/login/login.component.ts b/src/app/account/login/login.component.ts index b77bffe..9c7b6de 100644 --- a/src/app/account/login/login.component.ts +++ b/src/app/account/login/login.component.ts @@ -2,6 +2,8 @@ import {Component, OnInit} from '@angular/core'; import {FormBuilder} from '@angular/forms'; import {Commons} from '../../commons'; import {Router} from '@angular/router'; +import {LoginService} from './login.service'; + @Component({ selector: 'app-login', templateUrl: './login.component.html', @@ -16,28 +18,25 @@ export class LoginComponent extends Commons implements OnInit { }); - - constructor(private fb: FormBuilder,private router: Router) { + constructor(private fb: FormBuilder, private router: Router, private loginService: LoginService) { super(); } ngOnInit(): void { + } // 登陆方法 login() { console.debug(this.loginForm.value); - this.request('http://localhost:8080/api/manager/login', JSON.stringify(this.loginForm.value), - res => { - this.message = res.message; - if (res.result === 'OK') { - this.messageStyle = 'info'; - this.router.navigateByUrl('/forum'); - } else { - this.messageStyle = 'warning'; - } - }); + // 发送登陆请求 + if (this.loginService.checkToken()) { + this.router.navigateByUrl('/forum'); + } else { + this.loginService.request(JSON.stringify(this.loginForm.value)); + } + } } diff --git a/src/app/account/login/login.service.spec.ts b/src/app/account/login/login.service.spec.ts new file mode 100644 index 0000000..ce2c842 --- /dev/null +++ b/src/app/account/login/login.service.spec.ts @@ -0,0 +1,16 @@ +import {TestBed} from '@angular/core/testing'; + +import {LoginService} from './login.service'; + +describe('LoginService', () => { + let service: LoginService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(LoginService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/account/login/login.service.ts b/src/app/account/login/login.service.ts new file mode 100644 index 0000000..9a5a259 --- /dev/null +++ b/src/app/account/login/login.service.ts @@ -0,0 +1,59 @@ +import {Injectable} from '@angular/core'; +import {CookieService} from 'ngx-cookie-service'; +import {Router} from '@angular/router'; +import {HttpInterface} from '../../interface/Http'; +import {MessageService} from '../../message/message.service'; + +@Injectable({ + providedIn: 'root' +}) +export class LoginService implements HttpInterface { + + constructor( + private cookieService: CookieService, + private router: Router, + private messageService: MessageService + ) { + } + + /** + * 检查登陆令牌是否有效 + */ + checkToken(): boolean { + return false; + } + + /** + * 登陆 + */ + login(body: string) { + if (this.checkToken()) { + this.router.navigateByUrl('/forum'); + } else { + this.request(body); + } + } + + /** + * + * @param body 请求表单 + */ + request(body: string) { + // res => { + // this.message = res.message; + // if (res.result === 'OK') { + // this.messageStyle = 'info'; + // this.cookieService.set(environment.tokenKey, res.body.token, 3600); + // this.router.navigateByUrl('/forum'); + // } else { + // this.messageStyle = 'warning'; + // } + // } + this.messageService.danger('登陆失败'); + return false; + } + + url(): string { + return '/api/manager/login'; + } +} diff --git a/src/app/account/register/register.component.html b/src/app/account/register/register.component.html index bf0db5b..6b23b3d 100644 --- a/src/app/account/register/register.component.html +++ b/src/app/account/register/register.component.html @@ -7,7 +7,8 @@
{{ 'login.manager_name' | translate }}
- + @@ -15,48 +16,49 @@
{{ 'login.password' | translate }}
- + - +
{{ 'register.confirm_pwd' | translate }}
- +
- +
{{ 'register.mobile' | translate }}
- +
- +
{{ 'register.email' | translate }}
- +
- + -
-
-
{{message}}
- -
+ diff --git a/src/app/account/register/register.component.spec.ts b/src/app/account/register/register.component.spec.ts index 6c19551..782d69a 100644 --- a/src/app/account/register/register.component.spec.ts +++ b/src/app/account/register/register.component.spec.ts @@ -1,6 +1,6 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; -import { RegisterComponent } from './register.component'; +import {RegisterComponent} from './register.component'; describe('RegisterComponent', () => { let component: RegisterComponent; @@ -8,9 +8,9 @@ describe('RegisterComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ RegisterComponent ] + declarations: [RegisterComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/account/register/register.component.ts b/src/app/account/register/register.component.ts index 65fe9d6..86c6285 100644 --- a/src/app/account/register/register.component.ts +++ b/src/app/account/register/register.component.ts @@ -1,6 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; import {FormBuilder} from '@angular/forms'; import {Commons} from '../../commons'; +import {Router} from '@angular/router'; +import {RegisterService} from './register.service'; + @Component({ selector: 'app-register', templateUrl: './register.component.html', @@ -10,14 +13,18 @@ import {Commons} from '../../commons'; export class RegisterComponent extends Commons implements OnInit { // 注册表单 registerForm = this.fb.group({ - managerName: [], - password: [], - confirmPassword: [], - mobile: [], - email: [] + managerName: [], + password: [], + confirmPassword: [], + mobile: [], + email: [] }); - constructor(private fb: FormBuilder) { + constructor( + private fb: FormBuilder, + private router: Router, + private registerService: RegisterService + ) { super(); } @@ -25,10 +32,6 @@ export class RegisterComponent extends Commons implements OnInit { } register() { - this.request('http://localhost:8080/api/manager/register', JSON.stringify(this.registerForm.value), - res => { - this.message = res.message; - this.messageStyle = (res.result === 'OK' ? 'info' : 'warning'); - }); + this.registerService.register(JSON.stringify(this.registerForm.value)); } } diff --git a/src/app/account/register/register.service.spec.ts b/src/app/account/register/register.service.spec.ts new file mode 100644 index 0000000..2ba3960 --- /dev/null +++ b/src/app/account/register/register.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { RegisterService } from './register.service'; + +describe('RegisterService', () => { + let service: RegisterService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(RegisterService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/account/register/register.service.ts b/src/app/account/register/register.service.ts new file mode 100644 index 0000000..bae472c --- /dev/null +++ b/src/app/account/register/register.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@angular/core'; +import {HttpInterface} from '../../interface/Http'; + +@Injectable({ + providedIn: 'root' +}) +export class RegisterService implements HttpInterface { + + constructor() { } + + /** + * + * @param body 注册表单 + */ + register(body: string) { + + } + + url(): string { + return '/api/manager/register'; + } +} diff --git a/src/app/account/resetpwd/resetpwd.component.html b/src/app/account/resetpwd/resetpwd.component.html index e09b382..bc67666 100644 --- a/src/app/account/resetpwd/resetpwd.component.html +++ b/src/app/account/resetpwd/resetpwd.component.html @@ -1,38 +1,44 @@
- +
{{ 'login.manager_name' | translate }}
- +
- +
{{ 'register.email' | translate }}
- +
- +
- +
{{ 'reset_pwd.code' | translate }}
- +
- + -
diff --git a/src/app/account/resetpwd/resetpwd.component.spec.ts b/src/app/account/resetpwd/resetpwd.component.spec.ts index cbd3f27..1895f6c 100644 --- a/src/app/account/resetpwd/resetpwd.component.spec.ts +++ b/src/app/account/resetpwd/resetpwd.component.spec.ts @@ -1,6 +1,6 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; -import { ResetpwdComponent } from './resetpwd.component'; +import {ResetpwdComponent} from './resetpwd.component'; describe('ResetpwdComponent', () => { let component: ResetpwdComponent; @@ -8,9 +8,9 @@ describe('ResetpwdComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ResetpwdComponent ] + declarations: [ResetpwdComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/account/resetpwd/resetpwd.component.ts b/src/app/account/resetpwd/resetpwd.component.ts index efc288a..9b70aec 100644 --- a/src/app/account/resetpwd/resetpwd.component.ts +++ b/src/app/account/resetpwd/resetpwd.component.ts @@ -1,5 +1,5 @@ -import { Component, OnInit } from '@angular/core'; -import { FormBuilder } from '@angular/forms'; +import {Component, OnInit} from '@angular/core'; +import {FormBuilder} from '@angular/forms'; import {Commons} from '../../commons'; @Component({ @@ -21,14 +21,17 @@ export class ResetpwdComponent extends Commons implements OnInit { super(); } + // ngOnInit(): void { } - sendCode(){ + // 发送验证码 + sendCode() { alert('发送验证码'); } - resetPwd(){ + // 重置密码 + resetPwd() { alert('重置密码'); } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 4996507..094b299 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,5 +1,5 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; import {LoginComponent} from './account/login/login.component'; import {RegisterComponent} from './account/register/register.component'; import {ResetpwdComponent} from './account/resetpwd/resetpwd.component'; @@ -14,11 +14,14 @@ export const routes: Routes = [ // 重置密码 {path: 'reset_pwd', component: ResetpwdComponent}, // 论坛管理' - {path: 'forum', component: ForumComponent} + {path: 'forum', component: ForumComponent}, + // 自动重定向到登陆 + {path: '', redirectTo: 'login', pathMatch: 'full'} ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) -export class AppRoutingModule { } +export class AppRoutingModule { +} diff --git a/src/app/app.component.html b/src/app/app.component.html index 48930ef..1da7f88 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -6,7 +6,8 @@ {{ 'forum.name' | translate }}