my.component.ts 6.0 KB

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