From d076088747d9c1e11d5887cfec21d6bfddf1a0e2 Mon Sep 17 00:00:00 2001
From: R2m1liA <15258427350@163.com>
Date: Sat, 1 Nov 2025 15:32:15 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E7=AB=96=E5=B1=8F?=
=?UTF-8?q?=E9=80=82=E9=85=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 首页Carousel高度根据屏幕宽度变化
- 首页推荐栏目卡片数量随屏幕宽度改变
---
.../pages/homepage/HomepageCarousel.vue | 6 ++
.../pages/homepage/HomepageProductSection.vue | 61 ++++++++++++++++--
.../homepage/HomepageSolutionSection.vue | 62 +++++++++++++++++--
3 files changed, 119 insertions(+), 10 deletions(-)
diff --git a/app/components/pages/homepage/HomepageCarousel.vue b/app/components/pages/homepage/HomepageCarousel.vue
index 6324594..0621c96 100644
--- a/app/components/pages/homepage/HomepageCarousel.vue
+++ b/app/components/pages/homepage/HomepageCarousel.vue
@@ -83,4 +83,10 @@
border-radius: 5px;
font-size: 14px;
}
+
+ @media (max-width: 768px) {
+ .homepage-carousel .el-carousel__item {
+ height: 50vw;
+ }
+ }
diff --git a/app/components/pages/homepage/HomepageProductSection.vue b/app/components/pages/homepage/HomepageProductSection.vue
index da4540a..9a4c9b0 100644
--- a/app/components/pages/homepage/HomepageProductSection.vue
+++ b/app/components/pages/homepage/HomepageProductSection.vue
@@ -7,19 +7,20 @@
('auto');
+ const perPage = ref(3);
+ const carouselItem = ref(null);
+
const { getImageUrl } = useDirectusImage();
+ const { height } = useElementSize(carouselItem);
const products = computed(() => props.homepageData?.recommendProducts || []);
+ const pages = computed(() =>
+ Math.ceil(products.value.length / perPage.value)
+ );
+
+ const updatePerPage = () => {
+ const width = window.innerWidth;
+ if (width < 768) {
+ perPage.value = 1;
+ } else if (width < 1024) {
+ perPage.value = 2;
+ } else {
+ perPage.value = 3;
+ }
+ };
+
+ const pageProducts = (n: number) => {
+ return products.value.slice((n - 1) * perPage.value, n * perPage.value);
+ };
const handleProductCardClick = (documentId: string) => {
// 使用路由导航到产品详情页
@@ -76,6 +100,21 @@
router.push(localePath(`/products/${documentId}`));
}
};
+
+ watch(height, (h) => {
+ if (h > 0) {
+ carouselHeight.value = h + 40 + 'px';
+ }
+ });
+
+ onMounted(() => {
+ updatePerPage();
+ window.addEventListener('resize', updatePerPage);
+ });
+
+ onBeforeUnmount(() => {
+ window.removeEventListener('resize', updatePerPage);
+ });
diff --git a/app/components/pages/homepage/HomepageSolutionSection.vue b/app/components/pages/homepage/HomepageSolutionSection.vue
index 3144c78..af1e062 100644
--- a/app/components/pages/homepage/HomepageSolutionSection.vue
+++ b/app/components/pages/homepage/HomepageSolutionSection.vue
@@ -5,19 +5,20 @@
('auto');
+ const perPage = ref(3);
+ const carouselItem = ref(null);
+
const { getImageUrl } = useDirectusImage();
+ const { height } = useElementSize(carouselItem);
const solutions = computed(
() => props.homepageData?.recommendSolutions || []
);
+ const pages = computed(() =>
+ Math.ceil(solutions.value.length / perPage.value)
+ );
+
+ const updatePerPage = () => {
+ const width = window.innerWidth;
+ if (width < 768) {
+ perPage.value = 1;
+ } else if (width < 1024) {
+ perPage.value = 2;
+ } else {
+ perPage.value = 3;
+ }
+ };
+
+ const pageSolutions = (n: number) => {
+ return solutions.value.slice((n - 1) * perPage.value, n * perPage.value);
+ };
const handleSolutionCardClick = (documentId: string) => {
// 使用路由导航到产品详情页
@@ -76,6 +100,22 @@
router.push(localePath(`/solutions/${documentId}`));
}
};
+
+ watch(height, (h) => {
+ if (h > 0) {
+ carouselHeight.value = h + 40 + 'px';
+ console.log('carouselHeight updated:', carouselHeight.value);
+ }
+ });
+
+ onMounted(() => {
+ updatePerPage();
+ window.addEventListener('resize', updatePerPage);
+ });
+
+ onBeforeUnmount(() => {
+ window.removeEventListener('resize', updatePerPage);
+ });