Hanye官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="py-8">
  3. <div class="container-custom">
  4. <h1 class="text-3xl font-bold mb-8">{{ $t('products.title') }}</h1>
  5. <ErrorBoundary :error="error">
  6. <div v-if="isLoading" class="flex justify-center py-12">
  7. <!-- 加载中 -->
  8. <div class="animate-spin h-8 w-8 border-4 border-blue-500 rounded-full border-t-transparent"></div>
  9. </div>
  10. <div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
  11. <div v-for="product in products" :key="product.id" class="bg-white border border-gray-200 rounded-lg overflow-hidden shadow-sm hover:shadow-md transition-shadow">
  12. <div class="h-48 bg-gray-100 flex items-center justify-center">
  13. <!-- 产品图片占位符 -->
  14. <span class="text-gray-400">{{ product.title }}</span>
  15. </div>
  16. <div class="p-6">
  17. <h2 class="text-xl font-semibold mb-2">{{ product.title }}</h2>
  18. <p class="text-gray-600 mb-4">{{ product.description }}</p>
  19. <NuxtLink :to="`/products/${product.id}`" class="text-blue-600 hover:text-blue-800 font-medium">
  20. {{ $t('products.viewDetails') }}
  21. </NuxtLink>
  22. </div>
  23. </div>
  24. </div>
  25. </ErrorBoundary>
  26. </div>
  27. </div>
  28. </template>
  29. <script setup lang="ts">
  30. /**
  31. * 产品列表页面
  32. * 展示所有产品
  33. */
  34. import { ref, onMounted } from 'vue';
  35. import { useErrorHandler } from '~/composables/useErrorHandler';
  36. // 产品接口定义
  37. interface Product {
  38. id: number;
  39. title: string;
  40. description: string;
  41. }
  42. const { error, isLoading, wrapAsync } = useErrorHandler();
  43. const products = ref<Product[]>([]);
  44. /**
  45. * 加载产品数据
  46. */
  47. async function loadProducts() {
  48. await wrapAsync(async () => {
  49. // 模拟API请求延迟
  50. await new Promise(resolve => setTimeout(resolve, 500));
  51. // 模拟数据,实际项目中应从API获取
  52. products.value = [
  53. {
  54. id: 1,
  55. title: '产品一',
  56. description: '这是产品一的详细描述,介绍产品特点和用途。'
  57. },
  58. {
  59. id: 2,
  60. title: '产品二',
  61. description: '这是产品二的详细描述,介绍产品特点和用途。'
  62. },
  63. {
  64. id: 3,
  65. title: '产品三',
  66. description: '这是产品三的详细描述,介绍产品特点和用途。'
  67. },
  68. {
  69. id: 4,
  70. title: '产品四',
  71. description: '这是产品四的详细描述,介绍产品特点和用途。'
  72. },
  73. {
  74. id: 5,
  75. title: '产品五',
  76. description: '这是产品五的详细描述,介绍产品特点和用途。'
  77. },
  78. {
  79. id: 6,
  80. title: '产品六',
  81. description: '这是产品六的详细描述,介绍产品特点和用途。'
  82. }
  83. ];
  84. return products.value;
  85. });
  86. }
  87. // 页面加载时获取产品数据
  88. onMounted(() => {
  89. loadProducts();
  90. });
  91. // SEO优化
  92. useHead({
  93. title: '产品列表 - Hanye',
  94. meta: [
  95. { name: 'description', content: '浏览我们的产品列表,找到适合您的解决方案。' }
  96. ]
  97. });
  98. </script>