| 
					
				 | 
			
			
				@@ -1,11 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Component, OnInit } from '@angular/core'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Router } from '@angular/router'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { IonHeader,IonButton, IonList,  IonItem,IonContent, IonIcon, IonLabel, IonTitle, IonToolbar,IonInput, IonSegment, IonSegmentButton, IonSelect, IonSelectOption } from '@ionic/angular/standalone'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  import { CommonModule } from '@angular/common'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  import { FormsModule } from '@angular/forms'; // 导入 FormsModule 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  import { HttpClient } from '@angular/common/http'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { IonHeader, IonButton, IonList, IonItem, IonContent, IonIcon, IonLabel, IonTitle, IonToolbar, IonInput, IonSegment, IonSegmentButton, IonSelect, IonSelectOption } from '@ionic/angular/standalone'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { CommonModule } from '@angular/common'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { FormsModule } from '@angular/forms'; // 导入 FormsModule 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { HttpClient } from '@angular/common/http'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { CloudObject } from 'src/lib/ncloud'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { UserService } from '../user.service'; // 引入 UserService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { ToastController } from '@ionic/angular'; // 引入 ToastController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   selector: 'app-page-publishsurvey', 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -13,16 +14,15 @@ import { CloudObject } from 'src/lib/ncloud'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   styleUrls: ['./page-publishsurvey.component.scss'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   standalone: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   imports: [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    IonHeader,IonToolbar,IonTitle,IonContent,IonSegment,IonSegmentButton,IonSelect,IonSelectOption, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    FormsModule,IonList, IonItem, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    IonLabel,IonIcon,IonButton, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    IonHeader, IonToolbar, IonTitle, IonContent, IonSegment, IonSegmentButton, IonSelect, IonSelectOption, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    FormsModule, IonList, IonItem, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    IonLabel, IonIcon, IonButton, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     IonInput, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     CommonModule, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-export class PagePublishsurveyComponent  implements OnInit { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+export class PagePublishsurveyComponent implements OnInit { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   category: string = 'school'; // 默认类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   surveyTitle: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   surveyLink: string = ''; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,45 +30,106 @@ export class PagePublishsurveyComponent  implements OnInit { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   societySurveyTitle: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   societySurveyLink: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  constructor( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private router: Router, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private http: HttpClient, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private userService: UserService, // 注入 UserService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private toastController: ToastController // 注入 ToastController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ) {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   onCategoryChange() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log(`当前选择的类别: ${this.category}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  async presentToast(message: string) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const toast = await this.toastController.create({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      message: message, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      duration: 2000, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      position: 'middle' // 设置 Toast 显示位置为中间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    await toast.present(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   publishSurvey() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const currentUser = this.userService.getCurrentUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (!currentUser || !currentUser.data || currentUser.data['identity'] !== 'teacher') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log('权限不够'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.presentToast('权限不够'); // 使用 Toast 提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log('发布学校问卷:'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log(`标题: ${this.surveyTitle}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log(`链接: ${this.surveyLink}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log(`面向对象: ${this.targetAudience}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 这里可以添加逻辑将问卷发布到后端或其他处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const surveyData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       title: this.surveyTitle, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       link: this.surveyLink, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       audience: this.targetAudience, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      publisher: this.userService.getUsername(), // 添加 publisher 字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      category: this.category, // 添加 category 字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      publishtime: new Date().toISOString() // 添加 publishtime 字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let survey = new CloudObject("Survey"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    survey.set(surveyData) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    survey.save().then(data=>{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      console.log('问卷已成功发布',data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }).catch(err=>{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      console.error('发布问卷时出错'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    survey.set(surveyData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    survey.save().then(data => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log('问卷已成功发布', data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.presentToast('问卷已成功发布'); // 添加成功发布的提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.resetSchoolSurveyFields(); // 清除填写的信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }).catch(err => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.error('发布问卷时出错', err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.presentToast('发布问卷时出错'); // 添加错误提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  resetSchoolSurveyFields() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.surveyTitle = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.surveyLink = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.targetAudience = 'all'; // 重置为默认值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   publishSocietySurvey() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const currentUser = this.userService.getCurrentUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (!currentUser || !currentUser.data || currentUser.data['identity'] !== 'teacher') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log('权限不够'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.presentToast('权限不够'); // 使用 Toast 提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log('发布社会问卷:'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log(`标题: ${this.societySurveyTitle}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     console.log(`链接: ${this.societySurveyLink}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 这里可以添加逻辑将问卷发布到后端或其他处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const surveyData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      title: this.societySurveyTitle, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      link: this.societySurveyLink, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      publisher: this.userService.getUsername(), // 添加 publisher 字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      category: this.category, // 添加 category 字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      publishtime: new Date().toISOString() // 添加 publishtime 字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let survey = new CloudObject("Survey"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    survey.set(surveyData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    survey.save().then(data => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log('问卷已成功发布', data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.presentToast('问卷已成功发布'); // 添加成功发布的提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.resetSocietySurveyFields(); // 清除填写的信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }).catch(err => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.error('发布问卷时出错', err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.presentToast('发布问卷时出错'); // 添加错误提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  constructor(private router: Router,private http: HttpClient) { } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  goTab1(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.router.navigate(['tabs/page-psysurvey']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  resetSocietySurveyFields() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.societySurveyTitle = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.societySurveyLink = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  goTab1() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.router.navigate(['tabs/page-psysurvey']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ngOnInit() {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |