7 2 өдөр өмнө
parent
commit
c1dec3e81b

+ 2 - 14
myapp/src/app/tab1/tab1.page.html

@@ -3,11 +3,8 @@
     <ion-title>
       <ion-text color="light">{{ greetingMessage }}</ion-text>
     </ion-title>
-    <ion-buttons slot="end">
-      <ion-button (click)="openVoiceInput()">
-        <ion-icon slot="icon-only" name="mic"></ion-icon>
-      </ion-button>
-    </ion-buttons>
+   
+   
   </ion-toolbar>
   
  
@@ -79,12 +76,3 @@
 
   
 
-<!-- 悬浮助手按钮 -->
-<div class="assistant-button" (click)="openVoiceInput()">
-  <div class="assistant-face">
-    <div class="assistant-eye left-eye"></div>
-    <div class="assistant-eye right-eye"></div>
-    <div class="assistant-mouth"></div>
-  </div>
-</div>
-  </div>

+ 21 - 0
myapp/src/app/tab5/auth.guard.ts

@@ -0,0 +1,21 @@
+import { Injectable } from '@angular/core';
+import { CanActivate, Router } from '@angular/router';
+import { CloudUser } from '../../lib/ncloud';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class AuthGuard implements CanActivate {
+  user = new CloudUser();
+
+  constructor(private router: Router) {}
+
+  async canActivate(): Promise<boolean> {
+    const currentUser = await this.user.current();
+    if (!currentUser) {
+      this.router.navigate(['/tabs/tab5']);
+      return false;
+    }
+    return true;
+  }
+}

+ 5 - 6
myapp/src/app/tab5/tab5-routing.module.ts

@@ -1,6 +1,7 @@
 import { NgModule } from '@angular/core';
 import { RouterModule, Routes } from '@angular/router';
 import { Tab5Page } from './tab5.page';
+import { AuthGuard } from './auth.guard';
 import { UserDashboardPage } from './user-dashboard.page';
 import { RegisterPage } from './register.page';
 import { UploadQualificationPage } from './upload-qualification.page';
@@ -12,15 +13,13 @@ const routes: Routes = [
   },
   {
     path: 'user-dashboard',
-    component: UserDashboardPage
-  },
-  {
-    path: 'register',
-    component: RegisterPage
+    component: UserDashboardPage,
+    canActivate: [AuthGuard]
   },
   {
     path: 'upload-qualification',
-    component: UploadQualificationPage
+    loadChildren: () => import('./upload-qualification.page').then(m => m.UploadQualificationPage),
+    canActivate: [AuthGuard]
   }
 ];
 

+ 1 - 4
myapp/src/app/tab5/tab5.page.ts

@@ -40,14 +40,11 @@ export class Tab5Page {
       return;
     }
 
-    // 清除用户相关的缓存信息
-    localStorage.removeItem("NCloud/dev/User");
-
     const result = await this.user.login(this.username, this.password);
     if (result) {
       this.isLoggedIn = true;
       this.currentUser = result;
-      this.router.navigate(['/tabs/tab5/user-dashboard']); // 跳转到新页面
+      this.router.navigate(['/tabs/tab5/user-dashboard']);
     } else {
       alert('登录失败,请检查用户名和密码');
     }