ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
<script lang="ts">
import type { PropType } from 'vue';
 
import { computed, defineComponent } from 'vue';
 
import { isString } from '@jnpf/utils';
 
import { Image } from 'ant-design-vue';
 
interface ImageProps {
  alt?: string;
  fallback?: string;
  height?: number | string;
  placeholder?: boolean | string;
  preview?:
    | boolean
    | {
        getContainer: (() => HTMLElement) | HTMLElement | string;
        onVisibleChange?: (visible: boolean, prevVisible: boolean) => void;
        visible?: boolean;
      };
  src: string;
  width: number | string;
}
 
type ImageItem = ImageProps | string;
 
export default defineComponent({
  components: {
    Image,
    PreviewGroup: Image.PreviewGroup,
  },
  name: 'ImagePreview',
  props: {
    functional: Boolean,
    imageList: {
      default: () => [],
      type: Array as PropType<ImageItem[]>,
    },
  },
  setup(props) {
    const getImageList = computed((): any[] => {
      const { imageList } = props;
      if (!imageList) return [];
      return (imageList as any).map((item) => {
        if (isString(item)) {
          return {
            placeholder: false,
            src: item,
          };
        }
        return item;
      });
    });
 
    return {
      getImageList,
    };
  },
});
</script>
<template>
  <div class="jnpf-image-preview">
    <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 v-if="item.placeholder" #placeholder>
              <Image v-bind="item" :preview="false" :src="item.placeholder" />
            </template>
          </Image>
        </template>
      </template>
    </PreviewGroup>
  </div>
</template>
<style lang="scss">
.jnpf-image-preview {
  .ant-image {
    margin-right: 10px;
  }
 
  .ant-image-preview-operations {
    background-color: rgb(0 0 0 / 40%);
  }
}
</style>