日期: 2025-10-24
问题: 项目列表中的"负责人"列显示"未分配"
现有项目在数据库中还没有 assignee 或 department 字段,导致显示"未分配"。
步骤:
打开浏览器控制台
http://localhost:4200/admin/project-managementF12 打开开发者工具运行迁移脚本
// 1. 检查项目状态
const ProjectMigrationService = await import('./src/app/pages/admin/services/project-migration.service').then(m => m.ProjectMigrationService);
const migrationService = new ProjectMigrationService();
   
// 查看需要迁移的项目数量
const status = await migrationService.checkProjectsStatus();
console.log('需要迁移的项目:', status.needsMigration);
   
// 2. 执行迁移
const result = await migrationService.migrateProjectAssignees();
console.log('迁移结果:', result);
刷新页面
Ctrl+Shift+R 强制刷新步骤:
在 src/app/pages/admin/project-management/project-management.ts 中添加:
import { ProjectMigrationService } from '../services/project-migration.service';
export class ProjectManagement {
  constructor(
    private projectService: ProjectService,
    private migrationService: ProjectMigrationService // ✅ 添加
  ) {}
  
  // ✅ 添加迁移方法
  async migrateProjects() {
    const confirmed = confirm('确定要批量更新所有项目的负责人吗?');
    if (!confirmed) return;
    
    try {
      const result = await this.migrationService.migrateProjectAssignees();
      alert(`迁移完成!\n总计: ${result.total}\n成功: ${result.success}\n失败: ${result.failed}`);
      
      // 刷新项目列表
      await this.loadProjects();
    } catch (error) {
      alert('迁移失败: ' + error);
    }
  }
}
在 src/app/pages/admin/project-management/project-management.html 顶部添加:
<button (click)="migrateProjects()" class="btn btn-warning">
  🔧 批量更新负责人
</button>
重启开发服务器
npm start
点击按钮执行迁移
如果上述方案都不work,可以在Parse Dashboard中手动修复:
步骤:
打开Parse Dashboard
进入Project表
找到一个项目
编辑该项目:
department 列,选择一个Departmentassignee 列,选择该Department的leader重复步骤3-4,直到所有项目都有负责人
在浏览器控制台执行:
// 使用FmodeParse直接查询
const Parse = FmodeParse.with('nova');
const query = new Parse.Query('Project');
query.include(['assignee', 'department', 'department.leader']);
query.limit(5);
const projects = await query.find();
projects.forEach(p => {
  console.log('项目:', p.get('title'));
  console.log('- assignee:', p.get('assignee')?.get('name'));
  console.log('- department:', p.get('department')?.get('name'));
  console.log('- leader:', p.get('department')?.get('leader')?.get('name'));
});
http://localhost:4200/admin/project-management开始迁移
  ↓
查询所有项目
  ↓
遍历每个项目
  ↓
已有assignee? → 跳过
  ↓ No
有department? → 使用其leader作为assignee
  ↓ No
查找默认项目组 → 使用其leader作为assignee
  ↓
保存项目
  ↓
下一个项目
安全性:
智能分配:
详细日志:
批量处理:
备份数据:
检查项目组:
Project表
- project1: { title: "项目A", assignee: null, department: null }
- project2: { title: "项目B", assignee: null, department: null }
项目列表显示:
项目A    | 未分配
项目B    | 未分配
Project表
- project1: { 
    title: "项目A", 
    assignee: Pointer<Profile>汪奥, 
    department: Pointer<Department>汪奥组 
  }
- project2: { 
    title: "项目B", 
    assignee: Pointer<Profile>汪奥, 
    department: Pointer<Department>汪奥组 
  }
项目列表显示:
项目A    | 汪奥
项目B    | 汪奥
src/app/pages/admin/services/project-migration.service.tssrc/app/pages/admin/services/project.service.tssrc/modules/project/components/team-assign/team-assign.component.tsA:
A:
A:
准备好了吗?开始迁移吧! 🚀