Browse Source

feat: enhance project loading logic with defensive checks

- Added defensive checks for projectPointer to ensure valid project IDs are used when querying the Project class.
- Improved error handling with console warnings for invalid project IDs and loading failures.
- Enhanced logging for better debugging and tracking of project retrieval processes.
徐福静0235668 2 days ago
parent
commit
e82ea35fdb
1 changed files with 27 additions and 16 deletions
  1. 27 16
      src/modules/project/pages/chat-activation/chat-activation.component.ts

+ 27 - 16
src/modules/project/pages/chat-activation/chat-activation.component.ts

@@ -268,26 +268,37 @@ export class ChatActivationComponent implements OnInit, OnDestroy {
             memberCount: (this.groupChat.get('member_list') || []).length
           });
           
-          // 获取关联的项目(使用include)
+          // 获取关联的项目(使用include,添加防御性检查
           const projectPointer = this.groupChat.get('project');
+          console.log('📋 项目指针:', projectPointer);
+          
           if (projectPointer) {
-            try {
-              const pQuery = new Parse.Query('Project');
-              pQuery.include('contact');
-              pQuery.include('assignee');
-              pQuery.include('department');
-              pQuery.include('department.leader');
-              this.project = await pQuery.get(projectPointer.id);
-              
-              if (this.project) {
-                console.log('✅ 找到项目:', this.project.get('title'));
-                this.contact = this.project.get('contact');
-                this.projectId = this.project.id;
+            // 检查projectPointer是否有有效的id或objectId
+            const projectId = projectPointer.id || projectPointer.objectId;
+            console.log('📋 提取的项目ID:', projectId);
+            
+            if (projectId && projectId !== 'undefined') {
+              try {
+                const pQuery = new Parse.Query('Project');
+                pQuery.include('contact');
+                pQuery.include('assignee');
+                pQuery.include('department');
+                pQuery.include('department.leader');
+                this.project = await pQuery.get(projectId);
+                
+                if (this.project) {
+                  console.log('✅ 找到项目:', this.project.get('title'));
+                  this.contact = this.project.get('contact');
+                  this.projectId = this.project.id;
+                }
+              } catch (projectError) {
+                console.warn('⚠️ 加载项目失败:', projectError);
+                console.warn('   尝试的项目ID:', projectId);
               }
-            } catch (projectError) {
-              console.warn('⚠️ 加载项目失败:', projectError);
+            } else {
+              console.warn('⚠️ 项目ID无效:', projectId);
             }
-        } else {
+          } else {
             console.warn('⚠️ 群聊未关联项目');
           }