diff --git a/src/components/model-custom/index.vue b/src/components/model-custom/index.vue index 21ca53b9..30c735c0 100644 --- a/src/components/model-custom/index.vue +++ b/src/components/model-custom/index.vue @@ -2,14 +2,18 @@
- +
@@ -77,6 +81,13 @@ onBeforeMount(() => { } } }); +// 计算纵向显示的宽度 +const gap_width = computed(() => { + const model_number = Number(form.value.data_source_carousel_col); + // 计算间隔的空间。(gap * gap数量) / 模块数量 + let gap = (new_style.value.column_gap * (model_number - 1)) / model_number; + return `calc(${100 / model_number}% - ${gap}px)`; +}); //#region 计算比例大小,和每块当前的大小 const scale = ref(1); // 计算整体宽度和比例 @@ -124,6 +135,7 @@ const slides_per_group = ref(1); const dot_list = ref([]); const swiper_height = ref(390); const slides_per_view = ref(1); +const space_between = ref(0); // 内容参数的集合 watchEffect(() => { // 是否滚动 @@ -135,22 +147,26 @@ watchEffect(() => { } else { autoplay.value = false; } + // 间距 + space_between.value = form.value.data_source_direction == 'horizontal' ? new_style.value.column_gap : new_style.value.row_gap; + // 显示数量 + const data_source_carousel_col = Number(form.value.data_source_carousel_col); // 判断是平移还是整屏滚动 - slides_per_group.value = new_style.value.rolling_fashion == 'translation' ? 1 : Number(form.value.data_source_carousel_col); + slides_per_group.value = new_style.value.rolling_fashion == 'translation' ? 1 : Number(data_source_carousel_col); // 商品数量大于列数的时候,高度是列数,否则是当前的数量 - const col = data_source_content_list.value.length > Number(form.value.data_source_carousel_col) ? Number(form.value.data_source_carousel_col) : data_source_content_list.value.length; + const col = data_source_content_list.value.length > Number(data_source_carousel_col) ? Number(data_source_carousel_col) : data_source_content_list.value.length; slides_per_view.value = col; let num = 0; // 轮播图数量 if (!isEmpty(data_source_content_list.value)) { - num = new_style.value.rolling_fashion == 'translation' ? data_source_content_list.value.length : Math.ceil(data_source_content_list.value.length / Number(form.value.data_source_carousel_col)); + num = new_style.value.rolling_fashion == 'translation' ? data_source_content_list.value.length : Math.ceil(data_source_content_list.value.length / Number(data_source_carousel_col)); } const { padding_top, padding_bottom, margin_bottom, margin_top } = new_style.value.data_style; // 轮播图高度控制 if (form.value.data_source_direction == 'horizontal') { swiper_height.value = form.value.height * scale.value + padding_top + padding_bottom + margin_bottom + margin_top; } else { - swiper_height.value = (form.value.height * scale.value + padding_top + padding_bottom + margin_bottom + margin_top) * col; + swiper_height.value = (form.value.height * scale.value + padding_top + padding_bottom + margin_bottom + margin_top) * col + ((data_source_carousel_col - 1) * space_between.value); } dot_list.value = Array(num); // 更新轮播图的key,确保更换时能重新更新轮播图 diff --git a/src/components/model-custom/model-custom-content.vue b/src/components/model-custom/model-custom-content.vue index a8f4db42..adafd9a7 100644 --- a/src/components/model-custom/model-custom-content.vue +++ b/src/components/model-custom/model-custom-content.vue @@ -20,7 +20,7 @@ {{ item == 'vertical' ? '纵向展示' : item == 'vertical-scroll' ? '纵向滑动' : '横向滑动' }} -