WholeProcessPlatform/frontend/src/components/carouselIntroduce/ArtsDetail.vue

270 lines
6.9 KiB
Vue
Raw Normal View History

2026-05-26 19:30:22 +08:00
<!-- ArtsDetail.vue -->
<template>
<div class="arts-detail">
<div class="card-container">
<div class="card_left">
<div class="card_img">
<div class="carousel-wrapper">
<div class="carousel-inner">
<div class="carousel-track" :style="trackStyle">
<div v-for="(item, index) in originalMediaData" :key="index" class="carousel-item">
<img :src="item.image" :alt="item.title" />
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card_right">
<div class="card_text_title"></div>
<div class="card_text_content">
{{ currentDescription }}
</div>
</div>
</div>
<div style="width: 100%;display: flex;justify-content: center;">
<div class="card_button">
<LeftOutlined @click="prevSlide" />
<div class="pagination-dots">
<span v-for="(item, index) in originalMediaData" :key="index" class="dot-item"
:class="{ 'active': currentIndex === index }" @click="jumpToSlide(index)" />
</div>
<RightOutlined @click="nextSlide" />
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, computed, onMounted, watch } from 'vue';
import { LeftOutlined, RightOutlined } from '@ant-design/icons-vue';
defineOptions({
name: 'ArtsDetail'
});
const props = defineProps<{
dataSource: Array<{
title: string;
description: string;
image: string;
}>;
}>();
interface MediaItem {
title: string;
description: string;
image: string;
}
const originalMediaData = ref<MediaItem[]>([]);
const currentIndex = ref(0);
// 初始化数据
const initOriginalData = () => {
if (props.dataSource && props.dataSource.length > 0) {
originalMediaData.value = props.dataSource.map(item => ({
title: item.title,
description: item.description,
image: item.image
}));
}
};
// 计算轨道样式 - 完全按照 React 版本的逻辑
const trackStyle = computed(() => {
return {
transform: `translateX(calc((68.8px - 48vw) * ${currentIndex.value}))`
};
});
// 切换到下一张
const nextSlide = () => {
if (currentIndex.value < originalMediaData.value.length - 1) {
currentIndex.value++;
}
};
// 切换到上一张
const prevSlide = () => {
if (currentIndex.value > 0) {
currentIndex.value--;
}
};
// 跳转到指定页面
const jumpToSlide = (targetIndex: number) => {
currentIndex.value = targetIndex;
};
// 计算当前显示的描述文字
const currentDescription = computed(() => {
return originalMediaData.value[currentIndex.value]?.description || '';
});
// 页面加载时执行
onMounted(() => {
initOriginalData();
});
// 监听 dataSource 变化
watch(
() => props.dataSource,
(newData) => {
if (newData && newData.length > 0) {
currentIndex.value = 0;
initOriginalData();
}
},
{ deep: true }
);
</script>
<style lang="scss" scoped>
.arts-detail {
width: 100%;
box-sizing: border-box;
.card-container {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
}
.card_left {
// flex: 6;
width: 60%;
height: 630px;
padding: 12px;
border: 1px solid rgba(0, 0, 0, 0.12);
box-sizing: border-box;
.card_img {
width: 100%;
height: 100%;
padding: 12px;
border: 1px solid rgba(0, 0, 0, 0.12);
overflow: hidden;
box-sizing: border-box;
}
.carousel-wrapper {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
.carousel-inner {
width: 100%;
height: 100%;
overflow: hidden;
}
.carousel-track {
height: 100%;
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
transition: transform 0.3s ease-in-out;
.carousel-item {
width: calc(48vw - 80.8px);
flex: 0 0 calc(48vw - 80.8px);
height: 100%;
margin-right: 12px;
display: flex;
justify-content: center;
align-items: center;
img {
max-height: 100%;
max-width: 100%;
border: none;
object-fit: contain;
}
}
}
}
}
.card_right {
// flex: 4;
width: 40%;
height: 630px;
padding-left: 40px;
box-sizing: border-box;
.card_text_title {
width: 6px;
height: 24px;
background-color: rgb(108, 164, 247);
box-sizing: border-box;
}
.card_text_content {
width: 100%;
height: 96%;
padding: 0px 16px 16px 0px;
box-sizing: border-box;
line-height: 1.5;
overflow: auto;
font-size: 20px;
text-indent: 2em;
}
}
.card_button {
display: flex;
// justify-content: space-between;
align-items: center;
padding: 16px 0;
box-sizing: border-box;
.pagination-dots {
display: flex;
align-items: center;
.dot-item {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #adaaaa;
margin: 0 6px;
cursor: pointer;
transition: all 0.3s ease;
&:hover {
background-color: #8a8a8a;
transform: scale(1.1);
}
&.active {
background-color: #5E9BFE;
transform: scale(1.2);
}
}
}
:deep(.anticon) {
font-size: 24px;
cursor: pointer;
color: #6c8cf7;
transition: all 0.3s;
&:hover:not([disabled]) {
color: #4a6fd4;
transform: scale(1.1);
}
&[disabled] {
color: #d9d9d9;
cursor: not-allowed;
}
}
}
}
</style>