# 组长端待办任务区域重构方案 ## 📋 需求概述 **目标**:将组长端待办任务区域从现有的模拟数据样式,重构为基于真实项目问题板块的紧凑列表式布局。 **核心逻辑**: - 当任何项目的问题板块(`ProjectIssue`)中出现新问题或未处理的问题时,自动在组长端待办任务区域显示 - 使用紧凑的、按时间排序的列表式布局 - 支持快速查看、跳转和处理问题 --- ## 🎯 功能设计 ### 1. 数据来源 **数据表**:`ProjectIssue`(问题表) **筛选条件**: - `status` = `'待处理'`(open)或 `'处理中'`(in_progress) - `isDeleted` ≠ `true` - 按 `createdAt` 或 `updatedAt` 倒序排列 **关联数据**: - `project`:关联的项目信息(项目名称、ID) - `creator`:问题创建人 - `assignee`:负责人(默认为项目负责人或组长) - `priority`:优先级(low/medium/high/critical/urgent) - `type`:问题类型(bug/task/feedback/risk/feature) ### 2. UI/UX 设计 #### 2.1 布局样式 **列表式紧凑布局**: ``` ┌─────────────────────────────────────────────────┐ │ 待办任务 (12) [刷新] [全部查看] │ ├─────────────────────────────────────────────────┤ │ 🔴 [紧急] 厨房柜体尺寸与现场不符 │ │ 项目: 金地格林小镇 | 主卧 | 建模阶段 │ │ 创建于 2小时前 · 指派给: 王刚 │ │ [查看详情] [标记已读] │ ├─────────────────────────────────────────────────┤ │ 🟠 [高] 主卧效果图灯光偏暗 │ │ 项目: 碧桂园天玺 | 主卧 | 渲染阶段 │ │ 创建于 5小时前 · 指派给: 李娜 │ │ [查看详情] [标记已读] │ ├─────────────────────────────────────────────────┤ │ 🟡 [中] 确认客厅配色与材质样板 │ │ 项目: 万科城市之光 | 客厅 | 方案阶段 │ │ 创建于 1天前 · 指派给: 张三 │ │ [查看详情] [标记已读] │ └─────────────────────────────────────────────────┘ ``` #### 2.2 优先级视觉标识 - **🔴 紧急**(critical/urgent):红色圆点 + 红色文字 - **🟠 高**(high):橙色圆点 + 橙色文字 - **🟡 中**(medium):黄色圆点 + 灰色文字 - **⚪ 低**(low):灰色圆点 + 浅灰色文字 #### 2.3 时间显示逻辑 - **1小时内**:显示"X分钟前" - **1-24小时**:显示"X小时前" - **1-7天**:显示"X天前" - **7天以上**:显示完整日期"MM-dd" ### 3. 交互设计 #### 3.1 点击行为 1. **[查看详情]**:跳转到项目详情页的问题板块,高亮显示对应问题 2. **[标记已读]**:(可选)标记问题为已读状态,从待办列表中移除(但不改变问题状态) 3. **点击整行**:同"查看详情" #### 3.2 刷新逻辑 - **自动刷新**:每隔 5 分钟自动从后端拉取最新问题列表 - **手动刷新**:点击刷新按钮立即更新 - **实时推送**(可选):使用 WebSocket 或轮询实现实时更新 #### 3.3 分页/加载更多 - **默认显示**:最多显示 10 条待办任务 - **[全部查看]**:跳转到专用的待办任务管理页面(可选) - **无限滚动**:滚动到底部自动加载更多(可选) --- ## 🔧 技术实现 ### 1. 数据模型 #### 1.1 待办任务数据结构 ```typescript interface TodoTaskFromIssue { id: string; // 问题ID title: string; // 问题标题 description?: string; // 问题描述 priority: IssuePriority; // 优先级 type: IssueType; // 问题类型 status: IssueStatus; // 问题状态 projectId: string; // 项目ID projectName: string; // 项目名称 relatedSpace?: string; // 关联空间(如:主卧、客厅) relatedStage?: string; // 关联阶段(如:建模、渲染) assigneeName?: string; // 负责人姓名 creatorName?: string; // 创建人姓名 createdAt: Date; // 创建时间 updatedAt: Date; // 更新时间 dueDate?: Date; // 截止时间 tags?: string[]; // 标签 } ``` #### 1.2 优先级映射 ```typescript const PRIORITY_CONFIG = { urgent: { label: '紧急', icon: '🔴', color: '#dc2626', order: 0 }, critical: { label: '紧急', icon: '🔴', color: '#dc2626', order: 0 }, high: { label: '高', icon: '🟠', color: '#ea580c', order: 1 }, medium: { label: '中', icon: '🟡', color: '#ca8a04', order: 2 }, low: { label: '低', icon: '⚪', color: '#9ca3af', order: 3 } }; ``` ### 2. 后端数据查询 #### 2.1 Parse Server 查询 ```typescript async loadTodoTasksFromIssues(): Promise { try { const query = new Parse.Query('ProjectIssue'); // 筛选条件:待处理 + 处理中 query.containedIn('status', ['待处理', '处理中']); query.notEqualTo('isDeleted', true); // 关联数据 query.include(['project', 'creator', 'assignee']); // 排序:优先级 -> 更新时间 query.descending('updatedAt'); // 限制数量(首屏加载) query.limit(20); const results = await query.find(); // 数据转换 const tasks: TodoTaskFromIssue[] = results.map(obj => { const project = obj.get('project'); const assignee = obj.get('assignee'); const creator = obj.get('creator'); return { id: obj.id, title: obj.get('title') || '未命名问题', description: obj.get('description'), priority: obj.get('priority') as IssuePriority, type: obj.get('issueType') as IssueType, status: this.zh2en(obj.get('status')) as IssueStatus, projectId: project?.id || '', projectName: project?.get('name') || '未知项目', relatedSpace: obj.get('relatedSpace'), relatedStage: obj.get('relatedStage'), assigneeName: assignee?.get('name') || assignee?.get('realname') || '未指派', creatorName: creator?.get('name') || creator?.get('realname') || '未知', createdAt: obj.createdAt, updatedAt: obj.updatedAt, dueDate: obj.get('dueDate'), tags: (obj.get('data')?.tags || []) as string[] }; }); // 二次排序:优先级 -> 时间 return tasks.sort((a, b) => { const priorityA = PRIORITY_CONFIG[a.priority].order; const priorityB = PRIORITY_CONFIG[b.priority].order; if (priorityA !== priorityB) { return priorityA - priorityB; } return +new Date(b.updatedAt) - +new Date(a.updatedAt); }); } catch (error) { console.error('❌ 加载待办任务失败:', error); return []; } } ``` #### 2.2 状态映射 ```typescript private zh2en(status: string): IssueStatus { const map: Record = { '待处理': 'open', '处理中': 'in_progress', '已解决': 'resolved', '已关闭': 'closed' }; return map[status] || 'open'; } ``` ### 3. 前端组件实现 #### 3.1 组件文件结构 ``` src/app/pages/team-leader/dashboard/ ├── dashboard.ts # 主组件逻辑 ├── dashboard.html # 模板文件 ├── dashboard.scss # 样式文件 └── components/ └── todo-task-item/ # 待办任务列表项组件(可选) ├── todo-task-item.ts ├── todo-task-item.html └── todo-task-item.scss ``` #### 3.2 dashboard.ts 核心代码 ```typescript export class Dashboard implements OnInit { // 待办任务列表 todoTasksFromIssues: TodoTaskFromIssue[] = []; loadingTodoTasks: boolean = false; todoTaskError: string = ''; // 自动刷新定时器 private todoTaskRefreshTimer: any; ngOnInit() { // 初始加载 this.loadTodoTasksFromIssues(); // 启动自动刷新(每5分钟) this.startAutoRefresh(); } ngOnDestroy() { // 清理定时器 if (this.todoTaskRefreshTimer) { clearInterval(this.todoTaskRefreshTimer); } } /** * 加载待办任务(从问题板块) */ async loadTodoTasksFromIssues(): Promise { this.loadingTodoTasks = true; this.todoTaskError = ''; try { const query = new Parse.Query('ProjectIssue'); query.containedIn('status', ['待处理', '处理中']); query.notEqualTo('isDeleted', true); query.include(['project', 'creator', 'assignee']); query.descending('updatedAt'); query.limit(20); const results = await query.find(); this.todoTasksFromIssues = results.map(obj => { const project = obj.get('project'); const assignee = obj.get('assignee'); const creator = obj.get('creator'); return { id: obj.id, title: obj.get('title') || '未命名问题', description: obj.get('description'), priority: obj.get('priority') as IssuePriority, type: obj.get('issueType') as IssueType, status: this.zh2en(obj.get('status')) as IssueStatus, projectId: project?.id || '', projectName: project?.get('name') || '未知项目', relatedSpace: obj.get('relatedSpace'), relatedStage: obj.get('relatedStage'), assigneeName: assignee?.get('name') || assignee?.get('realname') || '未指派', creatorName: creator?.get('name') || creator?.get('realname') || '未知', createdAt: obj.createdAt, updatedAt: obj.updatedAt, dueDate: obj.get('dueDate'), tags: (obj.get('data')?.tags || []) as string[] }; }); // 排序:优先级 -> 时间 this.todoTasksFromIssues.sort((a, b) => { const priorityA = this.getPriorityOrder(a.priority); const priorityB = this.getPriorityOrder(b.priority); if (priorityA !== priorityB) { return priorityA - priorityB; } return +new Date(b.updatedAt) - +new Date(a.updatedAt); }); console.log(`✅ 加载待办任务成功,共 ${this.todoTasksFromIssues.length} 条`); } catch (error) { console.error('❌ 加载待办任务失败:', error); this.todoTaskError = '加载失败,请稍后重试'; } finally { this.loadingTodoTasks = false; } } /** * 启动自动刷新 */ startAutoRefresh(): void { // 每5分钟刷新一次 this.todoTaskRefreshTimer = setInterval(() => { this.loadTodoTasksFromIssues(); }, 5 * 60 * 1000); } /** * 手动刷新 */ refreshTodoTasks(): void { this.loadTodoTasksFromIssues(); } /** * 跳转到项目问题详情 */ navigateToIssue(task: TodoTaskFromIssue): void { const cid = localStorage.getItem('company') || 'cDL6R1hgSi'; // 跳转到项目详情页,并打开问题板块 this.router.navigate( ['/wxwork', cid, 'project', task.projectId, 'order'], { queryParams: { openIssues: 'true', highlightIssue: task.id } } ); } /** * 标记问题为已读(可选功能) */ async markAsRead(task: TodoTaskFromIssue): Promise { try { // 实现方式1: 本地隐藏(不修改数据库) this.todoTasksFromIssues = this.todoTasksFromIssues.filter(t => t.id !== task.id); // 实现方式2: 添加"已读"标记到数据库(需扩展数据模型) // const query = new Parse.Query('ProjectIssue'); // const issue = await query.get(task.id); // const readBy = issue.get('readBy') || []; // if (!readBy.includes(currentUserId)) { // readBy.push(currentUserId); // issue.set('readBy', readBy); // await issue.save(); // } console.log(`✅ 标记问题为已读: ${task.title}`); } catch (error) { console.error('❌ 标记已读失败:', error); } } /** * 获取优先级配置 */ getPriorityConfig(priority: IssuePriority) { const config = { urgent: { label: '紧急', icon: '🔴', color: '#dc2626', order: 0 }, critical: { label: '紧急', icon: '🔴', color: '#dc2626', order: 0 }, high: { label: '高', icon: '🟠', color: '#ea580c', order: 1 }, medium: { label: '中', icon: '🟡', color: '#ca8a04', order: 2 }, low: { label: '低', icon: '⚪', color: '#9ca3af', order: 3 } }; return config[priority] || config.medium; } getPriorityOrder(priority: IssuePriority): number { return this.getPriorityConfig(priority).order; } /** * 获取问题类型中文名 */ getIssueTypeLabel(type: IssueType): string { const map: Record = { bug: '问题', task: '任务', feedback: '反馈', risk: '风险', feature: '需求' }; return map[type] || '任务'; } /** * 格式化相对时间 */ formatRelativeTime(date: Date): string { const now = new Date(); const diff = now.getTime() - new Date(date).getTime(); const minutes = Math.floor(diff / 60000); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); if (minutes < 60) { return `${minutes}分钟前`; } else if (hours < 24) { return `${hours}小时前`; } else if (days < 7) { return `${days}天前`; } else { return new Date(date).toLocaleDateString('zh-CN', { month: '2-digit', day: '2-digit' }); } } /** * 状态映射 */ private zh2en(status: string): IssueStatus { const map: Record = { '待处理': 'open', '处理中': 'in_progress', '已解决': 'resolved', '已关闭': 'closed' }; return map[status] || 'open'; } } ``` #### 3.3 dashboard.html 模板代码 ```html

待办任务 @if (todoTasksFromIssues.length > 0) { ({{ todoTasksFromIssues.length }}) }

@if (loadingTodoTasks) {

加载中...

} @if (todoTaskError && !loadingTodoTasks) {

{{ todoTaskError }}

} @if (!loadingTodoTasks && !todoTaskError && todoTasksFromIssues.length === 0) {

暂无待办任务

所有项目问题都已处理完毕 🎉

} @if (!loadingTodoTasks && !todoTaskError && todoTasksFromIssues.length > 0) {
@for (task of todoTasksFromIssues; track task.id) {
{{ getPriorityConfig(task.priority).icon }} [{{ getPriorityConfig(task.priority).label }}]

{{ task.title }}

{{ getIssueTypeLabel(task.type) }}
{{ task.projectName }} @if (task.relatedSpace) { {{ task.relatedSpace }} } @if (task.relatedStage) { {{ task.relatedStage }} }
}
}
``` #### 3.4 dashboard.scss 样式代码 ```scss .todo-section { background: white; border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); .section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; h2 { font-size: 20px; font-weight: 600; color: #111827; display: flex; align-items: center; gap: 8px; .task-count { font-size: 16px; color: #6b7280; font-weight: 400; } } .section-actions { display: flex; gap: 12px; .btn-refresh { display: flex; align-items: center; gap: 6px; padding: 8px 16px; background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 6px; font-size: 14px; color: #374151; cursor: pointer; transition: all 0.2s; &:hover:not(:disabled) { background: #e5e7eb; border-color: #d1d5db; } &:disabled { opacity: 0.6; cursor: not-allowed; } svg.rotating { animation: rotate 1s linear infinite; } } } } // 加载/错误/空状态 .loading-state, .error-state, .empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; text-align: center; .spinner { width: 40px; height: 40px; border: 4px solid #f3f4f6; border-top-color: #667eea; border-radius: 50%; animation: rotate 1s linear infinite; } p { margin-top: 16px; font-size: 14px; color: #6b7280; &.hint { font-size: 13px; color: #9ca3af; margin-top: 8px; } } .btn-retry { margin-top: 16px; padding: 8px 20px; background: #667eea; color: white; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; transition: background 0.2s; &:hover { background: #5568d3; } } } // 紧凑列表 .todo-list-compact { display: flex; flex-direction: column; gap: 12px; .todo-item-compact { position: relative; display: flex; align-items: stretch; background: #fafafa; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; transition: all 0.2s; cursor: pointer; &:hover { background: #f9fafb; border-color: #d1d5db; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); transform: translateY(-1px); } // 优先级指示条 .priority-indicator { width: 4px; flex-shrink: 0; } // 主要内容区 .task-content { flex: 1; padding: 16px; min-width: 0; .task-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; .priority-icon { font-size: 16px; flex-shrink: 0; } .priority-label { font-size: 12px; font-weight: 600; flex-shrink: 0; } .task-title { font-size: 15px; font-weight: 500; color: #111827; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .issue-type-badge { padding: 2px 8px; background: #e0e7ff; color: #4f46e5; border-radius: 4px; font-size: 11px; font-weight: 500; flex-shrink: 0; } } .task-meta { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; flex-wrap: wrap; .meta-item { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #6b7280; svg { opacity: 0.6; } } } .task-footer { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; .time-info, .assignee-info { display: flex; align-items: center; gap: 4px; font-size: 12px; color: #9ca3af; svg { opacity: 0.7; } } .tags { display: flex; align-items: center; gap: 6px; .tag { padding: 2px 6px; background: #f3f4f6; color: #6b7280; border-radius: 3px; font-size: 11px; } .tag-more { font-size: 11px; color: #9ca3af; } } } } // 操作按钮区 .task-actions { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-left: 1px solid #e5e7eb; background: white; button { padding: 6px 12px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 12px; cursor: pointer; transition: all 0.2s; white-space: nowrap; &.btn-view { background: #667eea; color: white; border-color: #667eea; &:hover { background: #5568d3; border-color: #5568d3; } } &.btn-mark-read { background: white; color: #6b7280; &:hover { background: #f9fafb; border-color: #9ca3af; } } } } } } } @keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } // 响应式布局 @media (max-width: 768px) { .todo-section { padding: 16px; .section-header { flex-direction: column; align-items: flex-start; gap: 12px; } .todo-list-compact { .todo-item-compact { flex-direction: column; .task-actions { flex-direction: row; border-left: none; border-top: 1px solid #e5e7eb; padding: 12px; button { flex: 1; } } } } } } ``` --- ## 📊 数据流程图 ``` ┌─────────────────┐ │ ProjectIssue │ Parse Server 数据表 │ (问题表) │ └────────┬────────┘ │ │ Query: status in ['待处理','处理中'] │ isDeleted != true │ include: ['project','creator','assignee'] │ descending: 'updatedAt' │ limit: 20 │ ▼ ┌─────────────────┐ │ Dashboard.ts │ 组件逻辑层 │ │ │ - loadTodoTasks() ◄── 初始加载 (ngOnInit) │ - refreshTodoTasks() ◄── 手动刷新 │ - startAutoRefresh() ◄── 自动刷新 (5分钟) │ - navigateToIssue() ◄── 跳转详情 │ - markAsRead() ◄── 标记已读 └────────┬────────┘ │ │ todoTasksFromIssues: TodoTaskFromIssue[] │ ▼ ┌─────────────────┐ │ Dashboard.html │ 模板渲染层 │ │ │ - 列表循环渲染 │ - 优先级样式 │ - 相对时间格式化 │ - 交互事件绑定 └─────────────────┘ ``` --- ## 🚀 实施步骤 ### 阶段1: 数据模型与接口(第1天) 1. ✅ 定义 `TodoTaskFromIssue` 接口 2. ✅ 实现 `loadTodoTasksFromIssues()` 方法 3. ✅ 实现优先级配置和排序逻辑 4. ✅ 实现相对时间格式化工具函数 5. ✅ 单元测试数据查询逻辑 ### 阶段2: UI 组件开发(第2天) 1. ✅ 清空现有待办任务区域的模拟数据 2. ✅ 实现新的紧凑列表式 HTML 模板 3. ✅ 实现 SCSS 样式(包括响应式) 4. ✅ 实现加载/错误/空状态 UI 5. ✅ 实现优先级颜色映射 ### 阶段3: 交互功能(第3天) 1. ✅ 实现点击跳转到项目详情+问题板块 2. ✅ 实现手动刷新按钮 3. ✅ 实现自动刷新定时器(5分钟) 4. ✅ 实现"标记已读"功能(可选) 5. ✅ 优化跳转时的 URL 参数传递 ### 阶段4: 测试与优化(第4天) 1. ✅ 真实环境数据测试 2. ✅ 边界情况测试(无数据、大量数据) 3. ✅ 性能优化(分页加载、虚拟滚动) 4. ✅ 响应式布局测试(移动端) 5. ✅ 代码审查与文档完善 --- ## 🔍 边界情况处理 ### 1. 无待办任务 **场景**:所有问题都已解决或关闭 **处理**: - 显示空状态 UI - 提示文案:"暂无待办任务,所有项目问题都已处理完毕 🎉" ### 2. 大量待办任务(>100条) **场景**:问题积压,待办任务过多 **处理**: - 默认加载前 20 条 - 提供"加载更多"按钮或无限滚动 - 建议使用虚拟滚动优化性能 ### 3. 网络请求失败 **场景**:网络异常导致数据加载失败 **处理**: - 显示错误状态 UI - 提供"重试"按钮 - 保留上一次成功加载的数据(可选) ### 4. 问题缺失关联数据 **场景**:问题的 `project`、`assignee` 等关联数据为空 **处理**: - 使用默认值:`'未知项目'`、`'未指派'` - 不影响问题的正常显示 ### 5. 并发刷新 **场景**:用户在自动刷新期间手动点击刷新 **处理**: - 禁用刷新按钮(`loadingTodoTasks = true`) - 忽略重复请求 --- ## 📝 后续优化方向 ### 1. 实时推送 **技术方案**: - 使用 Parse Server 的 LiveQuery 实现实时数据更新 - 或使用 WebSocket 推送新问题通知 ### 2. 批量操作 **功能**: - 批量标记已读 - 批量指派负责人 - 批量修改优先级 ### 3. 筛选与搜索 **功能**: - 按优先级筛选 - 按项目筛选 - 按负责人筛选 - 关键词搜索 ### 4. 通知提醒 **功能**: - 新问题桌面通知 - 紧急问题声音提醒 - 问题催办提醒 ### 5. 数据分析 **功能**: - 问题趋势图表 - 平均处理时长 - 高频问题类型分析 --- ## ✅ 验收标准 1. ✅ 待办任务区域清空旧的模拟数据 2. ✅ 新列表式布局紧凑美观,符合设计稿 3. ✅ 数据来源于真实的 `ProjectIssue` 表 4. ✅ 只显示状态为"待处理"或"处理中"的问题 5. ✅ 按优先级(紧急→高→中→低)+ 时间排序 6. ✅ 点击任务项能正确跳转到项目详情+问题板块 7. ✅ 手动刷新功能正常工作 8. ✅ 自动刷新(5分钟)正常工作 9. ✅ 相对时间显示准确(X分钟前、X小时前、X天前) 10. ✅ 空状态、加载状态、错误状态 UI 正常显示 11. ✅ 移动端响应式布局正常 12. ✅ 无 console 错误和警告 --- ## 📌 注意事项 1. **数据权限**:确保组长有权限查询所有项目的问题数据 2. **性能优化**:大量数据时考虑分页或虚拟滚动 3. **状态同步**:标记已读后需要同步更新计数 4. **路由参数**:跳转时正确传递 `openIssues` 和 `highlightIssue` 参数 5. **清理定时器**:组件销毁时记得清理 `setInterval` --- ## 📚 相关文件清单 ``` src/app/pages/team-leader/dashboard/ ├── dashboard.ts # ✅ 修改 ├── dashboard.html # ✅ 修改 ├── dashboard.scss # ✅ 修改 src/modules/project/services/ ├── project-issue.service.ts # ✅ 已存在,无需修改 src/modules/project/components/ ├── project-issues-modal/ # ✅ 已存在,无需修改 ├── project-issues-modal.component.ts ├── project-issues-modal.component.html └── project-issues-modal.component.scss src/modules/project/pages/project-detail/ ├── project-detail.component.ts # ✅ 可能需要接收 queryParams ├── project-detail.component.html # ✅ 可能需要支持高亮问题 ``` --- ## 🎉 总结 本方案将组长端待办任务区域从静态模拟数据升级为基于真实项目问题板块的动态列表,实现了: 1. **数据真实性**:直接从 `ProjectIssue` 表读取 2. **布局优化**:紧凑的列表式设计,信息密度高 3. **交互流畅**:一键跳转、快速刷新、标记已读 4. **用户体验**:优先级可视化、相对时间、状态提示 5. **可扩展性**:预留了实时推送、批量操作、筛选搜索等扩展接口 **预计开发周期**:3-4 天 **技术风险**:低 **业务价值**:高 ✅