|
|
@@ -28,11 +28,16 @@
|
|
|
<!-- 课程部分 -->
|
|
|
<div class="lower-box">
|
|
|
<div class="content-box">
|
|
|
+ <!-- 左切换按钮 -->
|
|
|
+ <div v-if="!showVideo" class="carousel-btn prev-btn" @click="prevSlide" :disabled="currentIndex === 0">
|
|
|
+ <el-icon class="btn-icon"><ArrowLeftBold /></el-icon>
|
|
|
+ </div>
|
|
|
+
|
|
|
<!-- 动态渲染课程内容 -->
|
|
|
<div
|
|
|
- v-for="item in courseItems"
|
|
|
+ v-for="(item, index) in displayItems"
|
|
|
:key="item.id"
|
|
|
- :class="item.positionClass"
|
|
|
+ :class="getPositionClass(index)"
|
|
|
@click="handleCourseItemClick(item)"
|
|
|
>
|
|
|
<div class="box-content">
|
|
|
@@ -40,6 +45,11 @@
|
|
|
<div class="box-text">{{ item.title }}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
+ <!-- 右切换按钮 -->
|
|
|
+ <div v-if="!showVideo" class="carousel-btn next-btn" @click="nextSlide" :disabled="currentIndex >= courseItems.length - 3">
|
|
|
+ <el-icon class="btn-icon"><ArrowRightBold /></el-icon>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
@@ -51,8 +61,8 @@
|
|
|
|
|
|
<script setup>
|
|
|
// 返回图标
|
|
|
-import { ArrowLeftBold } from '@element-plus/icons-vue';
|
|
|
-import { ref, onMounted } from 'vue';
|
|
|
+import { ArrowLeftBold, ArrowRightBold } from '@element-plus/icons-vue';
|
|
|
+import { ref, onMounted, computed } from 'vue';
|
|
|
// 导入路由
|
|
|
import { useRouter, useRoute } from 'vue-router';
|
|
|
// 导入接口
|
|
|
@@ -83,6 +93,33 @@ const courseItems = ref([])
|
|
|
const selectedCourseData = ref(null)
|
|
|
// 保存原始API返回的数据
|
|
|
const resData = ref([])
|
|
|
+// 轮播图当前索引
|
|
|
+const currentIndex = ref(0)
|
|
|
+
|
|
|
+// 显示的项目(每次显示3个)
|
|
|
+const displayItems = computed(() => {
|
|
|
+ return courseItems.value.slice(currentIndex.value, currentIndex.value + 3)
|
|
|
+})
|
|
|
+
|
|
|
+// 获取位置类
|
|
|
+const getPositionClass = (index) => {
|
|
|
+ const positionClasses = ['left-content-box', 'center-content-box', 'right-content-box']
|
|
|
+ return positionClasses[index]
|
|
|
+}
|
|
|
+
|
|
|
+// 上一页
|
|
|
+const prevSlide = () => {
|
|
|
+ if (currentIndex.value > 0) {
|
|
|
+ currentIndex.value = Math.max(0, currentIndex.value - 3)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 下一页
|
|
|
+const nextSlide = () => {
|
|
|
+ if (currentIndex.value < courseItems.value.length - 3) {
|
|
|
+ currentIndex.value = Math.min(courseItems.value.length - 3, currentIndex.value + 3)
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
// 组件挂载时获取路由参数设置标题
|
|
|
onMounted(() => {
|
|
|
@@ -121,7 +158,6 @@ onMounted(() => {
|
|
|
id: item.id,
|
|
|
title: item.bcName,
|
|
|
image: positionInfo.image,
|
|
|
- positionClass: positionInfo.positionClass,
|
|
|
contentType: item.bcContentType
|
|
|
})
|
|
|
})
|
|
|
@@ -342,4 +378,45 @@ const goBackIndex = () => {
|
|
|
color: #333;
|
|
|
text-align: center;
|
|
|
}
|
|
|
+
|
|
|
+/* 轮播图按钮样式 */
|
|
|
+.carousel-btn {
|
|
|
+ position: absolute;
|
|
|
+ top: 40%;
|
|
|
+ transform: translateY(-50%);
|
|
|
+ width: rpx(30);
|
|
|
+ height: rpx(30);
|
|
|
+ background-color: rgba(255, 255, 255, 0.8);
|
|
|
+ border-radius: 50%;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ cursor: pointer;
|
|
|
+ z-index: 10;
|
|
|
+ box-shadow: 0 rpx(5) rpx(10) rgba(0, 0, 0, 0.2);
|
|
|
+ transition: all 0.3s ease;
|
|
|
+}
|
|
|
+
|
|
|
+.carousel-btn:hover {
|
|
|
+ background-color: rgba(255, 255, 255, 1);
|
|
|
+ transform: translateY(-50%) scale(1.1);
|
|
|
+}
|
|
|
+
|
|
|
+.carousel-btn:disabled {
|
|
|
+ opacity: 0.5;
|
|
|
+ cursor: not-allowed;
|
|
|
+}
|
|
|
+
|
|
|
+.prev-btn {
|
|
|
+ left: 1%;
|
|
|
+}
|
|
|
+
|
|
|
+.next-btn {
|
|
|
+ right: 1%;
|
|
|
+}
|
|
|
+
|
|
|
+.btn-icon {
|
|
|
+ font-size: rpx(15);
|
|
|
+ color: #333;
|
|
|
+}
|
|
|
</style>
|