Quellcode durchsuchen

优化login 前地址

李双才 vor 3 Jahren
Ursprung
Commit
005676f615

+ 14 - 3
src/app/core/services/auth.service.ts

@@ -68,9 +68,20 @@ export class AuthService {
     return oAuthSuccessEvent;
   }
 
-  async login() {
+
+  async isLoginedByUrl(url) {
+    const isLogin = await this.oauthService.hasValidAccessToken();
+
+    // return isLogin;
+    if (!isLogin) {
+      this.login(url);
+    }
+    return isLogin;
+  }
+
+  async login(url) {
     // 登录前先保存登录地址缓存
-    await this.stoage.setItem(this.loginBackKey, this.router.url);
+    await this.stoage.setItem(this.loginBackKey, url);
     // 登录前先跳转无需权限页面,比如登录等待界面
     this.router.navigateByUrl(this.loginRoute, { replaceUrl: true });
     if (this.platform.is('hybrid')) {
@@ -110,7 +121,7 @@ export class AuthService {
 
     // return isLogin;
     if (!isLogin) {
-      this.login();
+      this.login('');
     }
     return isLogin;
   }

+ 2 - 1
src/app/core/services/route-auth-guard.service.ts

@@ -15,7 +15,8 @@ export class RouteAuthGuardService implements CanActivate, CanActivateChild {
     return this.canActivate(childRoute, state);
   }
   canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
-    return this.authService.isLogined().then(isLogined => {
+    // 登录前先保存登录地址缓存
+    return this.authService.isLoginedByUrl(state.url).then(isLogined => {
       return isLogined;
     });
   }

+ 6 - 6
src/app/layout/user-profile/user-profile.component.html

@@ -4,7 +4,7 @@
   </ion-toolbar>
 </ion-header>
 <ion-content [fullscreen]="true">
-  <List>
+  <!-- <List>
     <ListItem [extra]="versionS"> 服务器版本: </ListItem>
     <ListItem [extra]="'version'"> 本地版本: </ListItem>
     <InputItem
@@ -12,7 +12,7 @@
       [labelNumber]="50"
       [(ngModel)]="updateS.serviceVersionInfoUrl"
     ></InputItem>
-  </List>
+  </List> -->
 
   <div id="container">
     <!-- <strong>Token: {{token}}</strong> -->
@@ -29,14 +29,14 @@
       <ion-label>更新服务器地址:</ion-label>
       <ion-input [(ngModel)]="updateS.serviceVersionInfoUrl"></ion-input>
     </ion-item>
-    <ion-item>
+    <!-- <ion-item>
       <ion-label>更新服务器地址:</ion-label>
       <ion-button (click)="login()">登录</ion-button>
-    </ion-item>
+    </ion-item> -->
 
-    <ion-item>
+    <!-- <ion-item>
       <ion-button (click)="login()">登录</ion-button>
-    </ion-item>
+    </ion-item> -->
     <ion-button (click)="loginOut()">退出</ion-button>
     <ion-button (click)="login()">登录</ion-button>
     <ion-button (click)="getversion()">版本检查</ion-button>

+ 1 - 1
src/app/layout/user-profile/user-profile.component.ts

@@ -29,7 +29,7 @@ export class UserProfileComponent implements OnInit {
   }
 
   async login() {
-    await this.auth.login();
+    await this.auth.login('');
   }
 
   async update() {