my.component.ts 5.1 KB

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