ryanemax 22 часов назад
Родитель
Сommit
7673e4c3a4

+ 16 - 0
src/app/pages/admin/admin-layout/admin-layout.ts

@@ -1,6 +1,7 @@
 import { Component } from '@angular/core';
 import { CommonModule } from '@angular/common';
 import { RouterModule, RouterOutlet } from '@angular/router';
+import { WxworkAuth } from "fmode-ng/core";
 
 @Component({
   selector: 'app-admin-layout',
@@ -11,9 +12,24 @@ import { RouterModule, RouterOutlet } from '@angular/router';
 }) 
 export class AdminLayout {
   sidebarOpen = true;
+
   currentUser = { name: '超级管理员', avatar: "data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='100%25' height='100%25' fill='%23CCFFCC'/%3E%3Ctext x='50%25' y='50%25' font-family='Arial' font-size='13.333333333333334' font-weight='bold' text-anchor='middle' fill='%23555555' dy='0.3em'%3EADMIN%3C/text%3E%3C/svg%3E" };
   currentDate = new Date();
 
+  constructor(){
+    this.loadProfile()
+  }
+  async loadProfile(){
+    let cid = localStorage.getItem("company");
+    if(cid){
+      let wwAuth = new WxworkAuth({cid:cid})
+      let profile = await wwAuth.currentProfile();
+      this.currentUser  = {
+        name: profile?.get("name") || profile?.get("mobile"),
+        avatar: profile?.get("avatar")
+      }
+    }
+  }
   toggleSidebar() {
     this.sidebarOpen = !this.sidebarOpen;
   }

+ 18 - 2
src/app/pages/admin/employees/employees.html

@@ -68,7 +68,15 @@
           <td>{{ emp.mobile }}</td>
           <td>{{ emp.userid }}</td>
           <td><span class="badge">{{ emp.roleName }}</span></td>
-          <td>{{ emp.department }}</td>
+          <td>
+            @if(emp.roleName=="客服"){
+              客服部
+            }@else if(emp.roleName=="管理员"){
+              总部
+            }@else{
+              {{ emp.department }}
+            }
+           </td>
           <td><span [class]="'status ' + (emp.isDisabled ? 'disabled' : 'active')">{{ emp.isDisabled ? '已禁用' : '正常' }}</span></td>
           <td>
             <button class="btn-icon" (click)="viewEmployee(emp)" title="查看">👁</button>
@@ -99,7 +107,15 @@
           <div class="detail-item"><label>手机号</label><div>{{ currentEmployee.mobile }}</div></div>
           <div class="detail-item"><label>企微ID</label><div>{{ currentEmployee.userid }}</div></div>
           <div class="detail-item"><label>身份</label><div>{{ currentEmployee.roleName }}</div></div>
-          <div class="detail-item"><label>部门</label><div>{{ currentEmployee.department }}</div></div>
+          <div class="detail-item"><label>部门</label><div>
+          @if(currentEmployee.roleName=="客服"){
+            客服部
+          }@else if(currentEmployee.roleName=="管理员"){
+            总部
+          }@else{
+            {{ currentEmployee.department }}
+          }
+          </div></div>
           <div class="detail-item"><label>状态</label><div>{{ currentEmployee.isDisabled ? '已禁用' : '正常' }}</div></div>
         </div>
         <div *ngIf="panelMode === 'edit'" class="form-view">

+ 2 - 2
src/app/pages/admin/employees/employees.ts

@@ -80,8 +80,8 @@ export class Employees implements OnInit {
           mobile: json.mobile || '',
           userid: json.userid || '',
           roleName: json.roleName || '未分配',
-          department: json.departmentName || '未分配',
-          departmentId: json.departmentId,
+          department: e.get("department")?.get("name") || '未分配',
+          departmentId: e.get("department")?.id,
           isDisabled: json.isDisabled || false,
           createdAt: json.createdAt
         };

+ 10 - 2
src/app/pages/admin/services/department.service.ts

@@ -1,6 +1,7 @@
 import { Injectable } from '@angular/core';
 import { AdminDataService } from './admin-data.service';
-import { FmodeObject } from 'fmode-ng/core';
+import { FmodeObject, FmodeParse } from 'fmode-ng/core';
+const Parse = FmodeParse.with("nova")
 
 /**
  * 项目组(部门)管理数据服务
@@ -86,6 +87,12 @@ export class DepartmentService {
     return await this.adminData.save(dept);
   }
 
+  async saveProfileDepart(pid:string,did:string){
+    let query = new Parse.Query("Profile");
+    let profile = await query.get(pid);
+    profile.set("department",{__type:"Pointer",className:"Department",objectId:did});
+    profile.save();
+  }
   /**
    * 更新项目组
    */
@@ -107,12 +114,13 @@ export class DepartmentService {
       dept.set('name', updates.name);
     }
 
-    if (updates.leaderId !== undefined) {
+    if (updates.leaderId) {
       dept.set('leader', {
         __type: 'Pointer',
         className: 'Profile',
         objectId: updates.leaderId
       });
+      this.saveProfileDepart(updates.leaderId,objectId)
     }
 
     if (updates.type !== undefined) {

+ 6 - 4
src/app/pages/customer-service/customer-service-layout/customer-service-layout.html

@@ -70,10 +70,12 @@
       </div>
     </div>
     }
-    <div class="user-profile">
-      <div style="width: 40px; height: 40px; background-color: #FFCCCC; color: #555555; display: flex; align-items: center; justify-content: center; font-size: 13.333333333333334px; font-weight: bold;" class="user-avatar" title="用户头像">CS</div>
-      <span class="user-name">客服小李</span>
-    </div>
+    @if(currentUser?.name){
+      <div class="user-profile">
+        <img [src]="currentUser.avatar" alt="用户头像" class="user-avatar">
+        <span class="user-name">{{ currentUser.name }}</span>
+      </div>
+    }
   </div>
 </header>
 

+ 17 - 2
src/app/pages/customer-service/customer-service-layout/customer-service-layout.ts

@@ -2,7 +2,7 @@ import { Component, signal, OnInit, OnDestroy } from '@angular/core';
 import { CommonModule } from '@angular/common';
 import { Router, RouterOutlet, RouterLinkActive, RouterLink } from '@angular/router';
 import { FormsModule } from '@angular/forms';
-
+import { WxworkAuth } from "fmode-ng/core";
 @Component({
   selector: 'app-customer-service-layout',
   standalone: true,
@@ -23,12 +23,27 @@ export class CustomerServiceLayout implements OnInit, OnDestroy {
   ]);
   showNotifications = signal(false);
 
-  constructor(private router: Router) {}
+  constructor(private router: Router) {
+    this.loadProfile();
+  }
 
   ngOnInit() {
     // 监听来自iframe的消息
     window.addEventListener('message', this.handleIframeMessage.bind(this));
   }
+  currentUser:any = {}
+  async loadProfile(){
+      let cid = localStorage.getItem("company");
+      if(cid){
+        let wwAuth = new WxworkAuth({cid:cid})
+        let profile = await wwAuth.currentProfile();
+        this.currentUser  = {
+          name: profile?.get("name") || profile?.get("mobile"),
+          avatar: profile?.get("avatar"),
+          roleName: profile?.get("roleName")
+        }
+      }
+    }
 
   ngOnDestroy() {
     // 清理事件监听器

+ 1 - 1
src/app/pages/customer-service/dashboard/dashboard.html

@@ -2,7 +2,7 @@
 <section class="welcome-section">
   <div class="welcome-header">
     <div>
-      <h2>您好,客服小李 👋</h2>
+      <h2>您好,{{currentUser?.name}} 👋</h2>
       <p>今天是 {{ currentDate.toLocaleDateString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' }) }},祝您工作顺利!</p>
     </div>
     <button class="attendance-view-btn" (click)="viewAttendance()" title="查看人员考勤">

+ 17 - 37
src/app/pages/customer-service/dashboard/dashboard.ts

@@ -5,7 +5,7 @@ import { FormsModule } from '@angular/forms';
 import { RouterModule, Router, ActivatedRoute } from '@angular/router';
 import { ProjectService } from '../../../services/project.service';
 import { Project, Task, CustomerFeedback } from '../../../models/project.model';
-import { FmodeQuery, FmodeObject, FmodeUser } from 'fmode-ng/core';
+import { FmodeQuery } from 'fmode-ng/core';
 import { WxworkAuth } from 'fmode-ng/core';
 
 @Component({
@@ -158,55 +158,35 @@ export class Dashboard implements OnInit, OnDestroy {
     return date.toISOString().split('T')[0];
   }
 
-  private wxAuth: WxworkAuth | null = null;
-  private currentUser: FmodeUser | null = null;
 
   constructor(
     private projectService: ProjectService,
     private router: Router,
     private activatedRoute: ActivatedRoute
   ) {
-    this.initAuth();
-  }
-
-  // 初始化企业微信认证
-  private initAuth(): void {
-    try {
-      this.wxAuth = new WxworkAuth({
-        cid: 'cDL6R1hgSi'  // 公司帐套ID
-      });
-      console.log('✅ 客服仪表板企业微信认证初始化成功');
-    } catch (error) {
-      console.error('❌ 客服仪表板企业微信认证初始化失败:', error);
+    this.loadProfile();
+  }
+
+  currentUser:any = {}
+  async loadProfile(){
+      let cid = localStorage.getItem("company");
+      if(cid){
+        let wwAuth = new WxworkAuth({cid:cid})
+        let profile = await wwAuth.currentProfile();
+        this.currentUser  = {
+          name: profile?.get("name") || profile?.get("mobile"),
+          avatar: profile?.get("avatar"),
+          roleName: profile?.get("roleName")
+        }
+      }
     }
-  }
 
-  async ngOnInit(): Promise<void> {
-    await this.authenticateAndLoadData();
 
+  async ngOnInit(): Promise<void> {
     // 添加滚动事件监听
     window.addEventListener('scroll', this.onScroll.bind(this));
   }
 
-  // 认证并加载数据
-  private async authenticateAndLoadData(): Promise<void> {
-    try {
-      // 执行企业微信认证和登录
-      const { user } = await this.wxAuth!.authenticateAndLogin();
-      this.currentUser = user;
-
-      if (user) {
-        console.log('✅ 客服登录成功:', user.get('username'));
-        await this.loadDashboardData();
-      } else {
-        console.error('❌ 客服登录失败');
-      }
-    } catch (error) {
-      console.error('❌ 客服认证过程出错:', error);
-      // 降级到模拟数据
-      this.loadMockData();
-    }
-  }
 
   // 加载仪表板数据
   private async loadDashboardData(): Promise<void> {