From a508224d5995f3e0daf8977adf48047ea9aab9c1 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Fri, 21 Feb 2020 06:17:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86/=E6=B3=A8=E5=86=8C=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular.json | 3 +- package.json | 1 + src/app/account/login/login.component.html | 15 ++++++--- src/app/account/login/login.component.ts | 23 ++++++++++---- .../account/register/register.component.html | 15 ++++++--- .../account/register/register.component.ts | 10 ++++-- .../account/resetpwd/resetpwd.component.html | 2 +- .../account/resetpwd/resetpwd.component.ts | 4 +-- src/app/app.component.ts | 31 ++----------------- src/app/app.module.ts | 4 +-- src/app/commons.ts | 21 +++++++++++++ src/app/height.ts | 4 --- 12 files changed, 77 insertions(+), 56 deletions(-) create mode 100644 src/app/commons.ts delete mode 100644 src/app/height.ts diff --git a/angular.json b/angular.json index 8753b78..78118bd 100644 --- a/angular.json +++ b/angular.json @@ -33,7 +33,8 @@ "scripts": [ "node_modules/jquery/dist/jquery.js", "node_modules/popper.js/dist/umd/popper.js", - "node_modules/bootstrap/dist/js/bootstrap.js" + "node_modules/bootstrap/dist/js/bootstrap.js", + "node_modules" ] }, "configurations": { diff --git a/package.json b/package.json index 541f92b..acfb681 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@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", "popper.js": "^1.16.1", diff --git a/src/app/account/login/login.component.html b/src/app/account/login/login.component.html index a1a768c..14d402c 100644 --- a/src/app/account/login/login.component.html +++ b/src/app/account/login/login.component.html @@ -7,7 +7,7 @@
{{ 'login.manager_name' | translate }}
- + @@ -15,7 +15,7 @@
{{ 'login.password' | translate }}
- +
@@ -23,11 +23,18 @@ -
+
- + +
+ +
+
{{message}}
+
diff --git a/src/app/account/login/login.component.ts b/src/app/account/login/login.component.ts index ffac637..b77bffe 100644 --- a/src/app/account/login/login.component.ts +++ b/src/app/account/login/login.component.ts @@ -1,21 +1,23 @@ import {Component, OnInit} from '@angular/core'; import {FormBuilder} from '@angular/forms'; -import {Height} from '../../height'; - +import {Commons} from '../../commons'; +import {Router} from '@angular/router'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.scss'] }) // 登陆模块 -export class LoginComponent extends Height implements OnInit { +export class LoginComponent extends Commons implements OnInit { // 登陆表单 loginForm = this.fb.group({ managerName: [''], password: [''] }); - constructor(private fb: FormBuilder) { + + + constructor(private fb: FormBuilder,private router: Router) { super(); } @@ -25,8 +27,17 @@ export class LoginComponent extends Height implements OnInit { // 登陆方法 login() { console.debug(this.loginForm.value); - alert('执行登陆操作'); - } + 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'; + } + }); + } } diff --git a/src/app/account/register/register.component.html b/src/app/account/register/register.component.html index 2923632..c668d71 100644 --- a/src/app/account/register/register.component.html +++ b/src/app/account/register/register.component.html @@ -15,7 +15,7 @@
{{ 'login.password' | translate }}
- + @@ -24,7 +24,7 @@
{{ 'register.confirm_pwd' | translate }}
- + @@ -43,12 +43,19 @@ -
+
+ class="btn btn-info btn-lg ml-3">{{ 'button.backLogin' | translate }} +
+ +
+
{{message}}
+
diff --git a/src/app/account/register/register.component.ts b/src/app/account/register/register.component.ts index 6d07bfd..bd8f345 100644 --- a/src/app/account/register/register.component.ts +++ b/src/app/account/register/register.component.ts @@ -1,13 +1,13 @@ import { Component, OnInit } from '@angular/core'; import {FormBuilder} from '@angular/forms'; -import {Height} from '../../height'; +import {Commons} from '../../commons'; @Component({ selector: 'app-register', templateUrl: './register.component.html', styleUrls: ['./register.component.scss'] }) // 注册模块 -export class RegisterComponent extends Height implements OnInit { +export class RegisterComponent extends Commons implements OnInit { // 注册表单 registerForm = this.fb.group({ managerName: [], @@ -25,6 +25,10 @@ export class RegisterComponent extends Height implements OnInit { } register() { - alert('确认注册'); + 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'); + }); } } diff --git a/src/app/account/resetpwd/resetpwd.component.html b/src/app/account/resetpwd/resetpwd.component.html index 923289d..e09b382 100644 --- a/src/app/account/resetpwd/resetpwd.component.html +++ b/src/app/account/resetpwd/resetpwd.component.html @@ -33,7 +33,7 @@ + class="btn btn-info btn-lg ml-3">{{ 'button.backLogin' | translate }}
diff --git a/src/app/account/resetpwd/resetpwd.component.ts b/src/app/account/resetpwd/resetpwd.component.ts index d101ba6..efc288a 100644 --- a/src/app/account/resetpwd/resetpwd.component.ts +++ b/src/app/account/resetpwd/resetpwd.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder } from '@angular/forms'; -import {Height} from '../../height'; +import {Commons} from '../../commons'; @Component({ selector: 'app-resetpwd', @@ -8,7 +8,7 @@ import {Height} from '../../height'; styleUrls: ['./resetpwd.component.scss'] }) // 重置密码模块 -export class ResetpwdComponent extends Height implements OnInit { +export class ResetpwdComponent extends Commons implements OnInit { // 重置密码表单 resetForm = this.fb.group({ diff --git a/src/app/app.component.ts b/src/app/app.component.ts index d2e75da..de11fab 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,8 +1,7 @@ import {Component} from '@angular/core'; -import {Router, ActivatedRoute, NavigationStart} from '@angular/router'; +import {Router, ActivatedRoute} from '@angular/router'; import {TranslateService} from '@ngx-translate/core'; -import { filter } from 'rxjs/operators'; -import { Observable } from 'rxjs-compat'; + @Component({ selector: 'app-root', templateUrl: './app.component.html', @@ -13,13 +12,8 @@ export class AppComponent { // 登陆状态 isLogin; - navStart: Observable; constructor(public route: ActivatedRoute, public translate: TranslateService, private router: Router) { - // 导航开始事件 - this.navStart = this.router.events.pipe( - filter(evt => evt instanceof NavigationStart) - ) as Observable; } public async ngOnInit() { @@ -30,27 +24,6 @@ export class AppComponent { this.translate.use(currentLanguage); // 记录当前设置的语言 localStorage.setItem('currentLanguage', currentLanguage); - - // const that = this; - // this.navStart.subscribe(evt => { - // if ( evt.url !== '/login') { - // // 检查登陆状态 - // this.checkLogin(that); - // } - // }); - - this.checkLogin(); } - /** - * 检查登陆状态 - */ - checkLogin() { - this.isLogin = true; - if (this.isLogin) { - this.router.navigateByUrl('/forum'); - } else { - this.router.navigateByUrl('/login'); - } - } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2497ada..58f71cd 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,7 +6,7 @@ import {AppRoutingModule} from './app-routing.module'; import {AppComponent} from './app.component'; // 登陆 import {LoginComponent} from './account/login/login.component'; - +import { CookieService } from 'ngx-cookie-service'; // 响应式表单 import {ReactiveFormsModule} from '@angular/forms'; // 国际化支持 @@ -41,7 +41,7 @@ export function HttpLoaderFactory(http: HttpClient) { } }) ], - providers: [], + providers: [CookieService], bootstrap: [AppComponent] }) export class AppModule { diff --git a/src/app/commons.ts b/src/app/commons.ts new file mode 100644 index 0000000..c079d5c --- /dev/null +++ b/src/app/commons.ts @@ -0,0 +1,21 @@ +export class Commons { + // 页面高度=屏幕的高度/2 + height = 'height:' + screen.height / 2 + 'px'; + + message = null; + messageStyle = 'warning'; + + // 清空警告信息 + clearError() { + this.message = null; + } + + // post请求 + request(url, b, res) { + const header = new Headers(); + header.append('Content-Type', 'application/json'); + const req = new Request(url, + {method: 'POST', body: b, headers: header}); + fetch(req).then(r => r.json()).then(res); + } +} diff --git a/src/app/height.ts b/src/app/height.ts deleted file mode 100644 index 675896b..0000000 --- a/src/app/height.ts +++ /dev/null @@ -1,4 +0,0 @@ -export class Height { - // 页面高度=屏幕的高度/2 - height = 'height:' + screen.height / 2 + 'px'; -}