From efe936a73370a55d4c3336fb9973a92fcf87efff Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Thu, 08 Mar 2018 09:22:09 +0800
Subject: [PATCH] ts语法修正,报表部分功能实现

---
 src/app/routes/passport/login/login.component.ts |   61 ++++++++++++++++++++----------
 1 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/src/app/routes/passport/login/login.component.ts b/src/app/routes/passport/login/login.component.ts
index 678152b..a793455 100644
--- a/src/app/routes/passport/login/login.component.ts
+++ b/src/app/routes/passport/login/login.component.ts
@@ -1,16 +1,21 @@
+import { error } from 'selenium-webdriver';
+import { HttpErrorResponse } from '@angular/common/http';
+import { Authorization } from '@business/entity/token';
+import { LoginService } from '@business/services/http/login.service';
 import { SettingsService } from '@delon/theme';
-import { Component, OnDestroy, Inject } from '@angular/core';
+import { Component, OnDestroy, Inject, Optional } from '@angular/core';
 import { Router } from '@angular/router';
 import { FormGroup, FormBuilder, Validators } from '@angular/forms';
 import { NzMessageService } from 'ng-zorro-antd';
 import { SocialService, SocialOpenType, ITokenService, DA_SERVICE_TOKEN } from '@delon/auth';
+import { ReuseTabService } from '@delon/abc';
 import { environment } from '@env/environment';
-
+import { CookieService } from 'angular2-cookie/services/cookies.service';
 @Component({
     selector: 'passport-login',
     templateUrl: './login.component.html',
     styleUrls: [ './login.component.less' ],
-    providers: [ SocialService ]
+    providers: [ SocialService, CookieService]
 })
 export class UserLoginComponent implements OnDestroy {
 
@@ -25,6 +30,8 @@
         public msg: NzMessageService,
         private settingsService: SettingsService,
         private socialService: SocialService,
+        @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService,
+        private loginService: LoginService,
         @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) {
         this.form = fb.group({
             userName: [null, [Validators.required, Validators.minLength(5)]],
@@ -33,6 +40,8 @@
             captcha: [null, [Validators.required]],
             remember: [true]
         });
+        // let nowTime = new Date();
+        // nowTime.setDate(nowTime.getDate()+1);
     }
 
     // region: fields
@@ -75,28 +84,38 @@
             this.captcha.markAsDirty();
             if (this.mobile.invalid || this.captcha.invalid) return;
         }
-        // mock http
         this.loading = true;
-        setTimeout(() => {
-            this.loading = false;
-            if (this.type === 0) {
-                if (this.userName.value !== 'admin' || this.password.value !== '123456') {
-                    this.error = `���������������������`;
-                    return;
+            this.loginService.validate(this.userName.value, this.password.value).subscribe(
+                (res: Authorization) => {
+                   if (res.token != null) {
+                        // ������������������������
+                       this.reuseTabService.clear();
+                       this.tokenService.set({
+                           token: res.token,
+                           name: this.userName.value,
+                           time: +new Date
+                       });
+                       this.validateError = {};
+                       this.router.navigate(['/']);
+                   }
+                },
+                (err: HttpErrorResponse) => {                    
+                    if (!!err) {
+                        const errMsg = err.error;
+                        console.log(errMsg);
+                        if (errMsg.status === 401 && errMsg.errorCode === 10) {                                
+                            this.validateError['password_incorrect'] = true;
+                            this.loading = false;
+                       } else if (errMsg.status === 401 && errMsg.errorCode === 12) {
+                           this.validateError['account_expired'] = true;
+                           this.loading = false;
+                       }
+                    }                  
                 }
-            }
+           );
 
-            this.tokenService.set({
-                token: '123456789',
-                name: this.userName.value,
-                email: `cipchk@qq.com`,
-                id: 10000,
-                time: +new Date
-            });
-            this.router.navigate(['/']);
-        }, 1000);
     }
-
+    public validateError: {[s: string]: boolean} = {};
     // region: social
 
     open(type: string, openType: SocialOpenType = 'href') {

--
Gitblit v1.8.0