Preview.vue
2.22 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<template>
<div :class="prefixCls">
<PreviewGroup>
<slot v-if="!imageList || $slots.default"></slot>
<template v-else>
<template v-for="item in getImageList" :key="item.src">
<Image v-bind="item">
<template #placeholder v-if="item.placeholder">
<Image v-bind="item" :src="item.placeholder" :preview="false" />
</template>
</Image>
</template>
</template>
</PreviewGroup>
</div>
</template>
<script lang="ts">
import type { PropType } from 'vue';
import { defineComponent, computed } from 'vue';
import { Image } from 'ant-design-vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { propTypes } from '/@/utils/propTypes';
import { isString } from '/@/utils/is';
interface ImageProps {
alt?: string;
fallback?: string;
src: string;
width: string | number;
height?: string | number;
placeholder?: string | boolean;
preview?:
| boolean
| {
visible?: boolean;
onVisibleChange?: (visible: boolean, prevVisible: boolean) => void;
getContainer: string | HTMLElement | (() => HTMLElement);
};
}
type ImageItem = string | ImageProps;
export default defineComponent({
name: 'ImagePreview',
components: {
Image,
PreviewGroup: Image.PreviewGroup,
},
props: {
functional: propTypes.bool,
imageList: {
type: Array as PropType<ImageItem[]>,
},
},
setup(props) {
const { prefixCls } = useDesign('image-preview');
const getImageList = computed(() => {
const { imageList } = props;
if (!imageList) {
return [];
}
return imageList.map((item) => {
if (isString(item)) {
return {
src: item,
placeholder: false,
};
}
return item;
});
});
return {
prefixCls,
getImageList,
};
},
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-image-preview';
.@{prefix-cls} {
.ant-image {
margin-right: 10px;
}
.ant-image-preview-operations {
background-color: rgba(0, 0, 0, 0.4);
}
}
</style>