Browse Source

update:Routes

0235701 1 day ago
parent
commit
24162ebaf2

+ 3 - 4
ai-assisant/src/app/app.config.ts

@@ -1,12 +1,11 @@
 import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
 import { provideRouter } from '@angular/router';
-
-import { routes } from './app.routes';
+import { ROOT_ROUTES } from './app'; // 从app.ts导入路由配置
 
 export const appConfig: ApplicationConfig = {
   providers: [
     provideBrowserGlobalErrorListeners(),
     provideZoneChangeDetection({ eventCoalescing: true }),
-    provideRouter(routes)
+    provideRouter(ROOT_ROUTES) // 使用ROOT_ROUTES代替原有的routes
   ]
-};
+};

+ 21 - 10
ai-assisant/src/app/app.ts

@@ -1,30 +1,41 @@
 import { Component } from '@angular/core';
-import { RouterModule, RouterOutlet } from '@angular/router';
- import { NgModule } from '@angular/core';
- import { FormsModule } from '@angular/forms';
+import { RouterModule, RouterOutlet, Routes } from '@angular/router';
+import { NgModule } from '@angular/core';
+import { FormsModule } from '@angular/forms';
+import { MOBILE_ROUTES } from '../modules/crm/mobile/mobile.routes'; // 导入移动端路由配置
+
+import { PageCrmTraining } from '../modules/crm/mobile/page-crm-training/page-crm-training';
+import { TrainingReportsComponent } from '../modules/crm/mobile/page-crm-training/report-viewer.component';
+
+export const ROOT_ROUTES: Routes = [
+  ...MOBILE_ROUTES,
+  { path: '**', redirectTo: 'home', pathMatch: 'full' } // 通配符路由,处理无效路径
+];
 
- import { PageCrmTraining } from '../modules/crm/mobile/page-crm-training/page-crm-training';
- import { TrainingReportsComponent } from '../modules/crm/mobile/page-crm-training/report-viewer.component';
 
 @Component({
   selector: 'app-root',
   standalone: true,
-  imports: [RouterOutlet, RouterModule,],
+  imports: [
+    RouterOutlet, 
+  ],
   templateUrl: './app.html',
   styleUrl: './app.scss'
 })
 export class App {
   protected title = 'ai-assistant';
 }
- @NgModule({
+
+@NgModule({
   imports: [
-     FormsModule,
+    FormsModule,
     PageCrmTraining,
-     TrainingReportsComponent,
+    TrainingReportsComponent,
+    RouterModule.forChild(MOBILE_ROUTES) // 子模块路由注册
     // 其他模块...
   ],
   declarations: [
   ]
 
 })
- export class CrmModule { }
+export class CrmModule { }

+ 74 - 52
ai-assisant/src/modules/crm/mobile/page-crm-home/page-crm-home.ts

@@ -1,4 +1,5 @@
 import { Component, OnInit, ViewChild } from '@angular/core';
+import { Router, NavigationEnd } from '@angular/router'; // 导入 Router 和 NavigationEnd
 import { RouterModule } from '@angular/router';
 import { CommonModule } from '@angular/common';
 import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
@@ -8,7 +9,7 @@ import {
   faBrain, faBell, faUser, faRobot, faComments, 
   faDatabase, faUserTie, faTimes, faHistory, faStar, 
   faChartLine, faFileAlt, faBullhorn, faUserCircle,
-  faFire, faTrophy, faCheck
+  faFire, faTrophy, faCheck, faArrowUp, faEye, faClock
 } from '@fortawesome/free-solid-svg-icons';
 import { CloudUser } from '../../../../lib/ncloud';
 
@@ -25,7 +26,7 @@ export class PageCrmHome implements OnInit {
     faBrain, faBell, faUser, faRobot, faComments, 
     faDatabase, faUserTie, faTimes, faHistory, faStar, 
     faChartLine, faFileAlt, faBullhorn, faUserCircle,
-    faFire, faTrophy, faCheck
+    faFire, faTrophy, faCheck, faArrowUp, faEye, faClock
   };
 
   // 弹窗控制变量
@@ -57,7 +58,8 @@ export class PageCrmHome implements OnInit {
       statIcon: 'fas fa-history',
       stat1: '86次练习',
       stat2: '92%得分',
-      hasNotification: true
+      hasNotification: true,
+      routerPath: 'training' // 对应路由中的 training 路径
     },
     {
       id: 'speech-strategy',
@@ -66,7 +68,8 @@ export class PageCrmHome implements OnInit {
       icon: 'fas fa-comments',
       statIcon: 'fas fa-star',
       stat1: '34个策略',
-      stat2: '89%有效'
+      stat2: '89%有效',
+      routerPath: 'decision' // 对应路由中的 decision 路径
     },
     {
       id: 'data-training',
@@ -75,7 +78,8 @@ export class PageCrmHome implements OnInit {
       icon: 'fas fa-database',
       statIcon: 'fas fa-chart-line',
       stat1: '1.2GB',
-      stat2: '95%准确'
+      stat2: '95%准确',
+      routerPath: 'data' // 对应路由中的 data 路径
     },
     {
       id: 'customer-profile',
@@ -84,7 +88,8 @@ export class PageCrmHome implements OnInit {
       icon: 'fas fa-user-tie',
       statIcon: 'fas fa-file-alt',
       stat1: '28份',
-      stat2: '更新中'
+      stat2: '更新中',
+      routerPath: 'image' // 对应路由中的 image 路径
     }
   ];
 
@@ -147,57 +152,30 @@ export class PageCrmHome implements OnInit {
   @ViewChild(LoginModalComponent) loginModal!: LoginModalComponent;
   @ViewChild(RegisterModalComponent) registerModal!: RegisterModalComponent;
 
-// 在 PageCrmHome 类中添加(建议放在 logout 方法下方)
-async loadUserProfile() {
-  this.loadingProfile = true; // 开始加载
-  try {
-    const cloudUser = new CloudUser();
-    const currentUser = await cloudUser.current(); // 获取当前用户
-    
-    if (currentUser && currentUser.sessionToken) {
-      this.isLoggedIn = true;
-      // 绑定完整用户信息(包含注册时的扩展字段)
-      this.currentUser = {
-        username: currentUser.get('username') || '用户',
-        role: currentUser.get('role') || '销售',
-        // 扩展字段(注册时填写的信息)
-        age: currentUser.get('age') || '未设置',   // 年龄
-        birthDate: currentUser.get('birthDate') || '未设置', // 出生日期
-        position: currentUser.get('position') || '未设置',   // 职位
-        // 系统字段
-        trainingCount: currentUser.get('trainingCount') || 0
-      };
-      // 更新 user 对象,确保页面数据同步
-      this.user = {
-        username: this.currentUser.username,
-        role: this.currentUser.position,
-        age: this.currentUser.age,
-        birthDate: this.currentUser.birthDate,
-        trainingCount: this.currentUser.trainingCount
-      };
-    }
-  } catch (error) {
-    console.error('加载用户信息失败:', error);
-    this.currentUser = null;
-    this.isLoggedIn = false;
-  } finally {
-    this.loadingProfile = false; // 结束加载
-  }
-}
-
-
-
-
-
-
   private modalOpenCount = 0;
   private modalCloseReason: string = '';
+  
+  // 当前激活的路由,用于高亮卡片
+  currentRoute: string = '';
+
+  constructor(private router: Router) {
+    // 监听路由变化,更新当前激活的路由
+    this.router.events.subscribe(event => {
+      if (event instanceof NavigationEnd) {
+        this.currentRoute = event.urlAfterRedirects.replace('/', '');
+      }
+    });
+  }
 
   ngOnInit(): void {
+    // 优先读取本地存储的消息(如果有)
+    const savedMessages = localStorage.getItem('crmMessages');
+    if (savedMessages) {
+      this.messages = JSON.parse(savedMessages);
+    }
     this.updateUnreadCount();
     this.updateMotivationalText();
-    this.loadUserProfile(); // 初始化加载用户信息
-    
+    this.loadUserProfile();
     setInterval(() => this.updateMotivationalText(), 10000);
   }
 
@@ -206,6 +184,40 @@ async loadUserProfile() {
     this.motivationalText = this.motivationalPhrases[randomIndex];
   }
 
+  async loadUserProfile() {
+    this.loadingProfile = true;
+    try {
+      const cloudUser = new CloudUser();
+      const currentUser = await cloudUser.current();
+      
+      if (currentUser && currentUser.sessionToken) {
+        this.isLoggedIn = true;
+        this.currentUser = {
+          username: currentUser.get('username') || '用户',
+          role: currentUser.get('role') || '销售',
+          age: currentUser.get('age') || '未设置',
+          birthDate: currentUser.get('birthDate') || '未设置',
+          position: currentUser.get('position') || '未设置',
+          trainingCount: currentUser.get('trainingCount') || 0
+        };
+        // 同步更新 user 对象
+        this.user = {
+          username: this.currentUser.username,
+          role: this.currentUser.position,
+          age: this.currentUser.age,
+          birthDate: this.currentUser.birthDate,
+          trainingCount: this.currentUser.trainingCount
+        };
+      }
+    } catch (error) {
+      console.error('加载用户信息失败:', error);
+      this.currentUser = null;
+      this.isLoggedIn = false;
+    } finally {
+      this.loadingProfile = false;
+    }
+  }
+
   async logout(): Promise<void> {
     const cloudUser = new CloudUser();
     await cloudUser.logout();
@@ -242,6 +254,7 @@ async loadUserProfile() {
     if (message.unread) {
       message.unread = false;
       this.updateUnreadCount();
+      localStorage.setItem('crmMessages', JSON.stringify(this.messages)); // 保存消息状态
     }
   }
 
@@ -254,18 +267,21 @@ async loadUserProfile() {
     if (message.unread) {
       message.unread = false;
       this.updateUnreadCount();
+      localStorage.setItem('crmMessages', JSON.stringify(this.messages)); // 保存消息状态
     }
   }
 
   markAllAsRead(): void {
     this.messages.forEach(message => message.unread = false);
     this.updateUnreadCount();
+    localStorage.setItem('crmMessages', JSON.stringify(this.messages)); // 保存消息状态
   }
 
   markAsRead(message: any): void {
     if (message.unread) {
       message.unread = false;
       this.updateUnreadCount();
+      localStorage.setItem('crmMessages', JSON.stringify(this.messages)); // 保存消息状态
     }
   }
 
@@ -273,8 +289,14 @@ async loadUserProfile() {
     this.unreadMessagesCount = this.messages.filter(m => m.unread).length;
   }
 
+  // 实现路由跳转
   navigateTo(featureId: string): void {
-    console.log('导航至:', featureId);
+    const feature = this.features.find(f => f.id === featureId);
+    if (feature?.routerPath) {
+      this.router.navigate([feature.routerPath]);
+    } else {
+      console.warn(`未找到功能ID为 ${featureId} 的路由配置`);
+    }
   }
 
   openLoginModal(): void {