my.component.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import { Component, OnInit } from '@angular/core';
  2. import {
  3. IonicModule,
  4. LoadingController,
  5. ToastController,
  6. } from '@ionic/angular';
  7. import * as Parse from 'parse';
  8. import { AgreementComponent } from '../../login/agreement/agreement.component';
  9. import { AlertController, ModalController } from '@ionic/angular';
  10. import { Router } from '@angular/router';
  11. import { AuthService } from '../../../services/auth.service';
  12. import { AiChatService } from '../../../services/aichart.service';
  13. @Component({
  14. selector: 'app-my',
  15. templateUrl: './my.component.html',
  16. styleUrls: ['./my.component.scss'],
  17. standalone: true,
  18. imports: [IonicModule],
  19. })
  20. export class MyComponent implements OnInit {
  21. profile?: Parse.Object; //身份信息
  22. user: Parse.Object = Parse.User.current()!;
  23. constructor(
  24. public loadingCtrl: LoadingController,
  25. private modalController: ModalController,
  26. private alertController: AlertController,
  27. public authServ: AuthService,
  28. public toastController: ToastController,
  29. private router: Router,
  30. private aiServ: AiChatService
  31. ) {}
  32. tools: Array<{ icon: string; title: string; path: string }> = [
  33. {
  34. icon: '/img/钱包.png',
  35. title: '钱包',
  36. path: 'account/wattle',
  37. },
  38. {
  39. icon: '/img/相册.png',
  40. title: '相册',
  41. path: 'user/album',
  42. },
  43. {
  44. icon: '/img/邀请.png',
  45. title: '邀请',
  46. path: 'user/share',
  47. },
  48. {
  49. icon: '/img/设置.png',
  50. title: '设置',
  51. path: 'user/setting',
  52. },
  53. ];
  54. registerAgreement: any; //用户协议
  55. liveAgreement: any; //直播协议
  56. company: string | null = localStorage?.getItem('company');
  57. userObj: any = {
  58. fans: 0,
  59. follow: 0,
  60. friendly_degree: 0,
  61. };
  62. ngOnInit() {
  63. this.refresh();
  64. }
  65. async refresh() {
  66. this.getProfile();
  67. this.getAgreement();
  68. const data = await this.aiServ.getFansAndFollow(this.user.id);
  69. console.log(data);
  70. const { fans, follow } = data.data[0]
  71. this.userObj = { fans, follow, friendly_degree: 0 }
  72. }
  73. // 获取用户信息
  74. async getProfile() {
  75. let user = Parse.User.current();
  76. let query = new Parse.Query('Profile');
  77. query.equalTo('user', user?.id);
  78. query.notEqualTo('isDeleted', true);
  79. query.select('isCheck', 'isCross');
  80. this.profile = await query.first();
  81. }
  82. getAgreement() {
  83. let Agreement = new Parse.Query('ContractAgreement');
  84. Agreement.equalTo('company', this.company);
  85. Agreement.equalTo('type', 'register');
  86. Agreement.first().then((res) => {
  87. console.log(res);
  88. this.registerAgreement = res;
  89. });
  90. let Agreement2 = new Parse.Query('ContractAgreement');
  91. Agreement2.equalTo('company', this.company);
  92. Agreement2.equalTo('type', 'live');
  93. Agreement2.first().then((res) => {
  94. console.log(res);
  95. this.liveAgreement = res;
  96. });
  97. }
  98. async onChange(e: any) {
  99. const loading = await this.loadingCtrl.create({
  100. message: '正在修改',
  101. });
  102. loading.present();
  103. let checked = e.detail.checked;
  104. console.log(checked);
  105. if (!this.profile?.id) {
  106. let obj = Parse.Object.extend('Profile');
  107. this.profile = new obj();
  108. this.profile?.set('mobile', Parse.User.current()?.get('mobile'));
  109. this.profile?.set('user', Parse.User.current()?.toPointer());
  110. this.profile?.set('company', {
  111. __type: 'Pointer',
  112. className: 'Company',
  113. objectId: this.authServ.company,
  114. });
  115. }
  116. this.profile?.set('isCheck', checked);
  117. await this.profile?.save();
  118. loading.dismiss();
  119. const toast = await this.toastController.create({
  120. message: `已${checked ? '开启' : '关闭'}`,
  121. color: 'success',
  122. duration: 1000,
  123. });
  124. toast.present();
  125. }
  126. toUrl(url: string, params?: Object) {
  127. console.log(url);
  128. if (params) {
  129. this.router.navigate([url, Object]);
  130. } else {
  131. this.router.navigate([url]);
  132. }
  133. }
  134. async showAgreement(type: string) {
  135. if (type == 'liveAgreement' || type == 'registerAgreement') {
  136. const modal = await this.modalController.create({
  137. component: AgreementComponent,
  138. cssClass: 'my-custom-class',
  139. componentProps: {
  140. agreement: this[type],
  141. },
  142. });
  143. return await modal.present();
  144. }
  145. }
  146. /* 进入直播间 */
  147. async goRoom() {
  148. if (!this.profile?.get('isCross')) {
  149. const alert = await this.alertController.create({
  150. header: '提示',
  151. message: '你还未认证主播身份,请认证后再进入直播间',
  152. buttons: [
  153. {
  154. text: '取消',
  155. role: 'cancel',
  156. cssClass: 'secondary',
  157. handler: (blah) => {},
  158. },
  159. {
  160. text: '去认证',
  161. handler: () => {
  162. console.log('Confirm Cancel: blah');
  163. this.toUrl('/user/auchor');
  164. },
  165. },
  166. ],
  167. });
  168. await alert.present();
  169. } else {
  170. this.toUrl('/live/room-manage');
  171. }
  172. }
  173. /* 退出登录 */
  174. async onLogout() {
  175. const alert = await this.alertController.create({
  176. cssClass: 'my-custom-class',
  177. header: '',
  178. message: '你确定退出登录吗?',
  179. buttons: [
  180. {
  181. text: '确定',
  182. role: 'cancel',
  183. cssClass: 'secondary',
  184. handler: (blah) => {
  185. console.log('Confirm Cancel: blah');
  186. this.authServ.logout();
  187. },
  188. },
  189. {
  190. text: '取消',
  191. handler: () => {},
  192. },
  193. ],
  194. });
  195. await alert.present();
  196. }
  197. }