Pārlūkot izejas kodu

feat:router guard

0210225 4 mēneši atpakaļ
vecāks
revīzija
7e45c3f1cd
2 mainītis faili ar 29 papildinājumiem un 10 dzēšanām
  1. 10 4
      src/app/tab1/tab1.page.html
  2. 19 6
      src/app/tab1/tab1.page.ts

+ 10 - 4
src/app/tab1/tab1.page.html

@@ -16,8 +16,14 @@
     <!-- Banner横幅图片 -->
     
     <!-- <ion-img src="assets/img/banner.jpg"></ion-img> -->
-
-    <ion-card (click)="navigateTo('模拟面试')"routerLink="/ai/chat">
+    <ion-alert
+      [isOpen]="!user"
+      header="用户未登录"
+      subHeader="亲爱的用户"
+      message="请先登录"
+      [buttons]="ok"
+    ></ion-alert>
+    <ion-card *ngIf="user" (click)="navigateTo('模拟面试')"routerLink="/ai/chat">
       <ion-card-header>
         <ion-card-title>模拟面试</ion-card-title>
       </ion-card-header>
@@ -26,7 +32,7 @@
       </ion-card-content>
     </ion-card>
     <!-- MBTI测试模块 -->
-    <ion-card (click)="navigateTo('MBTI测试')" routerLink="/test/mbti-test">
+    <ion-card *ngIf="user"(click)="navigateTo('MBTI测试')" routerLink="/test/mbti-test">
       <ion-card-header>
         <ion-card-title>MBTI测试</ion-card-title>
       </ion-card-header>
@@ -36,7 +42,7 @@
     </ion-card>
   
     <!-- 职业推荐模块 -->
-    <ion-card (click)="navigateTo('职业技能树')"routerLink="/test/job-recommend">
+    <ion-card *ngIf="user"(click)="navigateTo('职业技能树')"routerLink="/test/job-recommend">
       <ion-card-header>
         <ion-card-title>职业推荐</ion-card-title>
       </ion-card-header>

+ 19 - 6
src/app/tab1/tab1.page.ts

@@ -1,7 +1,8 @@
-import { Component } from '@angular/core';
+import { Component, OnInit } from '@angular/core';
 import { AlertController } from '@ionic/angular';
 import { trigger, state, style, animate, transition } from '@angular/animations';
-
+import * as Parse from "parse"
+import { Router } from '@angular/router';
 @Component({
   selector: 'app-tab1',
   templateUrl: 'tab1.page.html',
@@ -9,7 +10,7 @@ import { trigger, state, style, animate, transition } from '@angular/animations'
 }
  
 )
-export class Tab1Page {
+export class Tab1Page implements OnInit{
   slider = {
     effect: 'flip',
     speed: 400,
@@ -18,9 +19,21 @@ export class Tab1Page {
       delay: 2000
     }
   };
-
-
-  constructor() {}
+  ok=[{
+    text: 'OK',
+    role: 'confirm',
+    handler: () => {
+      this.router.navigate(['/tabs/tab3']);
+    },
+  },]
+  user:Parse.User|undefined
+  constructor(private router: Router) { 
+    let a=setInterval(() => {
+    this.user =  Parse.User.current()
+  }, 100);
+  }
+  ngOnInit(): void {
+  }
   navigateTo(path:string){
     
   }