gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<script setup lang="ts">
import type { CarouselProperty } from './config';
 
import { ref } from 'vue';
 
import { IconifyIcon } from '..\..\..\..\..\..\..\..\packages\icons\src';
 
import { Carousel, Image } from 'ant-design-vue';
 
/** 轮播图 */
defineOptions({ name: 'Carousel' });
 
defineProps<{ property: CarouselProperty }>();
 
const currentIndex = ref(0); // 当前索引
 
/** 处理索引变化 */
const handleIndexChange = (index: number) => {
  currentIndex.value = index + 1;
};
</script>
<template>
  <!-- 无图片 -->
  <div
    class="flex items-center justify-center bg-gray-300"
    :style="{
      height: property.items.length === 0 ? '250px' : `${property.height}px`,
    }"
    v-if="property.items.length === 0"
  >
    <IconifyIcon icon="tdesign:image" class="text-[120px] text-gray-800" />
  </div>
  <div v-else class="relative">
    <Carousel
      :autoplay="property.autoplay"
      :autoplay-speed="property.interval * 1000"
      :dots="property.indicator !== 'number'"
      @change="handleIndexChange"
      :style="{ height: `${property.height}px` }"
    >
      <div v-for="(item, index) in property.items" :key="index">
        <Image
          class="h-full w-full object-cover"
          :src="item.imgUrl"
          :preview="false"
        />
      </div>
    </Carousel>
    <div
      v-if="property.indicator === 'number'"
      class="absolute bottom-[10px] right-[10px] rounded-xl bg-black px-[8px] py-[2px] text-[10px] text-white opacity-40"
    >
      {{ currentIndex }} / {{ property.items.length }}
    </div>
  </div>
</template>