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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. <template>
  2. <div>
  3. <div class="w-full h-[45px] sm:h-[55px] md:h-[65px] lg:h-[72px]"></div>
  4. <ErrorBoundary :error="error">
  5. <div v-if="isLoading" class="flex justify-center py-8 md:py-12">
  6. <!-- 加载中 -->
  7. <div
  8. class="animate-spin h-6 w-6 md:h-8 md:w-8 border-4 border-cyan-500 rounded-full border-t-transparent"
  9. ></div>
  10. </div>
  11. <div v-else>
  12. <div class="w-full mb-8 md:mb-12 lg:mb-16 relative">
  13. <div class="absolute top-0 left-0 w-full h-full z-10">
  14. <div
  15. class="max-w-screen-2xl mx-auto h-full flex flex-col justify-center gap-2 md:gap-4 p-4 md:p-6 lg:p-8"
  16. >
  17. <div
  18. class="text-white text-xl sm:text-2xl md:text-3xl lg:text-4xl xl:text-6xl font-normal"
  19. >
  20. {{ t("products.product_list") }}
  21. </div>
  22. <div
  23. class="text-white text-xs sm:text-sm md:text-base lg:text-lg font-normal leading-relaxed md:leading-loose"
  24. >
  25. {{ t("products.product_list_description") }}
  26. </div>
  27. </div>
  28. </div>
  29. <img
  30. :src="banner"
  31. alt="products-banner"
  32. class="w-full object-cover h-40 sm:h-48 md:h-56 lg:h-64 xl:h-80"
  33. />
  34. </div>
  35. <div
  36. class="max-w-full mb-4 md:mb-6 lg:mb-8 xl:px-8 lg:px-6 md:px-4 px-4"
  37. >
  38. <div class="max-w-screen-2xl mx-auto">
  39. <nuxt-link
  40. :to="`${homepagePath}/`"
  41. class="text-white/60 text-sm md:text-base font-normal hover:text-white transition-colors duration-300"
  42. >{{ t("common.home") }}</nuxt-link
  43. >
  44. <span class="text-white/60 text-sm md:text-base font-normal px-2">
  45. /
  46. </span>
  47. <nuxt-link
  48. :to="`${homepagePath}/products`"
  49. class="text-white text-sm md:text-base font-normal"
  50. >{{ t("products.product_list") }}</nuxt-link
  51. >
  52. </div>
  53. </div>
  54. <div
  55. class="max-w-full mb-8 md:mb-12 lg:mb-16 xl:mb-20 xl:px-8 lg:px-6 md:px-4 px-4"
  56. >
  57. <div class="max-w-screen-2xl mx-auto">
  58. <div class="w-full grid grid-cols-1 md:grid-cols-12 gap-4">
  59. <div
  60. class="sticky top-24 col-span-1 md:col-span-3 flex flex-col gap-4 sm:gap-6 md:gap-8 lg:gap-10 xl:gap-12 2xl:gap-16 mb-4 sm:mb-6 md:mb-8 lg:mb-10 xl:mb-12 2xl:mb-16 pr-4"
  61. >
  62. <div
  63. class="flex flex-col gap-2 sm:gap-3 md:gap-4 lg:gap-5 xl:gap-6"
  64. >
  65. <div class="flex justify-between items-center">
  66. <div
  67. class="text-white text-base sm:text-lg md:text-xl lg:text-2xl xl:text-3xl font-medium"
  68. >
  69. {{ t("products.product_categories_title") }}
  70. </div>
  71. <button
  72. v-if="selectedCategory"
  73. @click="clearCategory"
  74. class="flex items-center gap-1 px-1.5 py-0.5 sm:px-2 sm:py-1 md:px-2.5 md:py-1.5 lg:px-3 lg:py-2 text-xs sm:text-sm md:text-base text-white/60 hover:text-white bg-zinc-800/50 hover:bg-zinc-700/50 rounded-lg transition-all duration-300 active:scale-95"
  75. >
  76. <svg
  77. xmlns="http://www.w3.org/2000/svg"
  78. class="h-2.5 w-2.5 sm:h-3 sm:w-3 md:h-4 md:w-4"
  79. viewBox="0 0 20 20"
  80. fill="currentColor"
  81. >
  82. <path
  83. fill-rule="evenodd"
  84. d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
  85. clip-rule="evenodd"
  86. />
  87. </svg>
  88. </button>
  89. </div>
  90. <div
  91. class="flex flex-row md:flex-col gap-1.5 sm:gap-2 md:gap-2.5 lg:gap-3 xl:gap-4 w-full md:w-fit overflow-x-auto md:overflow-x-visible pb-2 md:pb-0 whitespace-nowrap md:whitespace-normal"
  92. >
  93. <div
  94. v-for="category in categories"
  95. :key="category"
  96. @click="handleCategoryFilter(category)"
  97. class="select-none text-white text-xs sm:text-sm md:text-base lg:text-lg font-normal cursor-pointer hover:opacity-100 transition-all duration-300 px-2 py-1 sm:px-2.5 sm:py-1.5 md:px-3 md:py-2 lg:px-4 lg:py-2.5 rounded-lg inline-block active:scale-95 whitespace-nowrap"
  98. :class="{
  99. 'font-bold bg-cyan-400 text-zinc-900 border-0 shadow-lg scale-105 transition-all duration-300':
  100. selectedCategory === category,
  101. 'hover:bg-zinc-800/50': selectedCategory !== category,
  102. }"
  103. >
  104. {{ category }}
  105. </div>
  106. </div>
  107. </div>
  108. <div
  109. class="flex-col gap-2 sm:gap-3 md:gap-4 lg:gap-5 xl:gap-6 hidden"
  110. >
  111. <div class="flex justify-between items-center">
  112. <div
  113. class="text-white text-base sm:text-lg md:text-xl lg:text-2xl xl:text-3xl font-medium"
  114. >
  115. {{ t("products.product_categories_usage") }}
  116. </div>
  117. <button
  118. v-if="selectedUsage"
  119. @click="clearUsage"
  120. class="flex items-center gap-1 px-1.5 py-0.5 sm:px-2 sm:py-1 md:px-2.5 md:py-1.5 lg:px-3 lg:py-2 text-xs sm:text-sm md:text-base text-white/60 hover:text-white bg-zinc-800/50 hover:bg-zinc-700/50 rounded-lg transition-all duration-300 active:scale-95"
  121. >
  122. <svg
  123. xmlns="http://www.w3.org/2000/svg"
  124. class="h-2.5 w-2.5 sm:h-3 sm:w-3 md:h-4 md:w-4"
  125. viewBox="0 0 20 20"
  126. fill="currentColor"
  127. >
  128. <path
  129. fill-rule="evenodd"
  130. d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
  131. clip-rule="evenodd"
  132. />
  133. </svg>
  134. </button>
  135. </div>
  136. <div
  137. class="flex flex-row md:flex-col gap-1.5 sm:gap-2 md:gap-2.5 lg:gap-3 xl:gap-4 w-full md:w-fit overflow-x-auto md:overflow-x-visible pb-2 md:pb-0 whitespace-nowrap md:whitespace-normal"
  138. >
  139. <div
  140. v-for="usage in usages"
  141. :key="usage"
  142. @click="handleUsageFilter(usage)"
  143. class="opacity-80 select-none text-white text-xs sm:text-sm md:text-base lg:text-lg font-normal cursor-pointer hover:opacity-100 transition-all duration-300 px-2 py-1 sm:px-2.5 sm:py-1.5 md:px-3 md:py-2 lg:px-4 lg:py-2.5 rounded-lg inline-block active:scale-95"
  144. :class="{
  145. 'opacity-100 font-bold bg-cyan-400 text-white border-0 shadow-lg scale-105 transition-all duration-300':
  146. selectedUsage === usage,
  147. 'hover:bg-zinc-800/50': selectedUsage !== usage,
  148. }"
  149. >
  150. {{ usage }}
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. <div class="col-span-1 md:col-span-9">
  156. <div class="flex flex-col gap-8 md:gap-12 lg:gap-16">
  157. <template v-for="category in categories" :key="category">
  158. <div
  159. v-if="
  160. filteredProducts.filter((p) => {
  161. const categoryObj = allCategories.find(
  162. (c) => c.title === category
  163. );
  164. return categoryObj && p.categoryId === categoryObj.id;
  165. }).length > 0
  166. "
  167. class="flex flex-col gap-4 md:gap-6"
  168. >
  169. <div
  170. class="w-full text-white text-2xl md:text-3xl lg:text-4xl font-normal mb-4 md:mb-6"
  171. >
  172. {{ category }}
  173. </div>
  174. <!-- 添加系列分组 -->
  175. <template
  176. v-for="[seriesName, seriesProducts] in Array.from(
  177. productsBySeries.entries()
  178. )"
  179. :key="seriesName"
  180. >
  181. <div
  182. v-if="
  183. seriesProducts.some((p) => {
  184. const categoryObj = allCategories.find(
  185. (c) => c.title === category
  186. );
  187. return (
  188. categoryObj && p.categoryId === categoryObj.id
  189. );
  190. })
  191. "
  192. class="mb-8 md:mb-12"
  193. >
  194. <div class="relative">
  195. <!-- 系列标题背景 -->
  196. <div
  197. class="absolute inset-0 bg-gradient-to-r from-cyan-900/20 to-cyan-500/20 rounded-lg transform -skew-x-6"
  198. ></div>
  199. <!-- 系列标题内容 -->
  200. <div
  201. class="relative flex items-center gap-3 md:gap-4 py-3 md:py-4 px-4 md:px-6"
  202. >
  203. <!-- 装饰线 -->
  204. <div
  205. class="w-1 h-6 md:h-8 bg-cyan-400 text-zinc-900 rounded-full"
  206. ></div>
  207. <!-- 系列名称 -->
  208. <h3
  209. class="text-white text-lg md:text-xl lg:text-2xl font-medium tracking-wide"
  210. >
  211. {{ seriesName }}
  212. </h3>
  213. <!-- 产品数量标签 -->
  214. <div
  215. class="ml-auto px-2 py-0.5 md:px-3 md:py-1 bg-cyan-500/20 rounded-full text-cyan-300 text-xs md:text-sm"
  216. >
  217. {{ seriesProducts.length }}
  218. {{ t("products.product_count") }}
  219. </div>
  220. </div>
  221. </div>
  222. <!-- 产品网格 -->
  223. <div class="mt-4 md:mt-6">
  224. <transition-group
  225. name="fade"
  226. tag="div"
  227. class="w-full grid grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 gap-3 md:gap-4"
  228. >
  229. <nuxt-link
  230. v-for="product in seriesProducts.filter((p) => {
  231. const categoryObj = allCategories.find(
  232. (c) => c.title === category
  233. );
  234. return (
  235. categoryObj &&
  236. p.categoryId === categoryObj.id
  237. );
  238. })"
  239. :key="product.id"
  240. :to="`${homepagePath}/products/${product.name}`"
  241. class="group bg-zinc-900 rounded-lg transition-all duration-300 hover:bg-zinc-800 hover:scale-105 hover:shadow-lg hover:ring-2 hover:ring-cyan-400 relative overflow-hidden"
  242. >
  243. <div class="w-full p-4 md:p-6 lg:p-8">
  244. <div
  245. class="relative w-full aspect-square mb-3 md:mb-4"
  246. >
  247. <img
  248. v-if="!isImageError(product.id)"
  249. :src="product.image"
  250. :alt="product.name"
  251. class="w-full h-full object-cover rounded-lg transition-transform duration-300 group-hover:scale-110"
  252. @error="handleImageError($event, product)"
  253. @load="handleImageLoad($event, product)"
  254. loading="lazy"
  255. />
  256. <div
  257. v-if="isImageLoading(product.id)"
  258. class="absolute inset-0 flex items-center justify-center bg-zinc-800/50 rounded-lg"
  259. >
  260. <div
  261. class="animate-spin h-6 w-6 md:h-8 md:w-8 border-4 border-cyan-500 rounded-full border-t-transparent"
  262. ></div>
  263. </div>
  264. <div
  265. v-if="
  266. !product.image ||
  267. product.image === '' ||
  268. isImageError(product.id)
  269. "
  270. class="absolute inset-0 flex items-center justify-center bg-zinc-800/50 rounded-lg"
  271. >
  272. <svg
  273. xmlns="http://www.w3.org/2000/svg"
  274. class="h-12 w-12 md:h-16 md:w-16 text-white/40"
  275. fill="none"
  276. viewBox="0 0 24 24"
  277. stroke="currentColor"
  278. >
  279. <path
  280. stroke-linecap="round"
  281. stroke-linejoin="round"
  282. stroke-width="2"
  283. d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
  284. />
  285. </svg>
  286. </div>
  287. </div>
  288. <div
  289. class="text-center text-white text-base md:text-lg lg:text-xl font-normal mb-2"
  290. >
  291. {{ product.name }}
  292. </div>
  293. <div
  294. class="text-center text-[#71717A] text-sm md:text-base font-normal leading-normal"
  295. >
  296. {{ product.capacities.join(" / ") }}
  297. </div>
  298. <!-- Summary 悬浮层 -->
  299. <div
  300. class="absolute inset-0 bg-gradient-to-t from-black/90 via-black/50 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-300 flex items-end"
  301. >
  302. <div class="p-4 md:p-6 w-full">
  303. <div
  304. class="text-white text-sm md:text-base line-clamp-3"
  305. >
  306. {{ product.summary }}
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. </nuxt-link>
  312. </transition-group>
  313. </div>
  314. </div>
  315. </template>
  316. <!-- 展示没有系列的产品 -->
  317. <transition-group
  318. v-if="
  319. filteredProducts.filter((p) => {
  320. const categoryObj = allCategories.find(
  321. (c) => c.title === category
  322. );
  323. return (
  324. categoryObj &&
  325. p.categoryId === categoryObj.id &&
  326. (!p.series || p.series.length === 0)
  327. );
  328. }).length > 0
  329. "
  330. name="fade"
  331. tag="div"
  332. class="w-full grid grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 gap-3 md:gap-4"
  333. >
  334. <nuxt-link
  335. v-for="product in filteredProducts.filter((p) => {
  336. const categoryObj = allCategories.find(
  337. (c) => c.title === category
  338. );
  339. return (
  340. categoryObj &&
  341. p.categoryId === categoryObj.id &&
  342. (!p.series || p.series.length === 0)
  343. );
  344. })"
  345. :key="product.id"
  346. :to="`${homepagePath}/products/${product.name}`"
  347. class="group bg-zinc-900 rounded-lg transition-all duration-300 hover:bg-zinc-800 hover:shadow-lg hover:ring-2 hover:ring-cyan-400 relative overflow-hidden"
  348. >
  349. <div class="w-full p-4 md:p-6 lg:p-8">
  350. <div
  351. class="relative w-full aspect-square mb-3 md:mb-4"
  352. >
  353. <img
  354. v-if="!isImageError(product.id)"
  355. :src="product.image"
  356. :alt="product.name"
  357. class="w-full h-full object-cover rounded-lg transition-transform duration-300 group-hover:scale-110"
  358. @error="handleImageError($event, product)"
  359. @load="handleImageLoad($event, product)"
  360. loading="lazy"
  361. />
  362. <div
  363. v-if="isImageLoading(product.id)"
  364. class="absolute inset-0 flex items-center justify-center bg-zinc-800/50 rounded-lg"
  365. >
  366. <div
  367. class="animate-spin h-6 w-6 md:h-8 md:w-8 border-4 border-cyan-500 rounded-full border-t-transparent"
  368. ></div>
  369. </div>
  370. <div
  371. v-if="
  372. !product.image ||
  373. product.image === '' ||
  374. isImageError(product.id)
  375. "
  376. class="absolute inset-0 flex items-center justify-center bg-zinc-800/50 rounded-lg"
  377. >
  378. <svg
  379. xmlns="http://www.w3.org/2000/svg"
  380. class="h-12 w-12 md:h-16 md:w-16 text-white/40"
  381. fill="none"
  382. viewBox="0 0 24 24"
  383. stroke="currentColor"
  384. >
  385. <path
  386. stroke-linecap="round"
  387. stroke-linejoin="round"
  388. stroke-width="2"
  389. d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
  390. />
  391. </svg>
  392. </div>
  393. </div>
  394. <div
  395. class="text-center text-white text-base md:text-lg lg:text-xl font-normal mb-2"
  396. >
  397. {{ product.name }}
  398. </div>
  399. <div
  400. class="text-center text-[#71717A] text-sm md:text-base font-normal leading-normal"
  401. >
  402. {{ product.capacities.join(" / ") }}
  403. </div>
  404. <!-- Summary 悬浮层 -->
  405. <div
  406. class="absolute inset-0 bg-gradient-to-t from-black/90 via-black/50 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-300 flex items-end"
  407. >
  408. <div class="p-4 md:p-6 w-full">
  409. <div
  410. class="text-white text-sm md:text-base line-clamp-3"
  411. >
  412. {{ product.summary }}
  413. </div>
  414. </div>
  415. </div>
  416. </div>
  417. </nuxt-link>
  418. </transition-group>
  419. </div>
  420. </template>
  421. </div>
  422. </div>
  423. </div>
  424. </div>
  425. </div>
  426. </div>
  427. </ErrorBoundary>
  428. </div>
  429. </template>
  430. <script setup lang="ts">
  431. /**
  432. * 产品列表页面
  433. * 展示所有产品,支持按分类和用途筛选
  434. */
  435. import { useErrorHandler } from "~/composables/useErrorHandler";
  436. import banner from "@/assets/images/product-banner.webp";
  437. import { useI18n } from "vue-i18n";
  438. import { queryCollection } from "#imports";
  439. import { useRoute, useRouter } from "vue-router";
  440. import { useDebounceFn } from "@vueuse/core";
  441. const { t, locale } = useI18n();
  442. const route = useRoute();
  443. const router = useRouter();
  444. const homepagePath = computed(() => {
  445. return locale.value === "zh" ? "" : `/${locale.value}`;
  446. });
  447. // 产品接口定义
  448. interface Product {
  449. id: number;
  450. name: string;
  451. title: string;
  452. categoryId: number;
  453. usage: string[];
  454. series: string[];
  455. capacities: string[];
  456. image: string;
  457. description?: string;
  458. summary: string;
  459. gallery: string[];
  460. sort: number;
  461. }
  462. interface Category {
  463. id: number;
  464. title: string;
  465. description?: string;
  466. image: string;
  467. summary: string;
  468. capacities: string[];
  469. sort: number;
  470. }
  471. // 分页配置
  472. const PAGE_SIZE = 100;
  473. const currentPage = ref(1);
  474. const totalPages = ref(1);
  475. // 使用防抖优化路由更新
  476. const debouncedRouterPush = useDebounceFn(
  477. (query: Record<string, string | undefined>) => {
  478. router.push({ query });
  479. },
  480. 300
  481. );
  482. const { error, isLoading, wrapAsync } = useErrorHandler();
  483. const allProducts = ref<Product[]>([]);
  484. const allCategories = ref<Category[]>([]);
  485. const filteredProducts = ref<Product[]>([]);
  486. const categories = ref<string[]>([]);
  487. const usages = ref<string[]>([]);
  488. const selectedCategory = ref(route.query.category?.toString() || "");
  489. const selectedUsage = ref(route.query.usage?.toString() || "");
  490. // 使用缓存优化数据加载
  491. const { data: productData } = await useAsyncData("products", async () => {
  492. try {
  493. const content = await queryCollection("content").all();
  494. const products = content
  495. .filter((item: any) => {
  496. const isProduct =
  497. item.path?.includes("/products/") &&
  498. !item.path?.includes("/categories/") &&
  499. item.path?.includes(`/${locale.value}/`);
  500. return isProduct;
  501. })
  502. .map((item: any, index: number) => {
  503. const meta = item.meta || item.frontmatter || {};
  504. const pathId = item.path?.match(/\/products\/(\d+)/)?.[1];
  505. return {
  506. id: pathId ? parseInt(pathId) : index + 1,
  507. name: meta.name || item.title || "",
  508. title: item.title || "",
  509. categoryId: parseInt(meta.categoryId?.toString() || "0"),
  510. usage: meta.usage || [],
  511. series: meta.series || [],
  512. capacities: meta.capacities || [],
  513. image: meta.image || "",
  514. description: meta.description || "",
  515. summary: meta.summary || "",
  516. gallery: meta.gallery || [],
  517. sort: meta.sort || 0,
  518. };
  519. })
  520. .sort((a, b) => a.sort - b.sort);
  521. // 计算总页数
  522. totalPages.value = Math.ceil(products.length / PAGE_SIZE);
  523. return products;
  524. } catch (error) {
  525. console.error("Error loading product content:", error);
  526. return [];
  527. }
  528. });
  529. // 使用缓存优化类别数据加载
  530. const { data: categoryData } = await useAsyncData("categories", async () => {
  531. try {
  532. const content = await queryCollection("content").all();
  533. return content
  534. .filter((item: any) => {
  535. const isCategory =
  536. item.path?.includes("/categories/") &&
  537. item.path?.includes(`/${locale.value}/`);
  538. return isCategory;
  539. })
  540. .map((item: any, index: number) => {
  541. const meta = item.meta || item.frontmatter || {};
  542. const pathId = item.path?.match(/\/categories\/(\d+)/)?.[1];
  543. return {
  544. id: pathId ? parseInt(pathId) : index + 1,
  545. title: meta.title || item.title || "",
  546. description: meta.description || "",
  547. image: meta.image || "",
  548. summary: meta.summary || "",
  549. capacities: meta.capacities || [],
  550. sort: meta.sort || 0,
  551. };
  552. })
  553. .sort((a, b) => a.sort - b.sort);
  554. } catch (error) {
  555. console.error("Error loading category content:", error);
  556. return [];
  557. }
  558. });
  559. // 使用计算属性优化数据过滤
  560. const filteredProductsByCategory = computed(() => {
  561. if (!selectedCategory.value) return allProducts.value;
  562. const category = allCategories.value.find(
  563. (c: Category) => c.title === selectedCategory.value
  564. );
  565. if (!category) return allProducts.value;
  566. return allProducts.value.filter((p: Product) => p.categoryId === category.id);
  567. });
  568. const filteredProductsByUsage = computed(() => {
  569. if (!selectedUsage.value) return filteredProductsByCategory.value;
  570. return filteredProductsByCategory.value.filter((p: Product) =>
  571. p.usage.includes(selectedUsage.value)
  572. );
  573. });
  574. // 分页后的产品列表
  575. const paginatedProducts = computed(() => {
  576. const start = (currentPage.value - 1) * PAGE_SIZE;
  577. const end = start + PAGE_SIZE;
  578. return filteredProductsByUsage.value.slice(start, end);
  579. });
  580. // 使用计算属性优化用途列表
  581. const uniqueUsages = computed(() => {
  582. const usageSet = new Set<string>();
  583. allProducts.value.forEach((product: Product) => {
  584. product.usage.forEach((u: string) => usageSet.add(u));
  585. });
  586. return Array.from(usageSet);
  587. });
  588. // 使用计算属性优化类别列表
  589. const categoryTitles = computed(() =>
  590. allCategories.value.map((c: Category) => c.title)
  591. );
  592. // 使用计算属性优化系列分组
  593. const productsBySeries = computed(() => {
  594. const seriesMap = new Map<string, Product[]>();
  595. filteredProducts.value.forEach((product: Product) => {
  596. if (product.series && product.series.length > 0) {
  597. const series = product.series[0]; // 取第一个系列作为分组依据
  598. if (!seriesMap.has(series)) {
  599. seriesMap.set(series, []);
  600. }
  601. seriesMap.get(series)?.push(product);
  602. }
  603. });
  604. return seriesMap;
  605. });
  606. // 处理数据变化
  607. watchEffect(() => {
  608. if (!productData.value || !categoryData.value) return;
  609. isLoading.value = true;
  610. try {
  611. allProducts.value = productData.value;
  612. allCategories.value = categoryData.value;
  613. usages.value = uniqueUsages.value;
  614. categories.value = categoryTitles.value;
  615. filteredProducts.value = paginatedProducts.value;
  616. } catch (err) {
  617. console.error("Error processing data:", err);
  618. error.value = new Error(t("products.processError"));
  619. } finally {
  620. isLoading.value = false;
  621. }
  622. });
  623. /**
  624. * 处理分类筛选
  625. */
  626. function handleCategoryFilter(category: string) {
  627. selectedCategory.value = selectedCategory.value === category ? "" : category;
  628. currentPage.value = 1; // 重置页码
  629. filteredProducts.value = paginatedProducts.value;
  630. }
  631. /**
  632. * 处理用途筛选
  633. */
  634. function handleUsageFilter(usage: string) {
  635. selectedUsage.value = selectedUsage.value === usage ? "" : usage;
  636. currentPage.value = 1; // 重置页码
  637. filteredProducts.value = paginatedProducts.value;
  638. }
  639. /**
  640. * 处理页码变化
  641. */
  642. function handlePageChange(page: number) {
  643. currentPage.value = page;
  644. filteredProducts.value = paginatedProducts.value;
  645. }
  646. // 监听分类变化
  647. watch(selectedCategory, (newValue) => {
  648. debouncedRouterPush({
  649. ...route.query,
  650. category: newValue || undefined,
  651. });
  652. });
  653. // 监听用途变化
  654. watch(selectedUsage, (newValue) => {
  655. debouncedRouterPush({
  656. ...route.query,
  657. usage: newValue || undefined,
  658. });
  659. });
  660. // 监听路由变化
  661. watch(
  662. () => route.query,
  663. (newQuery) => {
  664. selectedCategory.value = newQuery.category?.toString() || "";
  665. selectedUsage.value = newQuery.usage?.toString() || "";
  666. const page = parseInt(newQuery.page?.toString() || "1");
  667. if (page !== currentPage.value) {
  668. currentPage.value = page;
  669. }
  670. },
  671. { deep: true }
  672. );
  673. // 重置筛选条件
  674. const resetFilters = () => {
  675. selectedCategory.value = "";
  676. selectedUsage.value = "";
  677. currentPage.value = 1;
  678. debouncedRouterPush({});
  679. };
  680. // SEO优化
  681. useHead({
  682. title: `${t("products.title")} - Hanye`,
  683. meta: [
  684. {
  685. name: "description",
  686. content: `${t("products.description")}`,
  687. },
  688. ],
  689. });
  690. const fallbackImage = "/images/placeholder.jpg";
  691. // 图片加载状态管理
  692. const loadingImages = ref<Set<number>>(new Set());
  693. const errorImages = ref<Set<number>>(new Set());
  694. // 检查图片是否正在加载
  695. const isImageLoading = (productId: number) => {
  696. return loadingImages.value.has(productId);
  697. };
  698. // 检查图片是否加载错误
  699. const isImageError = (productId: number) => {
  700. return errorImages.value.has(productId);
  701. };
  702. // 处理图片加载开始
  703. const handleImageLoadStart = (productId: number) => {
  704. loadingImages.value.add(productId);
  705. errorImages.value.delete(productId);
  706. };
  707. // 处理图片加载完成
  708. const handleImageLoad = (event: Event, product: Product) => {
  709. loadingImages.value.delete(product.id);
  710. errorImages.value.delete(product.id);
  711. };
  712. // 处理图片加载错误
  713. const handleImageError = (event: Event, product: Product) => {
  714. console.warn(`Image load failed for product: ${product.title}`);
  715. if (event.target instanceof HTMLImageElement) {
  716. loadingImages.value.delete(product.id);
  717. errorImages.value.add(product.id);
  718. }
  719. };
  720. // 清除分类筛选
  721. const clearCategory = () => {
  722. selectedCategory.value = "";
  723. currentPage.value = 1;
  724. filteredProducts.value = paginatedProducts.value;
  725. debouncedRouterPush({
  726. ...route.query,
  727. category: undefined,
  728. });
  729. };
  730. // 清除用途筛选
  731. const clearUsage = () => {
  732. selectedUsage.value = "";
  733. currentPage.value = 1;
  734. filteredProducts.value = paginatedProducts.value;
  735. debouncedRouterPush({
  736. ...route.query,
  737. usage: undefined,
  738. });
  739. };
  740. // 组件卸载时清理资源
  741. onBeforeUnmount(() => {
  742. allProducts.value = [];
  743. allCategories.value = [];
  744. filteredProducts.value = [];
  745. categories.value = [];
  746. usages.value = [];
  747. loadingImages.value.clear();
  748. errorImages.value.clear();
  749. });
  750. </script>
  751. <style scoped>
  752. .fade-enter-active,
  753. .fade-leave-active {
  754. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  755. }
  756. .fade-enter-from,
  757. .fade-leave-to {
  758. opacity: 0;
  759. transform: translateY(20px);
  760. }
  761. /* 系列标题悬停效果 */
  762. .relative:hover .bg-gradient-to-r {
  763. @apply from-cyan-900/30 to-cyan-500/30;
  764. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  765. }
  766. /* 产品数量标签悬停效果 */
  767. .relative:hover .bg-cyan-500\/20 {
  768. @apply bg-cyan-500/30;
  769. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  770. }
  771. /* 装饰线动画效果 */
  772. .relative:hover .w-1 {
  773. @apply h-10;
  774. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  775. }
  776. .products-page {
  777. min-height: 100vh;
  778. background-color: #f9fafb;
  779. }
  780. /* 添加过渡动画 */
  781. .bg-primary {
  782. @apply bg-cyan-600;
  783. }
  784. button {
  785. transition: all 0.3s ease;
  786. }
  787. .rounded-full {
  788. @apply transition-all duration-300 ease-in-out;
  789. }
  790. .rounded-full:hover {
  791. @apply bg-gray-200;
  792. }
  793. /* 添加清除按钮悬停效果 */
  794. button:hover {
  795. transform: translateY(-1px);
  796. }
  797. /* 添加图片容器过渡效果 */
  798. .aspect-square {
  799. transition: all 0.3s ease;
  800. background-color: rgb(39, 39, 42); /* 添加背景色 */
  801. }
  802. .aspect-square:hover {
  803. transform: scale(1.02);
  804. }
  805. /* 加载动画优化 */
  806. .animate-spin {
  807. animation: spin 1s linear infinite;
  808. }
  809. @keyframes spin {
  810. from {
  811. transform: rotate(0deg);
  812. }
  813. to {
  814. transform: rotate(360deg);
  815. }
  816. }
  817. /* 响应式间距调整 */
  818. @media (max-width: 640px) {
  819. .gap-4 {
  820. gap: 0.75rem;
  821. }
  822. .p-4 {
  823. padding: 0.75rem;
  824. }
  825. }
  826. @media (min-width: 768px) {
  827. .gap-4 {
  828. gap: 1rem;
  829. }
  830. .p-4 {
  831. padding: 1rem;
  832. }
  833. }
  834. @media (min-width: 1024px) {
  835. .gap-4 {
  836. gap: 1.25rem;
  837. }
  838. .p-4 {
  839. padding: 1.5rem;
  840. }
  841. }
  842. /* 添加新的样式 */
  843. .line-clamp-3 {
  844. display: -webkit-box;
  845. -webkit-line-clamp: 3;
  846. -webkit-box-orient: vertical;
  847. overflow: hidden;
  848. }
  849. /* 优化过渡动画 */
  850. .group {
  851. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  852. }
  853. .group:hover {
  854. transform: translateY(-4px);
  855. }
  856. /* 图片缩放效果 */
  857. .group img {
  858. transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  859. }
  860. /* Summary 悬浮层动画 */
  861. .group .absolute {
  862. transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  863. }
  864. /* 确保文字在悬浮层上清晰可见 */
  865. .group .text-white {
  866. text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  867. }
  868. /* 响应式调整 */
  869. @media (max-width: 640px) {
  870. .group .absolute {
  871. padding: 0.75rem;
  872. }
  873. }
  874. @media (min-width: 768px) {
  875. .group .absolute {
  876. padding: 1rem;
  877. }
  878. }
  879. @media (min-width: 1024px) {
  880. .group .absolute {
  881. padding: 1.5rem;
  882. }
  883. }
  884. /* 导航栏样式优化 */
  885. .bg-zinc-900\/50 {
  886. backdrop-filter: blur(8px);
  887. -webkit-backdrop-filter: blur(8px);
  888. }
  889. /* 导航项悬停效果 */
  890. .group:hover {
  891. transform: translateX(4px);
  892. }
  893. /* 清除按钮动画 */
  894. button {
  895. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  896. }
  897. button:hover {
  898. transform: translateY(-2px);
  899. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
  900. 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  901. }
  902. button:active {
  903. transform: translateY(0);
  904. }
  905. /* 响应式调整 */
  906. @media (max-width: 768px) {
  907. .bg-zinc-900\/50 {
  908. padding: 1rem;
  909. }
  910. .group:hover {
  911. transform: translateX(2px);
  912. }
  913. }
  914. @media (min-width: 768px) {
  915. .bg-zinc-900\/50 {
  916. padding: 1.5rem;
  917. }
  918. }
  919. @media (min-width: 1024px) {
  920. .bg-zinc-900\/50 {
  921. padding: 2rem;
  922. }
  923. }
  924. /* 优化点击反馈 */
  925. .active\:scale-95:active {
  926. transform: scale(0.95);
  927. }
  928. /* 优化过渡动画 */
  929. .transition-all {
  930. transition-property: all;
  931. transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  932. transition-duration: 150ms;
  933. }
  934. /* 优化横向滚动 */
  935. .overflow-x-auto {
  936. -webkit-overflow-scrolling: touch;
  937. scrollbar-width: none; /* Firefox */
  938. -ms-overflow-style: none; /* IE and Edge */
  939. }
  940. .overflow-x-auto::-webkit-scrollbar {
  941. display: none; /* Chrome, Safari, Opera */
  942. }
  943. /* 响应式断点说明:
  944. sm: 640px
  945. md: 768px
  946. lg: 1024px
  947. xl: 1280px
  948. 2xl: 1536px
  949. */
  950. </style>