tab3.page.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { Component } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { ExploreContainerComponent } from '../explore-container/explore-container.component';
  4. import { IonicModule } from '@ionic/angular';
  5. import { CommonModule } from '@angular/common';
  6. import { addIcons } from 'ionicons';
  7. import { bookmarkOutline, cartOutline, documentTextOutline, downloadOutline, ellipsisHorizontal, heartOutline, imageOutline, imagesOutline, search, timeOutline, walletOutline } from 'ionicons/icons';
  8. import { EnvironmentInjector, inject } from '@angular/core';
  9. import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
  10. import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
  11. import { CloudUser } from 'src/lib/ncloud';
  12. import { ModalController } from '@ionic/angular/standalone';
  13. import { AlertController } from '@ionic/angular/standalone'; // 导入所需的模块
  14. @Component({
  15. selector: 'app-tab3',
  16. templateUrl: 'tab3.page.html',
  17. styleUrls: ['tab3.page.scss'],
  18. standalone: true,
  19. imports: [ExploreContainerComponent, IonicModule, CommonModule],
  20. })
  21. export class Tab3Page {
  22. profile = {
  23. // name: 'X',
  24. // level: 'X',
  25. vipStatus: true,
  26. avatar: '../../assets/image/07/1.jpg', // 默认头像路径
  27. buttons: [
  28. { icon: 'time-outline', text: '浏览记录' },
  29. { icon: 'download-outline', text: '我的下载' },
  30. { icon: 'cart-outline', text: '我的购买' },
  31. { icon: 'wallet-outline', text: '我的钱包' }
  32. ],
  33. tabs: [
  34. { icon: 'images-outline', text: '全部' },
  35. { icon: 'image-outline', text: '图文' },
  36. { icon: 'document-text-outline', text: '文章' }
  37. ]
  38. };
  39. showTabs = false;
  40. activeTab: string | null = null; // 初始状态为null
  41. public environmentInjector = inject(EnvironmentInjector);
  42. currentUser: CloudUser | undefined;
  43. constructor(
  44. private router: Router,
  45. private alertController: AlertController,
  46. private modalCtrl: ModalController
  47. ) {
  48. this.currentUser = new CloudUser();
  49. addIcons({
  50. search, ellipsisHorizontal, timeOutline, downloadOutline, cartOutline, walletOutline,
  51. heartOutline, bookmarkOutline, imageOutline, imagesOutline, documentTextOutline
  52. });
  53. }
  54. toggleTabs(action: string) {
  55. this.showTabs = !this.showTabs;
  56. if (action === 'like') {
  57. this.setActiveTab('all');
  58. } else if (action === 'collect') {
  59. this.setActiveTab('collect'); // 假设有一个收藏选项卡
  60. }
  61. }
  62. setActiveTab(tab: string | null) {
  63. this.activeTab = tab;
  64. this.updateContent();
  65. }
  66. navigateToLogin() {
  67. this.router.navigate(['/tabs/login']);
  68. }
  69. // editName() {
  70. // const newName = prompt("请输入新的名字", this.profile.name); // 仅示例
  71. // if (newName) {
  72. // this.profile.name = newName;
  73. // }
  74. // }
  75. openVipPage() {
  76. // 这里可以添加逻辑来导航到VIP开通页面
  77. alert("导航到VIP开通页面");
  78. }
  79. onFileSelected(event: Event) {
  80. const input = event.target as HTMLInputElement;
  81. if (input.files && input.files[0]) {
  82. const file = input.files[0];
  83. const reader = new FileReader();
  84. reader.onload = (e: any) => {
  85. this.profile.avatar = e.target.result; // 将读取的图片设置为头像
  86. };
  87. reader.readAsDataURL(file); // 读取文件为Data URL
  88. }
  89. }
  90. async login() {
  91. // 弹出登录窗口
  92. let user = await openUserLoginModal(this.modalCtrl);
  93. if (user?.id) {
  94. this.currentUser = user;
  95. }
  96. }
  97. async signup() {
  98. // 弹出注册窗口
  99. let user = await openUserLoginModal(this.modalCtrl, "signup");
  100. if (user?.id) {
  101. this.currentUser = user;
  102. }
  103. }
  104. logout() {
  105. this.currentUser?.logout();
  106. }
  107. editUser() {
  108. openUserEditModal(this.modalCtrl);
  109. }
  110. editTags: Array<string> = [];
  111. async setTagsValue(ev: any) {
  112. let currentUser = new CloudUser();
  113. let userPrompt = ``;
  114. if (!currentUser?.id) {
  115. console.log("用户未登录,请登录后重试");
  116. let user = await openUserLoginModal(this.modalCtrl);
  117. if (!user?.id) {
  118. return;
  119. }
  120. currentUser = user;
  121. }
  122. this.editTags = ev;
  123. }
  124. async showAlert() {
  125. const alert = await this.alertController.create({
  126. header: '提示', // 提示框的标题
  127. message: '请先登录以查看个人信息。', // 提示框的消息
  128. buttons: ['确定'], // 按钮文本,用户点击后关闭提示框
  129. });
  130. await alert.present(); // 显示提示框
  131. }
  132. updateContent() {
  133. const contentContainer = document.getElementById('content-container');
  134. if (!contentContainer) return;
  135. switch (this.activeTab) {
  136. case 'all':
  137. contentContainer.innerHTML = `
  138. <h2>全部内容</h2>
  139. <p>这里是全部内容的详细信息。</p>
  140. `;
  141. break;
  142. case 'image':
  143. contentContainer.innerHTML = `
  144. <h2>图文内容</h2>
  145. <p>这里是图文内容的详细信息。</p>
  146. `;
  147. break;
  148. case 'document':
  149. contentContainer.innerHTML = `
  150. <h2>文章内容</h2>
  151. <p>这里是文章内容的详细信息。</p>
  152. `;
  153. break;
  154. default:
  155. contentContainer.innerHTML = ''; // 默认情况下清空内容
  156. }
  157. }
  158. }