From 309d1f9d649daa08bb9b068af014749f6d4a5bce Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Fri, 06 Jul 2018 14:00:45 +0800
Subject: [PATCH] 设备和监控点父页面 筛选条件不予 编辑页面联动

---
 src/app/routes/passport/login/login.component.ts |   59 +++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/src/app/routes/passport/login/login.component.ts b/src/app/routes/passport/login/login.component.ts
index 41331e2..f0ee060 100644
--- a/src/app/routes/passport/login/login.component.ts
+++ b/src/app/routes/passport/login/login.component.ts
@@ -1,17 +1,22 @@
+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 { 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';
+import { debounce } from 'rxjs/operators';
 @Component({
     selector: 'passport-login',
     templateUrl: './login.component.html',
     styleUrls: [ './login.component.less' ],
-    providers: [ SocialService]
+    providers: [ SocialService, CookieService]
 })
 export class UserLoginComponent implements OnDestroy {
 
@@ -26,7 +31,8 @@
         public msg: NzMessageService,
         private settingsService: SettingsService,
         private socialService: SocialService,
-        private loginService:LoginService,
+        @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)]],
@@ -35,6 +41,8 @@
             captcha: [null, [Validators.required]],
             remember: [true]
         });
+        // let nowTime = new Date();
+        // nowTime.setDate(nowTime.getDate()+1);
     }
 
     // region: fields
@@ -78,36 +86,43 @@
             if (this.mobile.invalid || this.captcha.invalid) return;
         }
         this.loading = true;
-            this.loginService.validate(this.userName.value,this.password.value).subscribe(
-                (res:Authorization) => {
-                   if(res.token!=null){
+        this.loginService.validate(this.userName.value, this.password.value).subscribe(
+                (res: Authorization) => {
+                    this.validateError['password_incorrect'] = false;
+                    this.validateError['account_expired'] = false;
+                    this.validateError['server_offline'] = false;
+                   if (res.token != null) {
+                        // ������������������������
+                       this.reuseTabService.clear();
                        this.tokenService.set({
                            token: res.token,
                            name: this.userName.value,
                            time: +new Date
                        });
-                       this.validateError = true;
+                       this.validateError = {};
                        this.router.navigate(['/']);
                    }
                 },
-                (err) => {
-                    console.log(err);
-                    if(err instanceof ProgressEvent){
-                        const error = <ProgressEvent>err;
-                        let xmlHttp = error.target;
-                        if(xmlHttp instanceof XMLHttpRequest){
-                            const xmlHttpRequest = <XMLHttpRequest> xmlHttp;
-                            if(xmlHttpRequest.status == 401){
-                                 this.validateError = true;
-                                 this.loading = false;
-                            }
-                        }
-                    }
+                (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;
+                       } else if (!errMsg.status  && !errMsg.errorCode) {
+                           this.validateError['server_offline'] = true;
+                           this.loading = false;
+                       }
+                    }                  
                 }
            );
 
     }
-    public validateError:boolean;
+    public validateError: {[s: string]: boolean} = {};
     // region: social
 
     open(type: string, openType: SocialOpenType = 'href') {

--
Gitblit v1.8.0