|
@@ -3,6 +3,7 @@ import { IonHeader, IonToolbar, IonTitle, IonContent, IonSearchbar, IonIcon, Ion
|
|
|
import { Router } from '@angular/router';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { CloudQuery, CloudObject, Pointer } from '../../lib/community_ncloud';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
|
|
|
interface Work {
|
|
|
WorkId: string;
|
|
@@ -26,15 +27,16 @@ interface Work {
|
|
|
CommonModule,
|
|
|
IonHeader, IonToolbar, IonTitle, IonContent,
|
|
|
IonSearchbar, IonIcon, IonTabButton, IonTabs, IonTabBar, IonLabel,
|
|
|
- IonMenu, IonList, IonItem, IonMenuButton
|
|
|
+ IonMenu, IonList, IonItem, IonMenuButton, FormsModule,
|
|
|
],
|
|
|
})
|
|
|
|
|
|
export class Tab3Page implements OnInit {
|
|
|
artworks: Work[] = [];
|
|
|
-
|
|
|
+ displayedArtworks: Work[] = [];
|
|
|
+ isSearchActive = false;
|
|
|
+ searchQuery = '';
|
|
|
constructor(private router: Router) { }
|
|
|
-
|
|
|
ngOnInit() {
|
|
|
this.loadWorks();
|
|
|
this.red_underline('发现');
|
|
@@ -46,25 +48,23 @@ export class Tab3Page implements OnInit {
|
|
|
const workQuery = new CloudQuery('Work');
|
|
|
const workObjs = await workQuery.find();
|
|
|
|
|
|
+
|
|
|
this.artworks = workObjs.map((workObj: CloudObject) => {
|
|
|
const workData = workObj.data as Work;
|
|
|
|
|
|
- console.log(workObj.data);
|
|
|
- console.log(workData.updatedAt);
|
|
|
- console.log(workData.fileUrl);
|
|
|
-
|
|
|
return {
|
|
|
...workData,
|
|
|
objectId: String(workObj.id),
|
|
|
- imageUrl: `${workData.fileUrl}`,
|
|
|
-
|
|
|
+ imageUrl: `${workData.fileUrl}`,
|
|
|
};
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+ this.displayedArtworks = [...this.artworks];
|
|
|
} catch (error) {
|
|
|
console.error('加载帖子数据失败:', error);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
red_underline(text: string) {
|
|
|
const prevUnderlined = document.querySelectorAll('span[underline="true"]') as NodeListOf<HTMLElement>;
|
|
|
prevUnderlined.forEach((el: HTMLElement) => {
|
|
@@ -77,98 +77,69 @@ export class Tab3Page implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- goToDetail(artId: string) {
|
|
|
- console.log('Work ID:', artId);
|
|
|
- const artwork = this.artworks.find(art => art.WorkId === artId);
|
|
|
+
|
|
|
+ onSearchIconClick() {
|
|
|
+ this.isSearchActive = !this.isSearchActive;
|
|
|
+ }
|
|
|
|
|
|
- if (artwork) {
|
|
|
- this.router.navigate(['/tabs/art-detail', artId], {
|
|
|
- state: { artwork }
|
|
|
- }).then(() => {
|
|
|
- console.log('Navigation successful');
|
|
|
- }).catch(err => {
|
|
|
- console.error('Navigation failed:', err);
|
|
|
- });
|
|
|
+
|
|
|
+ onCloseSearch() {
|
|
|
+ this.isSearchActive = false;
|
|
|
+ this.searchQuery = '';
|
|
|
+ this.displayedArtworks = [...this.artworks];
|
|
|
+ }
|
|
|
+ onSearchInput() {
|
|
|
+ if (this.searchQuery.trim()) {
|
|
|
+ this.filterPosts(this.searchQuery);
|
|
|
} else {
|
|
|
- console.warn('Artwork not found for id:', artId);
|
|
|
+ this.displayedArtworks = [...this.artworks];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- trackByFn(index: number, item: any) {
|
|
|
- return item.WorkId;
|
|
|
+
|
|
|
+
|
|
|
+ filterPosts(query: string) {
|
|
|
+
|
|
|
+ this.displayedArtworks = this.artworks.filter(artwork =>
|
|
|
+ artwork.title.toLowerCase().includes(query.toLowerCase()) ||
|
|
|
+ artwork.description.toLowerCase().includes(query.toLowerCase())
|
|
|
+ );
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-
|
|
|
-export class Tab3Page {
|
|
|
- artworks = [
|
|
|
- {
|
|
|
- id: '1',
|
|
|
- image: 'assets/img/xingkong.png',
|
|
|
- title: '梵高-星空高清画作',
|
|
|
- description: '致敬梵高 #艺术品 #星空',
|
|
|
- avatarUrl: 'assets/img/book1.png',
|
|
|
- userName: '星空艺术家',
|
|
|
- date: '12-01',
|
|
|
- likes: 1687,
|
|
|
- category: 'art'
|
|
|
- },
|
|
|
- {
|
|
|
- id: '2',
|
|
|
- image: 'assets/img/xiangrikui.png',
|
|
|
- title: '梵高《向日葵》',
|
|
|
- description: '经典中的经典,笔触很牛!',
|
|
|
- avatarUrl: 'assets/img/book2.png',
|
|
|
- userName: '艺术鉴赏家',
|
|
|
- date: '11-30',
|
|
|
- likes: 2341,
|
|
|
- category: 'art'
|
|
|
- },
|
|
|
- {
|
|
|
- id: '3',
|
|
|
- image: 'assets/img/fangao.png',
|
|
|
- title: '梵高自画像',
|
|
|
- description: '梵高生平自画像之其中🔟副👩🎨 #艺术欣赏 #美',
|
|
|
- avatarUrl: 'assets/img/book3.png',
|
|
|
- userName: '艺术探索者',
|
|
|
- date: '11-29',
|
|
|
- likes: 1892,
|
|
|
- category: 'art'
|
|
|
- },
|
|
|
- {
|
|
|
- id: '4',
|
|
|
- image: 'assets/img/cunzhuang.png',
|
|
|
- title: '阿尔小镇',
|
|
|
- description: '吧,梵高,去你最爱的阿尔看看,阿尔小镇',
|
|
|
- avatarUrl: 'assets/img/book4.png',
|
|
|
- userName: '风景画师',
|
|
|
- date: '11-28',
|
|
|
- likes: 2156,
|
|
|
- category: 'art'
|
|
|
- }
|
|
|
- ];
|
|
|
+
|
|
|
+ async loadWorkByContent(workContents: Work[]) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ const workQuery = new CloudQuery('Work');
|
|
|
|
|
|
- ngOnInit() {
|
|
|
- this.red_underline('发现');
|
|
|
-
|
|
|
- }
|
|
|
- constructor(private router: Router) { }
|
|
|
- red_underline(text: string) {
|
|
|
- const prevUnderlined = document.querySelectorAll('span[underline="true"]') as NodeListOf<HTMLElement>;
|
|
|
- prevUnderlined.forEach((el: HTMLElement) => {
|
|
|
- el.style.textDecoration = 'none';
|
|
|
- el.removeAttribute('underline');
|
|
|
- });
|
|
|
- const target = document.querySelector(`span[data-id="${text}"]`) as HTMLElement;
|
|
|
- if (target) {
|
|
|
- target.setAttribute('underline', 'true');
|
|
|
+
|
|
|
+
|
|
|
+ const workObjs = await workQuery.find();
|
|
|
+
|
|
|
+
|
|
|
+ this.artworks = workObjs.map((workObj: CloudObject) => {
|
|
|
+ const workData = workObj.data as Work;
|
|
|
+
|
|
|
+ console.log(workObj.data);
|
|
|
+ console.log(workData.updatedAt);
|
|
|
+ console.log(workData.fileUrl);
|
|
|
+
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...workData,
|
|
|
+ objectId: String(workObj.id),
|
|
|
+ imageUrl: `${workData.fileUrl}`,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载帖子数据失败:', error);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
goToDetail(artId: string) {
|
|
|
- console.log('Art ID:', artId);
|
|
|
- const artwork = this.artworks.find(art => art.id === artId);
|
|
|
+ console.log('Work ID:', artId);
|
|
|
+ const artwork = this.artworks.find(art => art.WorkId === artId);
|
|
|
|
|
|
if (artwork) {
|
|
|
this.router.navigate(['/tabs/art-detail', artId], {
|
|
@@ -182,6 +153,8 @@ export class Tab3Page {
|
|
|
console.warn('Artwork not found for id:', artId);
|
|
|
}
|
|
|
}
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ trackByFn(index: number, item: any) {
|
|
|
+ return item.WorkId;
|
|
|
+ }
|
|
|
+}
|