image-detail.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Component, OnInit } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { FormsModule } from '@angular/forms';
  4. // 导入 Swiper 11 相关模块
  5. import { register } from 'swiper/element/bundle';
  6. import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
  7. @Component({
  8. selector: 'app-image-detail',
  9. standalone: true,
  10. imports: [CommonModule, FormsModule],
  11. templateUrl: './image-detail.html',
  12. styleUrls: ['./image-detail.scss'],
  13. schemas: [CUSTOM_ELEMENTS_SCHEMA] // 允许使用自定义元素
  14. })
  15. export class ImageDetailComponent implements OnInit {
  16. // 轮播图配置
  17. swiperConfig = JSON.stringify({
  18. pagination: {
  19. clickable: true,
  20. type: 'bullets',
  21. },
  22. loop: true,
  23. autoplay: {
  24. delay: 5000,
  25. disableOnInteraction: false
  26. },
  27. effect: 'fade',
  28. fadeEffect: {
  29. crossFade: true
  30. }
  31. });
  32. // 轮播图数据
  33. slides = [
  34. {
  35. url: 'https://images.unsplash.com/photo-1565299624946-b28f40a0ae38?auto=format&fit=crop&w=800&q=80',
  36. alt: '美味披萨'
  37. },
  38. {
  39. url: 'https://images.unsplash.com/photo-1565958011703-44f9829ba187?auto=format&fit=crop&w=800&q=80',
  40. alt: '披萨制作过程'
  41. },
  42. {
  43. url: 'https://images.unsplash.com/photo-1513104890138-7c749659a591?auto=format&fit=crop&w=800&q=80',
  44. alt: '披萨特写'
  45. }
  46. ];
  47. // 图片详情数据
  48. imageDetail = {
  49. title: '意式玛格丽特披萨',
  50. meta: [
  51. { icon: 'fas fa-camera', text: '专业美食摄影' },
  52. { icon: 'fas fa-image', text: '高分辨率 (4000×3000)' },
  53. { icon: 'fas fa-tags', text: '意大利料理, 披萨' }
  54. ],
  55. stats: [
  56. { value: '1,258', label: '下载量' },
  57. { value: '4.9', label: '用户评分' },
  58. { value: '96%', label: '推荐度' }
  59. ],
  60. price: '¥ 38.00'
  61. };
  62. // 摄影师数据
  63. photographer = {
  64. name: '张明轩',
  65. title: '专业美食摄影师 | 8年经验',
  66. avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?auto=format&fit=crop&w=200&q=80',
  67. isFollowing: false
  68. };
  69. // 相关推荐数据
  70. relatedItems = [
  71. {
  72. image: 'https://images.unsplash.com/photo-1552539618-7eec9b4d1796?auto=format&fit=crop&w=400&q=80',
  73. name: '番茄肉酱意面',
  74. price: '¥ 32.00'
  75. },
  76. {
  77. image: 'https://images.unsplash.com/photo-1606491956689-2ea866880c84?auto=format&fit=crop&w=400&q=80',
  78. name: '凯撒沙拉',
  79. price: '¥ 28.00'
  80. },
  81. {
  82. image: 'https://images.unsplash.com/photo-1551183053-bf91a1d81141?auto=format&fit=crop&w=400&q=80',
  83. name: '提拉米苏',
  84. price: '¥ 25.00'
  85. },
  86. {
  87. image: 'https://images.unsplash.com/photo-1513104890138-7c749659a591?auto=format&fit=crop&w=400&q=80',
  88. name: '四芝士披萨',
  89. price: '¥ 42.00'
  90. }
  91. ];
  92. isFavorite = false;
  93. ngOnInit(): void {
  94. // 初始化代码可以放在这里
  95. }
  96. // 图片操作功能
  97. handleAction(iconType: string): void {
  98. let message = '';
  99. switch(iconType) {
  100. case 'expand':
  101. message = '图片已全屏展示';
  102. break;
  103. case 'share':
  104. message = '分享功能已激活';
  105. break;
  106. case 'download':
  107. message = '开始下载高清图片';
  108. break;
  109. }
  110. if (message) {
  111. alert(message);
  112. }
  113. }
  114. // 收藏功能
  115. toggleFavorite(): void {
  116. this.isFavorite = !this.isFavorite;
  117. alert(this.isFavorite ? '已添加到收藏' : '已取消收藏');
  118. }
  119. // 关注功能
  120. toggleFollow(): void {
  121. this.photographer.isFollowing = !this.photographer.isFollowing;
  122. }
  123. // 购买功能
  124. buyImage(): void {
  125. const buyBtn = document.querySelector('.buy-btn');
  126. if (buyBtn) {
  127. const originalText = buyBtn.innerHTML;
  128. buyBtn.innerHTML = '<i class="fas fa-check"></i> 已添加到购物车';
  129. buyBtn.classList.add('purchased');
  130. setTimeout(() => {
  131. buyBtn.innerHTML = originalText;
  132. buyBtn.classList.remove('purchased');
  133. }, 2000);
  134. }
  135. }
  136. // 返回功能
  137. goBack(): void {
  138. alert('返回首页');
  139. // 实际项目中这里应该是路由跳转
  140. }
  141. }