add-frends.page.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { Component, OnInit } from '@angular/core';
  2. import { AlertController } from '@ionic/angular';
  3. import {SharedService} from 'src/modules/user/service-user/Share.service'
  4. import { Router } from '@angular/router';
  5. import {NavController } from '@ionic/angular';
  6. import * as Parse from "parse"
  7. (Parse as any).serverURL = "https://web2023.fmode.cn/parse"
  8. Parse.initialize("dev")
  9. @Component({
  10. selector: 'app-add-frends',
  11. templateUrl: './add-frends.page.html',
  12. styleUrls: ['./add-frends.page.scss'],
  13. })
  14. export class AddFrendsPage implements OnInit {
  15. public userInput:string='';
  16. cares :any = [];
  17. search:any={
  18. userId:'',
  19. usename:'',
  20. userImg:''
  21. };
  22. careUsername:any=''
  23. public ifSearch:boolean=false;
  24. userId:any=''
  25. ngOnInit() {
  26. this.findMyCare()
  27. }
  28. constructor(private navCtrl:NavController,private sharedService: SharedService,private router:Router,private alertCtrl:AlertController){
  29. this.userId=this.sharedService.getUserId()
  30. // findMyCare(this.userId,this.cares)
  31. // console.log(this.cares)
  32. }
  33. goAiChatPage(){
  34. this.router.navigate(["/pocket-local/social-interactions/ai-chat-page"],{
  35. })
  36. }
  37. goChatPage(spot:Parse.Object){
  38. this.router.navigate(["/pocket-local/social-interactions/chat-page"],{
  39. queryParams:spot
  40. })
  41. }
  42. async findMyCare() {
  43. const GzpCare = Parse.Object.extend('GzpCare');
  44. const query = new Parse.Query(GzpCare);
  45. query.equalTo("userId", this.userId);
  46. try {
  47. const Cares = await query.find();
  48. for (const care of Cares) {
  49. this.cares.push({
  50. careUserId:care.get("careUserId"),
  51. careUsername:care.get('careUsername'),
  52. careUserImg:"http://q1.qlogo.cn/g?b=qq&nk="+care.get("careUserId")+"&s=100"
  53. })
  54. }
  55. } catch (error) {
  56. console.error("查询消息时出错:", error);
  57. }
  58. }
  59. async searchCare(){
  60. const GzpUser = Parse.Object.extend('GzpUser');
  61. const query = new Parse.Query(GzpUser);
  62. query.equalTo("userId", this.userInput);
  63. try{
  64. const Search = await query.find();
  65. this.careUsername=Search[0].get("username"),
  66. this.search={
  67. userId:Search[0].get("userId"),
  68. username:Search[0].get("username"),
  69. userImg:"http://q1.qlogo.cn/g?b=qq&nk="+Search[0].get("userId")+"&s=100",
  70. }
  71. this.ifSearch=true
  72. }catch(error){
  73. const alert = await this.alertCtrl.create({
  74. header: '查询错误',
  75. subHeader: '没有找到该用户',
  76. buttons: ['好的'],
  77. });
  78. await alert.present();
  79. }
  80. console.log(this.search)
  81. }
  82. backNoSearvh(){
  83. this.ifSearch=false
  84. }
  85. async careThis(){
  86. if(this.userId!=null){
  87. const GzpCare = Parse.Object.extend('GzpCare');
  88. const carethis = new GzpCare();
  89. carethis.set("userId",this.userId);
  90. carethis.set("careUserId",this.userInput);
  91. carethis.set("careUsername",this.careUsername);
  92. carethis.save();
  93. }
  94. const alert = await this.alertCtrl.create({
  95. header: '添加成功',
  96. subHeader: '该用户已成为你的关注用户',
  97. buttons: ['好的'],
  98. });
  99. await alert.present();
  100. this.ifSearch=false
  101. this.cares=[]
  102. this.findMyCare()
  103. }
  104. async noCareThis(care: any) {
  105. if (this.userId != null) {
  106. const GzpCare = Parse.Object.extend('GzpCare');
  107. const query = new Parse.Query(GzpCare);
  108. query.equalTo("userId", this.userId);
  109. query.equalTo("careUserId", care.careUserId);
  110. query.equalTo("careUsername", care.careUsername);
  111. const noCare = await query.find();
  112. for (const obj of noCare) {
  113. await obj.destroy();
  114. }
  115. const alert = await this.alertCtrl.create({
  116. header: '取关成功',
  117. subHeader: '该用户已不是你的关注用户',
  118. buttons: ['好的'],
  119. });
  120. await alert.present();
  121. this.cares=[]
  122. this.findMyCare()
  123. }
  124. }
  125. back(){
  126. this.navCtrl.back()
  127. }
  128. }