|
@@ -1,11 +1,11 @@
|
|
|
import { Component, NgModule } from '@angular/core';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
-import { DomSanitizer } from '@angular/platform-browser';
|
|
|
+import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
|
|
|
|
|
-interface home {
|
|
|
+interface Home {
|
|
|
name: string;
|
|
|
description: string;
|
|
|
- image: string;
|
|
|
+ imageUrl: string;
|
|
|
}
|
|
|
|
|
|
@Component({
|
|
@@ -14,58 +14,62 @@ interface home {
|
|
|
styleUrls: ['./home.component.scss']
|
|
|
})
|
|
|
export class HomeComponent {
|
|
|
- homes: home[] = [
|
|
|
+ homes: Home[] = [
|
|
|
{
|
|
|
name: 'Digital Collectible 1',
|
|
|
description: 'This is the first digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible1.jpg'
|
|
|
+ imageUrl: 'https://example.com/digital-collectible1.jpg'
|
|
|
},
|
|
|
{
|
|
|
name: 'Digital Collectible 2',
|
|
|
description: 'This is the second digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-2.jpg'
|
|
|
+ imageUrl: 'https://example.com/digital-collectible-2.jpg'
|
|
|
},
|
|
|
{
|
|
|
name: 'Digital Collectible 3',
|
|
|
description: 'This is the third digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-3.jpg'
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Digital Collectible 4',
|
|
|
- description: 'This is the third digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-3.jpg'
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Digital Collectible 5',
|
|
|
- description: 'This is the third digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-3.jpg'
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Digital Collectible 6',
|
|
|
- description: 'This is the third digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-3.jpg'
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Digital Collectible 3',
|
|
|
- description: 'This is the third digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-3.jpg'
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Digital Collectible 4',
|
|
|
- description: 'This is the third digital collectible.',
|
|
|
- image: 'https://example.com/digital-collectible-3.jpg'
|
|
|
+ imageUrl: 'https://example.com/digital-collectible-3.jpg'
|
|
|
},
|
|
|
// 添加更多的数字藏品数据...
|
|
|
];
|
|
|
+ itemList: Home[] = []; // 初始化物品列表为空
|
|
|
sanitizer: DomSanitizer;
|
|
|
|
|
|
constructor(private _sanitizer: DomSanitizer) {
|
|
|
- this.sanitizer = _sanitizer;}
|
|
|
+ this.sanitizer = _sanitizer as DomSanitizer;
|
|
|
+ this.showItemList('推荐'); // 默认显示推荐物品列表
|
|
|
+ }
|
|
|
+
|
|
|
+ getSafeImageUrl(url: string): SafeResourceUrl {
|
|
|
+ return this.sanitizer.bypassSecurityTrustResourceUrl(url);
|
|
|
+ }
|
|
|
|
|
|
+ showItemList(type: string) {
|
|
|
+ if (type === '热门') {
|
|
|
+ // 通过你的自定义逻辑获取热门物品列表
|
|
|
+ this.itemList = this.homes.filter(home => {
|
|
|
+ // 这里可以根据需要筛选出对应类型的物品
|
|
|
+ return home.name === 'Digital Collectible 1' || home.name === 'Digital Collectible 2';
|
|
|
+ });
|
|
|
+ } else if (type === '推荐') {
|
|
|
+ // 通过你的自定义逻辑获取推荐物品列表
|
|
|
+ this.itemList = this.homes.filter(home => {
|
|
|
+ // 这里可以根据需要筛选出对应类型的物品
|
|
|
+ return home.name === 'Digital Collectible 1' || home.name === 'Digital Collectible 3';
|
|
|
+ });
|
|
|
+ } else if (type === '活动') {
|
|
|
+ // 通过你的自定义逻辑获取活动物品列表
|
|
|
+ this.itemList = this.homes.filter(home => {
|
|
|
+ // 这里可以根据需要筛选出对应类型的物品
|
|
|
+ return home.name === 'Digital Collectible 2' || home.name === 'Digital Collectible 3';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@NgModule({
|
|
|
imports: [CommonModule],
|
|
|
- declarations: [HomeComponent]
|
|
|
+ declarations: [HomeComponent],
|
|
|
+ exports: [HomeComponent]
|
|
|
})
|
|
|
export class HomeModule { }
|