|
@@ -1,11 +1,133 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+// image-search.ts
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
|
|
+import {
|
|
|
+ faArrowLeft,
|
|
|
+ faSearch,
|
|
|
+ faHistory,
|
|
|
+ faCompass,
|
|
|
+ faFire,
|
|
|
+ faUtensils,
|
|
|
+ faTags,
|
|
|
+ faTimes
|
|
|
+} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-image-search',
|
|
|
- imports: [],
|
|
|
+ standalone: true,
|
|
|
+ imports: [CommonModule, FormsModule, FontAwesomeModule],
|
|
|
templateUrl: './image-search.html',
|
|
|
- styleUrl: './image-search.scss'
|
|
|
+ styleUrls: ['./image-search.scss']
|
|
|
})
|
|
|
-export class ImageSearch {
|
|
|
+export class ImageSearchComponent implements OnInit {
|
|
|
+ // FontAwesome 图标
|
|
|
+ faArrowLeft = faArrowLeft;
|
|
|
+ faSearch = faSearch;
|
|
|
+ faHistory = faHistory;
|
|
|
+ faCompass = faCompass;
|
|
|
+ faFire = faFire;
|
|
|
+ faUtensils = faUtensils;
|
|
|
+ faTags = faTags;
|
|
|
+ faTimes = faTimes;
|
|
|
|
|
|
-}
|
|
|
+ searchInput = '';
|
|
|
+ searchHistory: string[] = [];
|
|
|
+
|
|
|
+ // 搜索发现项
|
|
|
+ discoveryItems = [
|
|
|
+ '美食摄影', '中餐高清', '食材特写', '饮品素材',
|
|
|
+ '节日美食', '菜单设计', '火锅图片', '菜品展示'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 大家都在搜
|
|
|
+ popularSearches = [
|
|
|
+ { keyword: '高级料理图片素材', tag: '热' },
|
|
|
+ { keyword: '夏日饮品视觉素材', tag: '新' },
|
|
|
+ { keyword: '美食摄影技巧', tag: '' },
|
|
|
+ { keyword: '中餐厅投影素材', tag: '' },
|
|
|
+ { keyword: '食物特写高清', tag: '' }
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 美食热搜
|
|
|
+ foodTrends = [
|
|
|
+ { keyword: '火锅美食素材包', tag: '爆' },
|
|
|
+ { keyword: '甜品视觉图集', tag: '' },
|
|
|
+ { keyword: '海鲜大餐高清', tag: '' },
|
|
|
+ { keyword: '中式点心素材', tag: '' },
|
|
|
+ { keyword: '西餐摆盘艺术', tag: '' }
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 热门分类
|
|
|
+ categories = ['中餐', '西餐', '日料', '甜点', '饮品', '烧烤', '海鲜', '素食'];
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.loadSearchHistory();
|
|
|
+ }
|
|
|
+
|
|
|
+ loadSearchHistory() {
|
|
|
+ const history = localStorage.getItem('foodSearchHistory');
|
|
|
+ this.searchHistory = history ? JSON.parse(history) : [];
|
|
|
+ }
|
|
|
+
|
|
|
+ backAction() {
|
|
|
+ // 实际应用中这里应该是 router.navigate 或其他导航逻辑
|
|
|
+ alert('返回上一页面');
|
|
|
+ }
|
|
|
+
|
|
|
+ clearHistory() {
|
|
|
+ if (this.searchHistory.length === 0) return;
|
|
|
+
|
|
|
+ if (confirm('确定要清空所有搜索历史吗?')) {
|
|
|
+ this.searchHistory = [];
|
|
|
+ localStorage.removeItem('foodSearchHistory');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ deleteHistoryItem(index: number) {
|
|
|
+ this.searchHistory.splice(index, 1);
|
|
|
+ localStorage.setItem('foodSearchHistory', JSON.stringify(this.searchHistory));
|
|
|
+ }
|
|
|
+
|
|
|
+ performSearch(query: string) {
|
|
|
+ if (!query.trim()) return;
|
|
|
+
|
|
|
+ // 添加到历史记录
|
|
|
+ if (!this.searchHistory.includes(query)) {
|
|
|
+ this.searchHistory.unshift(query);
|
|
|
+ // 最多保留10条记录
|
|
|
+ if (this.searchHistory.length > 10) {
|
|
|
+ this.searchHistory.pop();
|
|
|
+ }
|
|
|
+ localStorage.setItem('foodSearchHistory', JSON.stringify(this.searchHistory));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行搜索(模拟)
|
|
|
+ alert(`正在搜索: ${query}\n将显示相关美食图片素材`);
|
|
|
+ }
|
|
|
+
|
|
|
+ onSearch() {
|
|
|
+ this.performSearch(this.searchInput.trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ onDiscoveryClick(item: string) {
|
|
|
+ this.searchInput = item;
|
|
|
+ this.performSearch(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ onPopularSearchClick(item: { keyword: string }) {
|
|
|
+ this.searchInput = item.keyword;
|
|
|
+ this.performSearch(item.keyword);
|
|
|
+ }
|
|
|
+
|
|
|
+ onFoodTrendClick(item: { keyword: string }) {
|
|
|
+ this.searchInput = item.keyword;
|
|
|
+ this.performSearch(item.keyword);
|
|
|
+ }
|
|
|
+
|
|
|
+ onCategoryClick(category: string) {
|
|
|
+ this.searchInput = `${category}图片素材`;
|
|
|
+ this.performSearch(`${category}图片素材`);
|
|
|
+ }
|
|
|
+}
|