Commit 09370c7e by niuxiaolin

添加登录功能

parent 7ddb1346
......@@ -37,5 +37,8 @@
</nz-form-control>
</nz-form-item>
<<nz-form-item *ngIf="error" nzFlex>
<label class="text-error">用户名或者密码出错!</label>
</nz-form-item>
</form>
</div>
\ No newline at end of file
......@@ -12,6 +12,9 @@ form{
background: #13151591;
padding: 2em;
}
.text-error{
color:red;
}
:host {
display: block;
margin: 0 auto;
......
......@@ -3,7 +3,7 @@ import { Component, OnDestroy, Inject, Optional, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpParams } from '@angular/common/http';
import { DefaultService } from '../api';
......@@ -17,6 +17,7 @@ import { DefaultService } from '../api';
})
export class LoginComponent implements OnInit {
validateForm: FormGroup;
error: boolean;
submitForm(): void {
for (const i in this.validateForm.controls) {
......@@ -24,7 +25,16 @@ export class LoginComponent implements OnInit {
this.validateForm.controls[i].updateValueAndValidity();
}
if(this.validateForm.valid){
this.http.post(this.s.basePath+"/user/login", this.validateForm.value).subscribe();
let urlParams:URLSearchParams = new URLSearchParams();
this.http.get(`${this.s.basePath}/user/login/${this.validateForm.value.userName}/${this.validateForm.value.password}`).subscribe(res=>{
if((res as any).code==1){
location.href = "./#/home";
}else{
this.error=true;
}
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment