Browse Source

Merge branch 'master' of http://git.fmode.cn:3000/4u/workspace

19136808282 3 months ago
parent
commit
4c0433cec4

+ 58 - 0
.history/soul-app/src/app/page-psysurvey/page-psysurvey.component_20241224105250.ts

@@ -0,0 +1,58 @@
+import { CommonModule } from '@angular/common';
+import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
+import { IonHeader,IonButton, IonContent, IonIcon, IonItem, IonLabel, IonList, 
+  IonListHeader,IonCardHeader,IonCardTitle,IonCardContent, IonTitle,IonCard, IonToolbar,IonInput,IonSearchbar } from '@ionic/angular/standalone';
+  import { HttpClient } from '@angular/common/http';
+  import { UserService } from '../user.service'; // 确保路径正确
+  import { FormsModule } from '@angular/forms'; // 导入 FormsModule
+import { CloudQuery, CloudUser } from 'src/lib/ncloud';
+
+
+  
+
+@Component({
+  selector: 'app-page-psysurvey',
+  templateUrl: './page-psysurvey.component.html',
+  styleUrls: ['./page-psysurvey.component.scss'],
+  standalone: true,
+  imports: [IonHeader,IonToolbar,IonTitle,IonContent,
+      IonList,IonListHeader,IonItem,IonCardTitle,FormsModule,
+      IonLabel,IonIcon,IonButton,IonCardContent,
+      IonInput,IonSearchbar,IonCard,IonCardHeader,
+      CommonModule
+    ]
+})
+export class PagePsysurveyComponent  implements OnInit {
+  surveys: any[] = []; // 存储问卷通知
+  filteredSurveys: any[] = []; // 存储过滤后的问卷
+  userDepartment: string = '' ; // 当前用户的学院
+
+  constructor(private router: Router,private http: HttpClient,private userService: UserService) { }
+  goTab1(){
+    this.router.navigate(['tabs/tab1']);
+   }
+   goPublishSurvey(){
+    this.router.navigate(['tabs/page-publishsurvey'])
+   }
+
+   ngOnInit() {
+      this.getSurveys(); // 在获取到用户信息后获取问卷
+  }
+
+  async getSurveys() {
+      let query = new CloudQuery("Survey");
+      this.surveys = await query.find(); // 假设响应是问卷数组
+      this.filterSurveys(); // 过滤问卷
+  }
+  filterSurveys() {
+    let user = new CloudUser();
+    console.log(user)
+    this.filteredSurveys = this.surveys.filter(survey => {
+      console.log(survey.get("audience"), user.get("department"))
+      return (survey.get("audience") === user.get("department") || survey.get("audience") === 'all');
+    });
+  }
+  
+  
+}

+ 5 - 5
soul-app/src/app/page-psysurvey/page-psysurvey.component.ts

@@ -6,7 +6,7 @@ import { IonHeader,IonButton, IonContent, IonIcon, IonItem, IonLabel, IonList,
   import { HttpClient } from '@angular/common/http';
   import { UserService } from '../user.service'; // 确保路径正确
   import { FormsModule } from '@angular/forms'; // 导入 FormsModule
-import { CloudQuery } from 'src/lib/ncloud';
+import { CloudQuery, CloudUser } from 'src/lib/ncloud';
 
 
   
@@ -37,9 +37,6 @@ export class PagePsysurveyComponent  implements OnInit {
    }
 
    ngOnInit() {
-    // 动态获取当前用户的学院信息
-    let user = this.userService.getCurrentUser()
-      this.userDepartment = user.get("department"); // 从用户数据中获取学院
       this.getSurveys(); // 在获取到用户信息后获取问卷
   }
 
@@ -49,8 +46,11 @@ export class PagePsysurveyComponent  implements OnInit {
       this.filterSurveys(); // 过滤问卷
   }
   filterSurveys() {
+    let user = new CloudUser();
+    console.log(user)
     this.filteredSurveys = this.surveys.filter(survey => {
-      return survey.get("audience") === this.userDepartment || survey.get("audience") === 'all';
+      console.log(survey.get("audience"), user.get("department"))
+      return (survey.get("audience") === user.get("department") || survey.get("audience") === 'all');
     });
   }