11<script setup lang="ts">
22import { Dialog , DialogContent } from ' ./dialog'
33
4- defineProps <{
5- src: string
4+ const props = defineProps <{
5+ src: string | string []
6+ index? : number
67}>()
78
89const isOpen = defineModel <boolean >()
910
11+ // 多图操作
12+ const index = ref (props .index ?? 0 )
13+ const srcList = computed (() => {
14+ if (Array .isArray (props .src )) {
15+ return props .src
16+ }
17+ return [props .src ]
18+ })
19+ function handlePrev() {
20+ index .value = index .value - 1
21+ if (index .value < 0 ) {
22+ index .value = srcList .value .length - 1
23+ }
24+ }
25+ function handleNext() {
26+ index .value = index .value + 1
27+ if (index .value >= srcList .value .length ) {
28+ index .value = 0
29+ }
30+ }
31+ watch (index , resetImageState )
32+
1033// 图片操作相关状态
1134const scale = ref (1 )
1235const rotate = ref (0 )
@@ -101,7 +124,7 @@ function handleAnimationEnd() {
101124 <DialogContent class =" size-full" @animation-end =" handleAnimationEnd" >
102125 <div class =" relative size-full flex-center" @wheel =" handleWheel" >
103126 <img
104- :src =" src "
127+ :src =" srcList[index] "
105128 class =" mx-auto max-h-full max-w-full object-contain"
106129 :class =" {
107130 'transition-all duration-300': !isDragging,
@@ -112,6 +135,17 @@ function handleAnimationEnd() {
112135 }"
113136 @mousedown.prevent =" handleMouseDown"
114137 >
138+ <template v-if =" srcList .length > 1 " >
139+ <div class =" absolute bottom-20 left-1/2 text-sm text-muted-foreground -translate-x-1/2" >
140+ {{ index + 1 }} / {{ srcList.length }}
141+ </div >
142+ <FaButton variant =" ghost" size =" icon" class =" absolute left-4 top-1/2 rounded-full bg-muted/50 -translate-y-1/2" @click =" handlePrev" >
143+ <FaIcon name =" i-lucide:chevron-left" class =" size-6" />
144+ </FaButton >
145+ <FaButton variant =" ghost" size =" icon" class =" absolute right-4 top-1/2 rounded-full bg-muted/50 -translate-y-1/2" @click =" handleNext" >
146+ <FaIcon name =" i-lucide:chevron-right" class =" size-6" />
147+ </FaButton >
148+ </template >
115149 <FaButtonGroup class =" absolute bottom-4 left-1/2 scale-125 -translate-x-1/2" >
116150 <FaButton variant =" outline" size =" icon" class =" border-none bg-muted/50" @click =" handleZoomIn" >
117151 <FaIcon name =" i-carbon:zoom-in" class =" size-5" />
0 commit comments