Commit cf36b9b7e8c01c92fc4fd9ab49f8cdda5f27641e
1 parent
7ca465a9
fix: 删除热销商品请求接口
Showing
4 changed files
with
15 additions
and
531 deletions
components/CategoryList.vue
... | ... | @@ -316,173 +316,9 @@ import type { ProductImage } from "~/type"; |
316 | 316 | import { isMobile, isEqual } from "~/utils"; |
317 | 317 | import { watchEffect, ref } from "vue"; |
318 | 318 | |
319 | -const loading = ref(false); | |
320 | -const hotLoading = ref(false); | |
321 | 319 | const title = ref(""); |
322 | -const keywordTitle = ref(""); | |
323 | -const maxPage = ref(1); | |
324 | -const tabRecom = ref(); | |
325 | -const recommendList = ref({}); | |
326 | -const recommendImages = ref({}); | |
327 | -const currentIndex = ref(1); | |
328 | -const hotTotal = ref(10); | |
329 | -const isOrNotMobile = ref(isMobile()); | |
330 | -const maxPageMobile = ref(1); | |
331 | -const recommendListMobile = ref({}); | |
332 | -const recommendImagesMobile = ref({}); | |
333 | -const currentIndexMobile = ref(1); | |
334 | -const hotLoadingMobile = ref(false); | |
335 | -const hotTotalMobile = ref(10); | |
336 | - | |
337 | -const loadHotProducts = async () => { | |
338 | - const pageSize = 5; | |
339 | - let { data: hotProducts } = await useAsyncData( | |
340 | - "hotProducts", | |
341 | - () => | |
342 | - $fetch("/shop/product/hotProducts", { | |
343 | - method: "GET", | |
344 | - params: { | |
345 | - pageNo: currentIndex.value, | |
346 | - pageSize: pageSize, | |
347 | - }, | |
348 | - }), | |
349 | - { | |
350 | - server: true, // 仅在服务器端获取数据 | |
351 | - } | |
352 | - ); | |
353 | - hotTotal.value = hotProducts.value.data.total; | |
354 | - recommendList.value = hotProducts.value.data.records; | |
355 | - maxPage.value = hotProducts.value.data.pages; | |
356 | - // recommendImages.value = recommendList.value.slice(0, 10).map((item) => { | |
357 | - recommendImages.value = Array.from({ length: 5 }).map((_, index) => { | |
358 | - const item = recommendList.value[index]; | |
359 | - if (!item) { | |
360 | - return null; | |
361 | - } | |
362 | - // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析 | |
363 | - if (typeof item.productimageliststore === "string") { | |
364 | - try { | |
365 | - item.productimageliststore = JSON.parse(item.productimageliststore); | |
366 | - } catch (error) { | |
367 | - item.productimageliststore = []; // 解析失败时,设置为空数组 | |
368 | - } | |
369 | - } | |
370 | - const ree = (item.productimageliststore = item?.productimageliststore.map( | |
371 | - (productItem: ProductImage) => ({ | |
372 | - ...productItem, | |
373 | - // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`, | |
374 | - url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`, | |
375 | - name: item.name, | |
376 | - productUrl: `https://www.canrud.com/products/detail/${item.id}`, | |
377 | - }) | |
378 | - )); | |
379 | - return ree; | |
380 | - }); | |
381 | -}; | |
382 | - | |
383 | -const toggleRowLeft = () => { | |
384 | - if (currentIndex.value !== 1) { | |
385 | - currentIndex.value--; | |
386 | - } else if (currentIndex.value == 1) { | |
387 | - currentIndex.value = maxPage.value; | |
388 | - } | |
389 | - startTimer(); | |
390 | -}; | |
391 | -let intervalId: any; | |
392 | -const toggleRowRight = () => { | |
393 | - if (currentIndex.value < maxPage.value) { | |
394 | - currentIndex.value++; | |
395 | - } else if (currentIndex.value == maxPage.value) { | |
396 | - currentIndex.value = 1; | |
397 | - } | |
398 | - startTimer(); | |
399 | -}; | |
400 | -const startTimer = () => { | |
401 | - // 清除已有计时器,防止重复 | |
402 | - clearInterval(intervalId); | |
403 | - intervalId = setInterval(() => { | |
404 | - toggleRowRight(); | |
405 | - }, 5000); // 每6秒调用一次 | |
406 | -}; | |
407 | - | |
408 | -onMounted(() => { | |
409 | - startTimer(); | |
410 | -}); | |
411 | - | |
412 | 320 | const { width } = useDisplay(); |
413 | -const firstHotIndex = ref(true); | |
414 | - | |
415 | -watch(currentIndex, (newIndex) => { | |
416 | - loadHotProducts(); // Call loadHotProducts when currentIndex changes | |
417 | -}); | |
418 | - | |
419 | -const loadHotProductsMobile = async () => { | |
420 | - hotLoadingMobile.value = true; | |
421 | - let { data: hotProductsMobile } = await useAsyncData( | |
422 | - "hotProducts", | |
423 | - () => | |
424 | - $fetch("/shop/product/hotProducts", { | |
425 | - method: "GET", | |
426 | - params: { | |
427 | - pageNo: currentIndexMobile.value, | |
428 | - pageSize: 4, | |
429 | - }, | |
430 | - }), | |
431 | - { | |
432 | - server: true, // 仅在服务器端获取数据 | |
433 | - } | |
434 | - ); | |
435 | - hotTotalMobile.value = hotProductsMobile.value.data.total; | |
436 | - recommendListMobile.value = hotProductsMobile.value.data.records; | |
437 | - maxPageMobile.value = hotProductsMobile.value.data.pages; | |
438 | - // recommendImages.value = recommendList.value.slice(0, 10).map((item) => { | |
439 | - recommendImagesMobile.value = Array.from({ length: 4 }).map((_, index) => { | |
440 | - const item = recommendListMobile.value[index]; | |
441 | - if (!item) { | |
442 | - return null; | |
443 | - } | |
444 | - // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析 | |
445 | - if (typeof item.productimageliststore === "string") { | |
446 | - try { | |
447 | - item.productimageliststore = JSON.parse(item.productimageliststore); | |
448 | - } catch (error) { | |
449 | - item.productimageliststore = []; // 解析失败时,设置为空数组 | |
450 | - } | |
451 | - } | |
452 | - const ree = (item.productimageliststore = item?.productimageliststore.map( | |
453 | - (productItem: ProductImage) => ({ | |
454 | - ...productItem, | |
455 | - // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`, | |
456 | - url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`, | |
457 | - name: item.name, | |
458 | - productUrl: `https://www.canrud.com/products/detail/${item.id}`, | |
459 | - }) | |
460 | - )); | |
461 | - return ree; | |
462 | - }); | |
463 | - hotLoadingMobile.value = false; | |
464 | -}; | |
465 | -watch(currentIndexMobile, (newIndex) => { | |
466 | - loadHotProductsMobile(); // Call loadHotProducts when currentIndex changes | |
467 | -}); | |
468 | -watchEffect(async () => { | |
469 | - console.log("Current route:", route.fullPath, "Width:", width.value); | |
470 | - | |
471 | - if (firstHotIndex.value) { | |
472 | - if (width.value > 600) { | |
473 | - await loadHotProducts(); | |
474 | - } else { | |
475 | - await loadHotProductsMobile(); | |
476 | - } | |
477 | - } | |
478 | -}); | |
479 | 321 | |
480 | -const length = computed(() => | |
481 | - productStore.total ? Math.ceil(productStore.total / productStore.pageSize) : 0 | |
482 | -); | |
483 | -const hotLength = computed(() => | |
484 | - hotTotalMobile.value ? Math.ceil(hotTotalMobile.value / 4) : 0 | |
485 | -); | |
486 | 322 | </script> |
487 | 323 | <style scoped> |
488 | 324 | .title { | ... | ... |
nuxt.config.ts
... | ... | @@ -56,14 +56,14 @@ export default defineNuxtConfig({ |
56 | 56 | nitro: { |
57 | 57 | devProxy: { |
58 | 58 | "/shop": { |
59 | - target: "http://47.89.254.121:8002/shop", // 线上代理地址 | |
60 | - // target: "http://127.0.0.1:8002/shop", | |
59 | + // target: "http://47.89.254.121:8002/shop", // 线上代理地址 | |
60 | + target: "http://127.0.0.1:8002/shop", | |
61 | 61 | // target: process.env.BASE_URL || 'http://39.108.227.113:8002/shop', // 目标接口域名 |
62 | 62 | changeOrigin: true, // 表示是否跨域 |
63 | 63 | }, |
64 | 64 | "/email": { |
65 | - target: "http://47.89.254.121:8002/email", // 线上代理地址 | |
66 | - // target: "http://127.0.0.1:8002/shop", | |
65 | + // target: "http://47.89.254.121:8002/email", // 线上代理地址 | |
66 | + target: "http://127.0.0.1:8002/shop", | |
67 | 67 | // target: process.env.BASE_URL || 'http://39.108.227.113:8002/shop', // 目标接口域名 |
68 | 68 | changeOrigin: true, // 表示是否跨域 |
69 | 69 | }, |
... | ... | @@ -77,13 +77,13 @@ export default defineNuxtConfig({ |
77 | 77 | // 该配置用于服务端请求转发 |
78 | 78 | routeRules: { |
79 | 79 | "/shop/**": { |
80 | - proxy: "http://47.89.254.121:8002/shop/**", | |
81 | - // proxy: "http://127.0.0.1:8002/shop/**", | |
80 | + // proxy: "http://47.89.254.121:8002/shop/**", | |
81 | + proxy: "http://127.0.0.1:8002/shop/**", | |
82 | 82 | // proxy: process.env.BASE_URL || 'http://39.108.227.113:8002/shop/**' |
83 | 83 | }, |
84 | 84 | "/email/**": { |
85 | - proxy: "http://47.89.254.121:8002/email/**", | |
86 | - // proxy: "http://127.0.0.1:8002/shop/**", | |
85 | + // proxy: "http://47.89.254.121:8002/email/**", | |
86 | + proxy: "http://127.0.0.1:8002/shop/**", | |
87 | 87 | // proxy: process.env.BASE_URL || 'http://39.108.227.113:8002/shop/**' |
88 | 88 | }, |
89 | 89 | ... | ... |
pages/contact.vue
... | ... | @@ -244,27 +244,6 @@ import { ref, reactive } from "vue"; |
244 | 244 | import { useVuelidate } from "@vuelidate/core"; |
245 | 245 | import { email, required, maxLength } from "@vuelidate/validators"; |
246 | 246 | |
247 | -const productStore = useProductListStore(); | |
248 | -const categoryStore = useCategoryStore(); | |
249 | -const loading = ref(false); | |
250 | -const hotLoading = ref(false); | |
251 | -const route = useRoute(); // 获取路由信息 | |
252 | -const router = useRouter(); // 获取路由信息 | |
253 | -const title = ref(""); | |
254 | -const keywordTitle = ref(""); | |
255 | -const maxPage = ref(1); | |
256 | -const maxPageMobile = ref(1); | |
257 | -const tabRecom = ref(); | |
258 | -const recommendList = ref({}); | |
259 | -const recommendImages = ref({}); | |
260 | -const currentIndex = ref(1); | |
261 | -const hotTotal = ref(10); | |
262 | -const isOrNotMobile = isMobile(); | |
263 | -const recommendListMobile = ref({}); | |
264 | -const recommendImagesMobile = ref({}); | |
265 | -const currentIndexMobile = ref(1); | |
266 | -const hotLoadingMobile = ref(false); | |
267 | -const hotTotalMobile = ref(10); | |
268 | 247 | const verified = ref(false); // 验证状态 |
269 | 248 | const snackbar = ref(false); |
270 | 249 | const snackbarFailed = ref(false); |
... | ... | @@ -386,153 +365,7 @@ const loadRecaptchaScript = (callback) => { |
386 | 365 | |
387 | 366 | document.head.appendChild(script); |
388 | 367 | }; |
389 | -const loadHotProducts = async () => { | |
390 | - hotLoading.value = true; | |
391 | - let { data: hotProducts } = await useAsyncData( | |
392 | - "hotProducts", | |
393 | - () => | |
394 | - $fetch("/shop/product/hotProducts", { | |
395 | - method: "GET", | |
396 | - params: { | |
397 | - pageNo: currentIndex.value, | |
398 | - pageSize: 5, | |
399 | - }, | |
400 | - }), | |
401 | - { | |
402 | - server: true, // 仅在服务器端获取数据 | |
403 | - } | |
404 | - ); | |
405 | - hotTotal.value = hotProducts.value.data.total; | |
406 | - recommendList.value = hotProducts.value.data.records; | |
407 | - maxPage.value = hotProducts.value.data.pages; | |
408 | - // recommendImages.value = recommendList.value.slice(0, 10).map((item) => { | |
409 | - recommendImages.value = Array.from({ length: 5 }).map((_, index) => { | |
410 | - const item = recommendList.value[index]; | |
411 | - if (!item) { | |
412 | - return null; | |
413 | - } | |
414 | - // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析 | |
415 | - if (typeof item.productimageliststore === "string") { | |
416 | - try { | |
417 | - item.productimageliststore = JSON.parse(item.productimageliststore); | |
418 | - } catch (error) { | |
419 | - item.productimageliststore = []; // 解析失败时,设置为空数组 | |
420 | - } | |
421 | - } | |
422 | - const ree = (item.productimageliststore = item?.productimageliststore.map( | |
423 | - (productItem: ProductImage) => ({ | |
424 | - ...productItem, | |
425 | - // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`, | |
426 | - url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`, | |
427 | - name: item.name, | |
428 | - productUrl: `https://www.canrud.com/products/detail/${item.id}`, | |
429 | - }) | |
430 | - )); | |
431 | - return ree; | |
432 | - }); | |
433 | - hotLoading.value = false; | |
434 | -}; | |
435 | - | |
436 | -const toggleRowLeft = () => { | |
437 | - if (currentIndex.value !== 1) { | |
438 | - currentIndex.value--; | |
439 | - } else if (currentIndex.value == 1) { | |
440 | - currentIndex.value = maxPage.value; | |
441 | - } | |
442 | - startTimer(); | |
443 | -}; | |
444 | -let intervalId: any; | |
445 | -const toggleRowRight = () => { | |
446 | - if (currentIndex.value < maxPage.value) { | |
447 | - currentIndex.value++; | |
448 | - } else if (currentIndex.value == maxPage.value) { | |
449 | - currentIndex.value = 1; | |
450 | - } | |
451 | - startTimer(); | |
452 | -}; | |
453 | -const startTimer = () => { | |
454 | - // 清除已有计时器,防止重复 | |
455 | - clearInterval(intervalId); | |
456 | - intervalId = setInterval(() => { | |
457 | - toggleRowRight(); | |
458 | - }, 5000); // 每6秒调用一次 | |
459 | -}; | |
460 | - | |
461 | -onMounted(() => { | |
462 | - startTimer(); | |
463 | -}); | |
464 | - | |
465 | -const toggleRowMobile = (value: number) => { | |
466 | - currentIndexMobile.value = value; | |
467 | -}; | |
468 | -const { width } = useDisplay(); | |
469 | -const firstIndex = ref(true); | |
470 | - | |
471 | -watch(currentIndex, (newIndex) => { | |
472 | - loadHotProducts(); // Call loadHotProducts when currentIndex changes | |
473 | -}); | |
474 | - | |
475 | -const loadHotProductsMobile = async () => { | |
476 | - hotLoadingMobile.value = true; | |
477 | - let { data: hotProductsMobile } = await useAsyncData( | |
478 | - "hotProducts", | |
479 | - () => | |
480 | - $fetch("/shop/product/hotProducts", { | |
481 | - method: "GET", | |
482 | - params: { | |
483 | - pageNo: currentIndexMobile.value, | |
484 | - pageSize: 4, | |
485 | - }, | |
486 | - }), | |
487 | - { | |
488 | - server: true, // 仅在服务器端获取数据 | |
489 | - } | |
490 | - ); | |
491 | - hotTotalMobile.value = hotProductsMobile.value.data.total; | |
492 | - recommendListMobile.value = hotProductsMobile.value.data.records; | |
493 | - maxPageMobile.value = hotProductsMobile.value.data.pages; | |
494 | - // recommendImages.value = recommendList.value.slice(0, 10).map((item) => { | |
495 | - recommendImagesMobile.value = Array.from({ length: 4 }).map((_, index) => { | |
496 | - const item = recommendListMobile.value[index]; | |
497 | - if (!item) { | |
498 | - return null; | |
499 | - } | |
500 | - // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析 | |
501 | - if (typeof item.productimageliststore === "string") { | |
502 | - try { | |
503 | - item.productimageliststore = JSON.parse(item.productimageliststore); | |
504 | - } catch (error) { | |
505 | - item.productimageliststore = []; // 解析失败时,设置为空数组 | |
506 | - } | |
507 | - } | |
508 | - const ree = (item.productimageliststore = item?.productimageliststore.map( | |
509 | - (productItem: ProductImage) => ({ | |
510 | - ...productItem, | |
511 | - // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`, | |
512 | - url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`, | |
513 | - name: item.name, | |
514 | - productUrl: `https://www.canrud.com/products/detail/${item.id}`, | |
515 | - }) | |
516 | - )); | |
517 | - return ree; | |
518 | - }); | |
519 | - hotLoadingMobile.value = false; | |
520 | -}; | |
521 | -watch(currentIndexMobile, (newIndex) => { | |
522 | - loadHotProductsMobile(); // Call loadHotProducts when currentIndex changes | |
523 | -}); | |
524 | -// Initial load of hot products | |
525 | -watchEffect(async () => { | |
526 | - console.log("Current route:", route.fullPath, "Width:", width.value); | |
527 | 368 | |
528 | - if (firstIndex.value) { | |
529 | - if (width.value > 600) { | |
530 | - await loadHotProducts(); | |
531 | - } else { | |
532 | - await loadHotProductsMobile(); | |
533 | - } | |
534 | - } | |
535 | -}); | |
536 | 369 | useHead({ |
537 | 370 | title: "Contact", |
538 | 371 | }); |
... | ... | @@ -748,10 +581,13 @@ button .recommendButton { |
748 | 581 | span a { |
749 | 582 | color: black; |
750 | 583 | } |
751 | -.icon{ | |
752 | - display: flex; gap: 16px; align-items: center | |
584 | +.icon { | |
585 | + display: flex; | |
586 | + gap: 16px; | |
587 | + align-items: center; | |
753 | 588 | } |
754 | -.mobileIcon{ | |
755 | - gap: 16px; align-items: center | |
589 | +.mobileIcon { | |
590 | + gap: 16px; | |
591 | + align-items: center; | |
756 | 592 | } |
757 | 593 | </style> | ... | ... |
pages/products/index.vue
... | ... | @@ -89,196 +89,11 @@ import { watchEffect, computed, ref } from "vue"; |
89 | 89 | const productStore = useProductListStore(); |
90 | 90 | const categoryStore = useCategoryStore(); |
91 | 91 | const loading = ref(false); |
92 | -const hotLoading = ref(false); | |
93 | 92 | const route = useRoute(); // 获取路由信息 |
94 | 93 | const router = useRouter(); // 获取路由信息 |
95 | 94 | const title = ref(""); |
96 | 95 | const keywordTitle = ref(""); |
97 | -const maxPage = ref(1); | |
98 | -const tabRecom = ref(); | |
99 | -const recommendList = ref({}); | |
100 | -const recommendImages = ref({}); | |
101 | -const currentIndex = ref(1); | |
102 | -const hotTotal = ref(10); | |
103 | -const isOrNotMobile = ref(isMobile()); | |
104 | -const maxPageMobile = ref(1); | |
105 | -const recommendListMobile = ref({}); | |
106 | -const recommendImagesMobile = ref({}); | |
107 | -const currentIndexMobile = ref(1); | |
108 | -const hotLoadingMobile = ref(false); | |
109 | -const hotTotalMobile = ref(10); | |
110 | 96 | |
111 | -const loadHotProducts = async () => { | |
112 | - const pageSize = 5; | |
113 | - let { data: hotProducts } = await useAsyncData( | |
114 | - "hotProducts", | |
115 | - () => | |
116 | - $fetch("/shop/product/hotProducts", { | |
117 | - method: "GET", | |
118 | - params: { | |
119 | - pageNo: currentIndex.value, | |
120 | - pageSize: pageSize, | |
121 | - }, | |
122 | - }), | |
123 | - { | |
124 | - server: true, // 仅在服务器端获取数据 | |
125 | - } | |
126 | - ); | |
127 | - hotTotal.value = hotProducts.value.data.total; | |
128 | - recommendList.value = hotProducts.value.data.records; | |
129 | - maxPage.value = hotProducts.value.data.pages; | |
130 | - // recommendImages.value = recommendList.value.slice(0, 10).map((item) => { | |
131 | - recommendImages.value = Array.from({ length: 5 }).map((_, index) => { | |
132 | - const item = recommendList.value[index]; | |
133 | - if (!item) { | |
134 | - return null; | |
135 | - } | |
136 | - // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析 | |
137 | - if (typeof item.productimageliststore === "string") { | |
138 | - try { | |
139 | - item.productimageliststore = JSON.parse(item.productimageliststore); | |
140 | - } catch (error) { | |
141 | - item.productimageliststore = []; // 解析失败时,设置为空数组 | |
142 | - } | |
143 | - } | |
144 | - const ree = (item.productimageliststore = item?.productimageliststore.map( | |
145 | - (productItem: ProductImage) => ({ | |
146 | - ...productItem, | |
147 | - // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`, | |
148 | - url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`, | |
149 | - name: item.name, | |
150 | - productUrl: `https://www.canrud.com/products/detail/${item.id}`, | |
151 | - }) | |
152 | - )); | |
153 | - return ree; | |
154 | - }); | |
155 | -}; | |
156 | - | |
157 | -const toggleRowLeft = () => { | |
158 | - if (currentIndex.value !== 1) { | |
159 | - currentIndex.value--; | |
160 | - } else if (currentIndex.value == 1) { | |
161 | - currentIndex.value = maxPage.value; | |
162 | - } | |
163 | - startTimer(); | |
164 | -}; | |
165 | -let intervalId: any; | |
166 | -const toggleRowRight = () => { | |
167 | - if (currentIndex.value < maxPage.value) { | |
168 | - currentIndex.value++; | |
169 | - } else if (currentIndex.value == maxPage.value) { | |
170 | - currentIndex.value = 1; | |
171 | - } | |
172 | - startTimer(); | |
173 | -}; | |
174 | -const startTimer = () => { | |
175 | - // 清除已有计时器,防止重复 | |
176 | - clearInterval(intervalId); | |
177 | - intervalId = setInterval(() => { | |
178 | - toggleRowRight(); | |
179 | - }, 5000); // 每6秒调用一次 | |
180 | -}; | |
181 | - | |
182 | -onMounted(() => { | |
183 | - startTimer(); | |
184 | -}); | |
185 | - | |
186 | -const toggleRowMobile = (value: number) => { | |
187 | - currentIndexMobile.value = value; | |
188 | -}; | |
189 | -const { width } = useDisplay(); | |
190 | -const firstHotIndex = ref(true); | |
191 | - | |
192 | -// // 监听屏幕宽度变化 | |
193 | -// watch(width, async (newWidth) => { | |
194 | -// console.log(newWidth, "5656widthvalue"); | |
195 | -// if (firstHotIndex.value) { | |
196 | -// if (newWidth > 600) { | |
197 | -// await loadHotProducts(); | |
198 | -// } else { | |
199 | -// await loadHotProductsMobile(); | |
200 | -// } | |
201 | -// } | |
202 | -// }); | |
203 | - | |
204 | -// // 监听路由变化 | |
205 | -// watch( | |
206 | -// () => route.fullPath, | |
207 | -// async () => { | |
208 | -// if (firstHotIndex.value) { | |
209 | -// if (width.value > 600) { | |
210 | -// await loadHotProducts(); | |
211 | -// } else { | |
212 | -// await loadHotProductsMobile(); | |
213 | -// } | |
214 | -// } | |
215 | -// } | |
216 | -// ); | |
217 | - | |
218 | -watch(currentIndex, (newIndex) => { | |
219 | - loadHotProducts(); // Call loadHotProducts when currentIndex changes | |
220 | -}); | |
221 | - | |
222 | -const loadHotProductsMobile = async () => { | |
223 | - hotLoadingMobile.value = true; | |
224 | - let { data: hotProductsMobile } = await useAsyncData( | |
225 | - "hotProducts", | |
226 | - () => | |
227 | - $fetch("/shop/product/hotProducts", { | |
228 | - method: "GET", | |
229 | - params: { | |
230 | - pageNo: currentIndexMobile.value, | |
231 | - pageSize: 4, | |
232 | - }, | |
233 | - }), | |
234 | - { | |
235 | - server: true, // 仅在服务器端获取数据 | |
236 | - } | |
237 | - ); | |
238 | - hotTotalMobile.value = hotProductsMobile.value.data.total; | |
239 | - recommendListMobile.value = hotProductsMobile.value.data.records; | |
240 | - maxPageMobile.value = hotProductsMobile.value.data.pages; | |
241 | - // recommendImages.value = recommendList.value.slice(0, 10).map((item) => { | |
242 | - recommendImagesMobile.value = Array.from({ length: 4 }).map((_, index) => { | |
243 | - const item = recommendListMobile.value[index]; | |
244 | - if (!item) { | |
245 | - return null; | |
246 | - } | |
247 | - // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析 | |
248 | - if (typeof item.productimageliststore === "string") { | |
249 | - try { | |
250 | - item.productimageliststore = JSON.parse(item.productimageliststore); | |
251 | - } catch (error) { | |
252 | - item.productimageliststore = []; // 解析失败时,设置为空数组 | |
253 | - } | |
254 | - } | |
255 | - const ree = (item.productimageliststore = item?.productimageliststore.map( | |
256 | - (productItem: ProductImage) => ({ | |
257 | - ...productItem, | |
258 | - // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`, | |
259 | - url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`, | |
260 | - name: item.name, | |
261 | - productUrl: `https://www.canrud.com/products/detail/${item.id}`, | |
262 | - }) | |
263 | - )); | |
264 | - return ree; | |
265 | - }); | |
266 | - hotLoadingMobile.value = false; | |
267 | -}; | |
268 | -watch(currentIndexMobile, (newIndex) => { | |
269 | - loadHotProductsMobile(); // Call loadHotProducts when currentIndex changes | |
270 | -}); | |
271 | -watchEffect(async () => { | |
272 | - console.log("Current route:", route.fullPath, "Width:", width.value); | |
273 | - | |
274 | - if (firstHotIndex.value) { | |
275 | - if (width.value > 600) { | |
276 | - await loadHotProducts(); | |
277 | - } else { | |
278 | - await loadHotProductsMobile(); | |
279 | - } | |
280 | - } | |
281 | -}); | |
282 | 97 | watchEffect(() => { |
283 | 98 | // 遍历数组 |
284 | 99 | if (router.currentRoute.value.query.categories) { |
... | ... | @@ -424,9 +239,6 @@ watchEffect(async () => { |
424 | 239 | const length = computed(() => |
425 | 240 | productStore.total ? Math.ceil(productStore.total / productStore.pageSize) : 0 |
426 | 241 | ); |
427 | -const hotLength = computed(() => | |
428 | - hotTotalMobile.value ? Math.ceil(hotTotalMobile.value / 4) : 0 | |
429 | -); | |
430 | 242 | </script> |
431 | 243 | |
432 | 244 | <style scoped> | ... | ... |