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

289 lines
8.0 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">
2026-05-28 08:36:32 +08:00
<a-image :src="item.url" />
<!-- <img :src="item.url" :alt="item.title" /> -->
2026-05-26 19:30:22 +08:00
</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">
2026-05-28 08:36:32 +08:00
<LeftOutlined @click="prevSlide" :class="{ 'disabled': currentIndex === 0 }"
:style="{ cursor: currentIndex === 0 ? 'not-allowed' : 'pointer' }" />
2026-05-26 19:30:22 +08:00
<div class="pagination-dots">
<span v-for="(item, index) in originalMediaData" :key="index" class="dot-item"
:class="{ 'active': currentIndex === index }" @click="jumpToSlide(index)" />
</div>
2026-05-28 08:36:32 +08:00
<RightOutlined @click="nextSlide" :class="{ 'disabled': currentIndex === originalMediaData.length - 1 }"
:style="{ cursor: currentIndex === originalMediaData.length - 1 ? 'not-allowed' : 'pointer' }" />
2026-05-26 19:30:22 +08:00
</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;
2026-05-28 08:36:32 +08:00
url: string;
2026-05-26 19:30:22 +08:00
}>;
2026-05-28 08:36:32 +08:00
index:any
2026-05-26 19:30:22 +08:00
}>();
interface MediaItem {
title: string;
description: string;
2026-05-28 08:36:32 +08:00
url: string;
2026-05-26 19:30:22 +08:00
}
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,
2026-05-28 08:36:32 +08:00
url: item.url
2026-05-26 19:30:22 +08:00
}));
}
};
2026-05-28 08:36:32 +08:00
// 根据 index prop 设置当前索引
const setCurrentIndexFromProps = () => {
if (props.index !== undefined && props.index !== null && originalMediaData.value.length > 0) {
const validIndex = Math.max(0, Math.min(props.index, originalMediaData.value.length - 1));
currentIndex.value = validIndex;
} else {
currentIndex.value = 0;
}
};
2026-05-26 19:30:22 +08:00
// 计算轨道样式 - 完全按照 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(() => {
2026-05-28 08:36:32 +08:00
console.log('ArtsDetail mounted - props.index:', props.index, 'props.dataSource.length:', props.dataSource?.length);
2026-05-26 19:30:22 +08:00
initOriginalData();
2026-05-28 08:36:32 +08:00
setCurrentIndexFromProps();
console.log('After setCurrentIndexFromProps - currentIndex.value:', currentIndex.value);
2026-05-26 19:30:22 +08:00
});
2026-05-28 08:36:32 +08:00
// 只监听 dataSource 变化,不监听 index 变化
2026-05-26 19:30:22 +08:00
watch(
() => props.dataSource,
(newData) => {
if (newData && newData.length > 0) {
2026-05-28 08:36:32 +08:00
// 数据更新时重新初始化
2026-05-26 19:30:22 +08:00
initOriginalData();
2026-05-28 08:36:32 +08:00
// 重置索引为 0 或根据当前 props.index 设置
setCurrentIndexFromProps();
2026-05-26 19:30:22 +08:00
}
},
{ 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;
2026-05-28 08:36:32 +08:00
&:hover:not(.disabled) {
2026-05-26 19:30:22 +08:00
color: #4a6fd4;
transform: scale(1.1);
}
2026-05-28 08:36:32 +08:00
&.disabled {
2026-05-26 19:30:22 +08:00
color: #d9d9d9;
2026-05-28 08:36:32 +08:00
cursor: not-allowed !important;
2026-05-26 19:30:22 +08:00
}
}
}
}
</style>