seimin 1 年之前
父節點
當前提交
0c1f2232ca
共有 3 個文件被更改,包括 22 次插入4 次删除
  1. 1 1
      proxy.conf.json
  2. 2 2
      src/app/app.component.ts
  3. 19 1
      src/app/views/login/login.component.ts

+ 1 - 1
proxy.conf.json

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "/service": {
3
-    "target": "http://192.168.3.108",
3
+    "target": "http://192.168.4.163",
4 4
     "logLevel": "debug",
5 5
     "changeOrigin": true,
6 6
     "pathRewrite": {

+ 2 - 2
src/app/app.component.ts

@@ -16,8 +16,8 @@ export class AppComponent {
16 16
     if(isHosIdLogin){
17 17
       // 登录页
18 18
       hosId = location.hash.replace(reg, '$1');
19
-    }else if(location.hash == '#/main/sysConfig' || location.hash == ''){
20
-      // 系统配置页
19
+    }else if(location.hash == '#/main/sysConfig' || location.hash == '' || location.href.includes("?")){
20
+      // 系统配置页||重定向前||单点登录
21 21
       hosId = '';
22 22
     }else{
23 23
       // 其他页面

+ 19 - 1
src/app/views/login/login.component.ts

@@ -1,5 +1,5 @@
1 1
 import { Component, OnInit } from "@angular/core";
2
-import { Router } from "@angular/router";
2
+import { Router, NavigationStart } from "@angular/router";
3 3
 import { FormBuilder, Validators, FormGroup } from "@angular/forms";
4 4
 import { NzMessageService } from "ng-zorro-antd/message";
5 5
 import { MainService } from "../../services/main.service";
@@ -19,6 +19,7 @@ export class LoginComponent implements OnInit {
19 19
   validateForm: FormGroup;
20 20
   loading: boolean = false; // 加载状态
21 21
   isSingleSignOn: boolean = false; // 是否单点登录
22
+  rooterChange
22 23
   constructor(
23 24
     private router: Router,
24 25
     private fb: FormBuilder,
@@ -28,12 +29,29 @@ export class LoginComponent implements OnInit {
28 29
     private titleService: Title,
29 30
     private markingService: MarkingService,
30 31
   ) {}
32
+  ngOnDestroy() {
33
+    if (this.rooterChange) {
34
+      this.rooterChange.unsubscribe();
35
+    }
36
+  }
31 37
   ngOnInit() {
32 38
     this.http = http;
33 39
     this.isSingleSignOn = location.href.includes("?");
34 40
     if (this.isSingleSignOn) {
35 41
       this.singleSignOn();
36 42
     } else {
43
+      this.rooterChange = this.router.events.subscribe(event => {
44
+        if(event instanceof NavigationStart) {
45
+          console.log(event, 'NavigationStart')
46
+          let reg = /^\/login\/?(\d*)$/;
47
+          let isHosIdLogin = reg.test(event.url);
48
+          console.log(isHosIdLogin)
49
+          if(isHosIdLogin){
50
+            // 登录页
51
+            location.reload(true);
52
+          }
53
+        }
54
+      })
37 55
       this.initForm();
38 56
     }
39 57
   }