123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { AlertController, ModalController } from '@ionic/angular';
- interface KnowledgeItem {
- id: string;
- title: string;
- summary: string;
- image: string;
- type: 'article' | 'video';
- category: string;
- tag?: 'emergency' | 'prevention' | 'expert';
- duration?: string;
- isEmergency?: boolean;
- }
- interface Expert {
- id: string;
- name: string;
- avatar: string;
- specialty: string;
- isOnline: boolean;
- rating: number;
- }
- @Component({
- selector: 'app-tab2',
- templateUrl: './tab2.page.html',
- styleUrls: ['./tab2.page.scss'],
- standalone: false,
- })
- export class Tab2Page implements OnInit {
- searchQuery = '';
- isLargeFont = false;
- currentCategory = 'all';
- categories = [
- { id: 'all', name: '全部', icon: 'apps' },
- { id: 'wheat', name: '小麦', icon: 'leaf' },
- { id: 'rice', name: '水稻', icon: 'water' },
- { id: 'corn', name: '玉米', icon: 'ear' },
- { id: 'fruit', name: '果树', icon: 'nutrition' },
- ];
- onlineExperts: Expert[] = [
- {
- id: '1',
- name: '张农艺师',
- avatar: 'assets/images/expert1.jpg',
- specialty: '水稻种植专家',
- isOnline: true,
- rating: 4.8
- },
- {
- id: '2',
- name: '李研究员',
- avatar: 'assets/images/expert2.jpg',
- specialty: '果树病虫害防治',
- isOnline: true,
- rating: 4.9
- },
- {
- id: '3',
- name: '王技术员',
- avatar: 'assets/images/expert3.jpg',
- specialty: '土壤改良',
- isOnline: true,
- rating: 4.7
- }
- ];
- knowledgeList: KnowledgeItem[] = [
- {
- id: '1',
- title: '小麦赤霉病防治',
- summary: '识别赤霉病早期症状及防治方案',
- image: 'assets/images/wheat-disease.jpg',
- type: 'article',
- category: 'wheat',
- tag: 'emergency',
- isEmergency: true
- },
- {
- id: '2',
- title: '水稻科学灌溉技巧',
- summary: '不同生长阶段的水分管理要点',
- image: 'assets/images/rice-irrigation.jpg',
- type: 'article',
- category: 'rice',
- tag: 'expert',
- duration: '5分钟阅读'
- },
- {
- id: '3',
- title: '果树修剪实操指南',
- summary: '视频演示冬季修剪的正确方法',
- image: 'assets/images/fruit-pruning.jpg',
- type: 'video',
- category: 'fruit',
- duration: '12分钟'
- },
- {
- id: '4',
- title: '玉米螟虫预防措施',
- summary: '生物防治与化学防治结合方案',
- image: 'assets/images/corn-pest.jpg',
- type: 'article',
- category: 'corn',
- tag: 'prevention'
- },
- {
- id: '5',
- title: '土壤改良方法',
- summary: '酸性土壤改良的7种有效方式',
- image: 'assets/images/soil-improve.jpg',
- type: 'article',
- category: 'all',
- duration: '8分钟阅读'
- }
- ];
- filteredKnowledge: KnowledgeItem[] = [];
- constructor(
- private router: Router,
- private alertCtrl: AlertController
- ) {}
- ngOnInit() {
- this.filteredKnowledge = [...this.knowledgeList];
- }
- toggleFontSize() {
- this.isLargeFont = !this.isLargeFont;
- }
- refreshData() {
- // 模拟刷新数据
- this.filteredKnowledge = [...this.knowledgeList];
- this.searchQuery = '';
- this.currentCategory = 'all';
- }
- resetFilters() {
- this.refreshData();
- }
- onSearch() {
- if (!this.searchQuery) {
- this.filteredKnowledge = [...this.knowledgeList];
- return;
- }
- const query = this.searchQuery.toLowerCase();
- this.filteredKnowledge = this.knowledgeList.filter(item =>
- item.title.toLowerCase().includes(query) ||
- item.summary.toLowerCase().includes(query)
- );
- }
- startVoiceSearch() {
- console.log('启动语音搜索');
- // 实际应集成语音识别API
- }
- filterByCategory() {
- if (this.currentCategory === 'all') {
- this.filteredKnowledge = [...this.knowledgeList];
- } else {
- this.filteredKnowledge = this.knowledgeList.filter(
- item => item.category === this.currentCategory
- );
- }
- }
- navigateToDetail(item: KnowledgeItem) {
- this.router.navigate(['/knowledge-detail', item.id]);
- }
- getTagColor(tag: string): string {
- switch (tag) {
- case 'emergency': return 'danger';
- case 'prevention': return 'warning';
- case 'expert': return 'success';
- default: return 'primary';
- }
- }
- getTagLabel(tag: string): string {
- switch (tag) {
- case 'emergency': return '紧急';
- case 'prevention': return '预防';
- case 'expert': return '专家推荐';
- default: return '';
- }
- }
- }
|