|
@@ -1,4 +1,4 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
import { IonicModule } from '@ionic/angular';
|
|
@@ -8,7 +8,7 @@ import { bookmarkOutline, cartOutline, documentTextOutline, downloadOutline, ell
|
|
|
import { EnvironmentInjector, inject } from '@angular/core';
|
|
|
import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
|
|
|
import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
|
|
|
-import { CloudUser } from 'src/lib/ncloud';
|
|
|
+import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
import { ModalController } from '@ionic/angular/standalone';
|
|
|
import { AlertController } from '@ionic/angular/standalone'; // 导入所需的模块
|
|
|
|
|
@@ -19,18 +19,16 @@ import { AlertController } from '@ionic/angular/standalone'; // 导入所需的
|
|
|
standalone: true,
|
|
|
imports: [ExploreContainerComponent, IonicModule, CommonModule],
|
|
|
})
|
|
|
-export class Tab3Page {
|
|
|
+export class Tab3Page implements OnInit{
|
|
|
profile = {
|
|
|
- // name: 'X',
|
|
|
- // level: 'X',
|
|
|
vipStatus: true,
|
|
|
avatar: '../../assets/image/07/1.jpg', // 默认头像路径
|
|
|
- buttons: [
|
|
|
- { icon: 'time-outline', text: '浏览记录' },
|
|
|
- { icon: 'download-outline', text: '我的下载' },
|
|
|
- { icon: 'cart-outline', text: '我的购买' },
|
|
|
- { icon: 'wallet-outline', text: '我的钱包' }
|
|
|
- ],
|
|
|
+ // buttons: [
|
|
|
+ // { icon: 'time-outline', text: '浏览记录' },
|
|
|
+ // { icon: 'download-outline', text: '我的下载' },
|
|
|
+ // { icon: 'cart-outline', text: '我的购买' },
|
|
|
+ // { icon: 'wallet-outline', text: '我的钱包' }
|
|
|
+ // ],
|
|
|
tabs: [
|
|
|
{ icon: 'images-outline', text: '全部' },
|
|
|
{ icon: 'image-outline', text: '图文' },
|
|
@@ -43,7 +41,10 @@ export class Tab3Page {
|
|
|
public environmentInjector = inject(EnvironmentInjector);
|
|
|
|
|
|
currentUser: CloudUser | undefined;
|
|
|
-
|
|
|
+ // 创建用于存储喜欢或收藏的文章内容的属性
|
|
|
+ favoriteOrLikedContents: Array<CloudObject> = [];
|
|
|
+ error:string|null = null;
|
|
|
+ loading: boolean = false;
|
|
|
constructor(
|
|
|
private router: Router,
|
|
|
private alertController: AlertController,
|
|
@@ -59,31 +60,90 @@ export class Tab3Page {
|
|
|
toggleTabs(action: string) {
|
|
|
this.showTabs = !this.showTabs;
|
|
|
if (action === 'like') {
|
|
|
- this.setActiveTab('all');
|
|
|
+ this.setActiveTab('like'); // 设置为 'like'
|
|
|
} else if (action === 'collect') {
|
|
|
- this.setActiveTab('collect'); // 假设有一个收藏选项卡
|
|
|
+ this.setActiveTab('collect'); // 设置为 'collect'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ // 生命周期
|
|
|
+ this.loadPLContentsList();
|
|
|
+ if(this.currentUser?.id){
|
|
|
+ this.loadFavoriteOrLikedContents(this.currentUser.id);
|
|
|
+ }else {
|
|
|
+ console.log('未登录');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 创建用于数据列表存储的属性
|
|
|
+ PLContentsList:Array<CloudObject> = []
|
|
|
+
|
|
|
+ async loadPLContentsList(){
|
|
|
+ let query = new CloudQuery("PL_Contents");
|
|
|
+ this.PLContentsList = await query.find()
|
|
|
+ }
|
|
|
setActiveTab(tab: string | null) {
|
|
|
this.activeTab = tab;
|
|
|
this.updateContent();
|
|
|
}
|
|
|
|
|
|
+ updateContent() {
|
|
|
+ const contentContainer = document.getElementById('content-container');
|
|
|
+ if (!contentContainer) return;
|
|
|
+
|
|
|
+ if (!this.showTabs || this.activeTab === null) {
|
|
|
+ contentContainer.innerHTML = '';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第一次筛选:根据 like 和 favorite 进行筛选
|
|
|
+ let filteredContents: CloudObject[] = [];
|
|
|
+ switch (this.activeTab) {
|
|
|
+ case 'like':
|
|
|
+ filteredContents = this.favoriteOrLikedContents.filter(content => content.get('is_liked') === true);
|
|
|
+ break;
|
|
|
+ case 'collect':
|
|
|
+ filteredContents = this.favoriteOrLikedContents.filter(content => content.get('is_favorite') === true);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ filteredContents = this.favoriteOrLikedContents;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二次筛选:根据 all、image 和 document 进行进一步的筛选
|
|
|
+ switch (this.activeTab) {
|
|
|
+ case 'all':
|
|
|
+ // 不需要进一步筛选,保持 filteredContents 不变
|
|
|
+ break;
|
|
|
+ case 'image':
|
|
|
+ filteredContents = filteredContents.filter(content => content.get('type') === '图文');
|
|
|
+ break;
|
|
|
+ case 'document':
|
|
|
+ filteredContents = filteredContents.filter(content => content.get('type') === '故诗');
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 渲染内容
|
|
|
+ if (filteredContents.length > 0) {
|
|
|
+ contentContainer.innerHTML = filteredContents.map(content => `
|
|
|
+ <div class="content-item">
|
|
|
+ <h2>${content.get('title')}</h2>
|
|
|
+ <p>${content.get('snippet')}</p>
|
|
|
+ <p>类型: ${content.get('type')}</p>
|
|
|
+ <p>发布时间: ${content.get('time')}</p>
|
|
|
+ <img src="${content.get('image')}" alt="${content.get('title')} 图片" />
|
|
|
+ </div>
|
|
|
+ `).join('');
|
|
|
+ } else {
|
|
|
+ contentContainer.innerHTML = `<p>暂时还没有相关内容呢,快去添加吧。</p>`;
|
|
|
+ }
|
|
|
+ }
|
|
|
navigateToLogin() {
|
|
|
this.router.navigate(['/tabs/login']);
|
|
|
}
|
|
|
|
|
|
- // editName() {
|
|
|
- // const newName = prompt("请输入新的名字", this.profile.name); // 仅示例
|
|
|
- // if (newName) {
|
|
|
- // this.profile.name = newName;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
openVipPage() {
|
|
|
- // 这里可以添加逻辑来导航到VIP开通页面
|
|
|
- alert("导航到VIP开通页面");
|
|
|
+ alert("不允许你花钱!!!");
|
|
|
}
|
|
|
|
|
|
onFileSelected(event: Event) {
|
|
@@ -121,7 +181,11 @@ export class Tab3Page {
|
|
|
}
|
|
|
|
|
|
editUser() {
|
|
|
- openUserEditModal(this.modalCtrl);
|
|
|
+ if (this.currentUser) {
|
|
|
+ openUserEditModal(this.modalCtrl); // 假设 modalCtrl 内部会处理 currentUser
|
|
|
+ } else {
|
|
|
+ console.error("未登录,无法执行此操作");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
editTags: Array<string> = [];
|
|
@@ -149,32 +213,34 @@ export class Tab3Page {
|
|
|
|
|
|
await alert.present(); // 显示提示框
|
|
|
}
|
|
|
-
|
|
|
- updateContent() {
|
|
|
- const contentContainer = document.getElementById('content-container');
|
|
|
- if (!contentContainer) return;
|
|
|
-
|
|
|
- switch (this.activeTab) {
|
|
|
- case 'all':
|
|
|
- contentContainer.innerHTML = `
|
|
|
- <h2>全部内容</h2>
|
|
|
- <p>这里是全部内容的详细信息。</p>
|
|
|
- `;
|
|
|
- break;
|
|
|
- case 'image':
|
|
|
- contentContainer.innerHTML = `
|
|
|
- <h2>图文内容</h2>
|
|
|
- <p>这里是图文内容的详细信息。</p>
|
|
|
- `;
|
|
|
- break;
|
|
|
- case 'document':
|
|
|
- contentContainer.innerHTML = `
|
|
|
- <h2>文章内容</h2>
|
|
|
- <p>这里是文章内容的详细信息。</p>
|
|
|
- `;
|
|
|
- break;
|
|
|
- default:
|
|
|
- contentContainer.innerHTML = ''; // 默认情况下清空内容
|
|
|
+ async loadFavoriteOrLikedContents(userId: string) {
|
|
|
+ try {
|
|
|
+ this.loading = true;
|
|
|
+ let query = new CloudQuery("PL_UserRelation");
|
|
|
+ query.equalTo('user_id', userId); // 根据用户ID查询
|
|
|
+ const subQuery1 = new CloudQuery("PL_UserRelation");
|
|
|
+ subQuery1.equalTo('is_favorite', true);
|
|
|
+ const subQuery2 = new CloudQuery("PL_UserRelation");
|
|
|
+ subQuery2.equalTo('is_liked', true);
|
|
|
+ query.or(subQuery1, subQuery2); // 查询 is_favorite 或 is_like 为 true 的记录
|
|
|
+ const userRelations = await query.find();
|
|
|
+ console.log('User relations:', userRelations);
|
|
|
+
|
|
|
+ // 获取所有符合条件的 article_id
|
|
|
+ const articleIds = userRelations.map((relation: CloudObject) => relation.get('article_id'));
|
|
|
+
|
|
|
+ // 根据 article_id 查询 PL_Contents 表
|
|
|
+ if (articleIds.length > 0) {
|
|
|
+ let contentQuery = new CloudQuery("PL_Contents");
|
|
|
+ contentQuery.containedIn('objectId', articleIds); // 使用 containedIn 查询多个 article_id
|
|
|
+ this.favoriteOrLikedContents = await contentQuery.find();
|
|
|
+ console.log('Favorite or liked contents:', this.favoriteOrLikedContents);
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ this.error = '加载喜欢或收藏的内容时出错';
|
|
|
+ console.error(err);
|
|
|
+ } finally {
|
|
|
+ this.loading = false;
|
|
|
}
|
|
|
}
|
|
|
}
|