page-publishsurvey.component_20241223214959.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Component, OnInit,NgModule } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { IonHeader,IonButton, IonContent, IonIcon, IonItem, IonLabel, IonList,
  4. IonListHeader,IonCardHeader,IonCardTitle,IonCardContent, IonTitle,IonCard, IonToolbar,IonInput,IonSearchbar, IonSegment, IonSegmentButton, IonSelect, IonSelectOption } from '@ionic/angular/standalone';
  5. import { CommonModule } from '@angular/common';
  6. import { FormsModule } from '@angular/forms';
  7. import { HttpClient } from '@angular/common/http';
  8. @Component({
  9. selector: 'app-page-publishsurvey',
  10. templateUrl: './page-publishsurvey.component.html',
  11. styleUrls: ['./page-publishsurvey.component.scss'],
  12. standalone: true,
  13. imports: [
  14. IonHeader,IonToolbar,IonTitle,IonContent,IonSegment,IonSegmentButton,IonSelect,IonSelectOption,
  15. IonList,IonListHeader,IonItem,IonCardTitle,HttpClient,
  16. IonLabel,IonIcon,IonButton,IonCardContent,
  17. IonInput,IonSearchbar,IonCard,IonCardHeader,
  18. CommonModule,FormsModule
  19. ]
  20. })
  21. export class PagePublishsurveyComponent implements OnInit {
  22. category: string = 'school'; // 默认类别
  23. surveyTitle: string = '';
  24. surveyLink: string = '';
  25. targetAudience: string = 'all'; // 默认面向对象
  26. // societySurveyTitle: string = '';
  27. // societySurveyLink: string = '';
  28. onCategoryChange() {
  29. console.log(`当前选择的类别: ${this.category}`);
  30. }
  31. publishSurvey() {
  32. console.log('发布学校问卷:');
  33. console.log(`标题: ${this.surveyTitle}`);
  34. console.log(`链接: ${this.surveyLink}`);
  35. console.log(`面向对象: ${this.targetAudience}`);
  36. // 这里可以添加逻辑将问卷发布到后端或其他处理
  37. const surveyData = {
  38. title: this.surveyTitle,
  39. link: this.surveyLink,
  40. audience: this.targetAudience,
  41. };
  42. this.http.post('http://127.0.0.1:4040/apps/DevServer/browser/survey', surveyData).subscribe(
  43. response => {
  44. console.log('问卷已成功发布:', response);
  45. // 发布成功后可以导航到心理普查页面
  46. this.router.navigate(['tabs/psysurvey']);
  47. },
  48. error => {
  49. console.error('发布问卷时出错:', error);
  50. }
  51. );
  52. }
  53. // publishSocietySurvey() {
  54. // console.log('发布社会问卷:');
  55. // console.log(`标题: ${this.societySurveyTitle}`);
  56. // console.log(`链接: ${this.societySurveyLink}`);
  57. // 这里可以添加逻辑将问卷发布到后端或其他处理
  58. // }
  59. constructor(private router: Router,private http: HttpClient) { }
  60. goTab1(){
  61. this.router.navigate(['tabs/tab1']);
  62. }
  63. ngOnInit() {}
  64. }