|
@@ -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 {
|