wupengfei
2025-02-17 7ab49073679e738a11c33d0b094fe7308e83fd51
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
  <div class="image-grid-wrapper">
    <nut-grid square :gutter="gutter" :column-num="columnNum" :center="false">
      <nut-grid-item
        v-for="item in images"
        :key="item.src"
        class="image-grid-file-list-item-wrapper"
      >
        <div class="image-grid-file-list-item img-grid">
          <PreviewImage
            :src="setOSSLink(item.src)"
            class="image-grid-img"
            wrapperClassName="image-grid-img-wrapper"
            :urls="previewUrls"
          />
        </div>
      </nut-grid-item>
    </nut-grid>
    <!-- <div v-else-if="images.length === 1" class="image-grid-file-list-item img">
      <AutoWidthImage
        wrapperClassName="image-normal-img"
        openScale
        :src="setOSSLink(images[0].src)"
      />
    </div> -->
  </div>
</template>
 
<script setup lang="ts">
import AutoWidthImage from './AutoWidthImage.vue';
import PreviewImage from './PreviewImage.vue';
import { setOSSLink } from '@12333/utils';
import { computed } from 'vue';
 
defineOptions({
  name: 'ImageGrid',
});
 
type Props = {
  imageList: {
    fileUrl?: string;
    [key: string]: any;
  }[];
  gutter?: number;
  columnNum?: number;
};
 
const props = withDefaults(defineProps<Props>(), {
  gutter: 20,
  columnNum: 3,
});
 
const images = computed(() =>
  props.imageList.map((item) => ({
    src: setOSSLink(item.fileUrl),
  }))
);
 
const previewUrls = computed(() => images.value.map((item) => item.src));
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.image-grid-wrapper {
  // margin: -10px;
  // display: flex;
  // flex-wrap: wrap;
  margin-bottom: 20px;
  width: 100%;
 
  .nut-grid {
    padding: 0 !important;
    width: 100%;
  }
 
  .image-grid-file-list-item-wrapper {
    .nut-grid-item__content--square {
      padding: 0;
      border: none;
      display: block;
    }
  }
 
  .image-grid-file-list-item {
    padding: 5px;
    box-sizing: border-box;
 
    &.video {
      // width: 300px;
      // height: 150px;
      max-width: 66%;
    }
 
    &.img {
      // width: 450px;
      // max-height: 400px;
      overflow: hidden;
      // height: auto;
      // height: 150px;
      width: 66%;
      display: flex;
    }
 
    &.img-grid {
      // width: 33%;
      width: 100%;
      height: 100%;
    }
 
    .image-grid-img-wrapper {
      overflow: hidden;
      @include hairline-surround;
      box-sizing: border-box;
      border-radius: 8px;
    }
 
    .image-grid-img {
      width: 100%;
      height: 100%;
      /* object-fit: cover; */
    }
 
    .image-normal-img {
      @include hairline-surround;
      width: auto;
      height: auto;
    }
 
    .image-grid-video {
      width: 100%;
      height: 100%;
    }
  }
}
</style>