hejianhao
2026-04-02 0940d56748a73525790c350c393a5be960aab62c
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<template>
  <div class="image-grid-container">
    <div class="cell-box">
      <div
        v-for="(item, index) in images"
        :key="item.id || `in-${index}`"
        class="cell-wrapper"
      >
        <el-tooltip
          placement="top"
          :hide-after="0"
          :show-after="500"
          :enterable="false"
          :popper-class="'image-grid-tooltip'"
        >
          <template #content>
            <div class="custom-tip-body">
              <div class="text">名称:{{ item.name }}</div>
              <div class="text">路径:{{ item.path }}</div>
              <div class="text">尺寸:{{ item.size || '未知尺寸' }}</div>
              <div class="text">标注数量:{{ item.annotations ? item.annotations.length : 0 }}</div>
              <div class="text" v-if="selectedSplit">
                拆分分配:{{ getImageSplitTypeText(item) }}
              </div>
              <div class="text" v-if="getImageCategories(item).length > 0">
                标注类别:{{ getImageCategories(item).map(c => c.title).join(', ') }}
              </div>
              <div class="text" v-if="item.width && item.height">
                分辨率:{{ item.width }} × {{ item.height }}px
              </div>
            </div>
          </template>
          <div
            @click.stop="handleChange(item)"
            @dblclick="handleDetail(item)"
            class="cell"
            :class="{ active: currentImageId && item['id'] == currentImageId }"
          >
            <div class="image-container">
              <img
                :src="getImageUrl(item)"
                class="cell-img"
                @error="handleImageError"
              />
 
              <!-- 显示所有标注的类别标签 -->
              <div class="category-overlay" v-if="getImageCategories(item).length > 0">
                <CategoryTags :categories="getImageCategories(item)" :maxDisplay="3" />
              </div>
              
            </div>
            <div class="cell-title">{{ item["name"] }}</div>
          </div>
        </el-tooltip>
      </div>
    </div>
    
    <!-- 分页组件 -->
    <div class="pagination-wrapper" v-if="total > pageSize">
      <el-pagination
        v-model:current-page="currentPageValue"
        :page-size="pageSizeValue"
        :total="total"
        :page-sizes="[30, 50, 100, 200]"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      />
    </div>
  </div>
</template>
 
<script setup>
import { ref, watch } from 'vue';
import { CategoryTags } from '@/components';
import { getImageSplitTypeForTooltip, getImageCategories as getImageCategoriesUtil, handleImageError } from '@/utils/image/imageHelper';
 
const props = defineProps({
  images: {
    type: Array,
    default: () => []
  },
  total: {
    type: Number,
    default: 0
  },
  currentPage: {
    type: Number,
    default: 1
  },
  pageSize: {
    type: Number,
    default: 30
  },
  currentImageId: [String, Number],
  selectedSplit: Object,
  projectTypes: {
    type: Array,
    default: () => []
  },
  projectPath: String,
  imageUrlGetter: Function,
  imageCategoriesGetter: Function
});
 
const emit = defineEmits([
  'update:currentPage',
  'update:pageSize',
  'selectImage',
  'openImage'
]);
 
// 使用内部响应式变量来管理分页状态
const currentPageValue = ref(props.currentPage);
const pageSizeValue = ref(props.pageSize);
 
// 监听props变化
watch(() => props.currentPage, (val) => {
  currentPageValue.value = val;
});
 
watch(() => props.pageSize, (val) => {
  pageSizeValue.value = val;
});
 
// 获取图片URL
const getImageUrl = (item) => {
  if (props.imageUrlGetter) {
    return props.imageUrlGetter(item);
  }
  // 默认返回占位图
  return new URL("../../static/common/icon_loading.png", import.meta.url).href;
};
 
// 获取图片类别
const getImageCategories = (item) => {
  if (props.imageCategoriesGetter) {
    return props.imageCategoriesGetter(item);
  }
  return getImageCategoriesUtil(item, props.projectTypes);
};
 
// 获取图片拆分类型文本
const getImageSplitTypeText = (item) => {
  return getImageSplitTypeForTooltip(item, props.selectedSplit);
};
 
// 处理图片选择
const handleChange = (item) => {
  emit('selectImage', item);
};
 
// 处理图片双击
const handleDetail = (item) => {
  emit('openImage', item);
};
 
// 处理分页大小改变
const handleSizeChange = (val) => {
  pageSizeValue.value = val;
  currentPageValue.value = 1;
  emit('update:pageSize', val);
  emit('update:currentPage', 1);
};
 
// 处理页码改变
const handlePageChange = (page) => {
  currentPageValue.value = page;
  emit('update:currentPage', page);
  // 滚动到顶部
  const contentEl = document.querySelector('.image-grid-container .cell-box');
  if (contentEl) {
    contentEl.scrollTop = 0;
  }
};
</script>
 
<style scoped lang="scss">
.image-grid-container {
  display: flex;
  flex-direction: column;
  height: 100%;
 
  .cell-box {
    display: grid;
    grid-template-columns: repeat(auto-fill, 120px);
    gap: 12px;
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    align-content: start;
    justify-content: center;
    box-sizing: border-box;
 
    .cell-wrapper {
      display: flex;
      justify-content: center;
    }
    
    // 响应式网格调整
    @media (max-width: 800px) {
      grid-template-columns: repeat(auto-fill, 110px);
      gap: 10px;
      padding: 10px;
      
      .cell {
        width: 110px;
        height: 140px;
      }
    }
    
    @media (max-width: 600px) {
      grid-template-columns: repeat(auto-fill, 100px);
      gap: 8px;
      padding: 8px;
      
      .cell {
        width: 100px;
        height: 130px;
      }
    }
 
    .cell {
      border-radius: 8px;
      width: 120px;
      height: 150px; // 固定高度
      background: #fff;
      display: flex;
      flex-direction: column;
      cursor: pointer;
      border: 2px solid #fff;
      box-sizing: border-box;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
      transition: box-shadow 0.2s ease, transform 0.2s ease;
 
      &:hover {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
        transform: translateY(-2px);
      }
 
      .image-container {
        position: relative;
        width: 100%;
        height: 120px;
        border-radius: 6px 6px 0 0;
        overflow: hidden;
      }
 
      .cell-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        background: #f5f7fa;
        background-image: url('../../static/common/icon_loading.png');
        background-position: center;
        background-repeat: no-repeat;
        background-size: 40px 40px;
        display: block;
        transition: transform 0.2s ease;
      }
 
      &:hover .cell-img {
        transform: scale(1.02);
      }
 
      .category-overlay {
        position: absolute;
        top: 4px;
        left: 4px;
        right: 4px;
        z-index: 2;
        pointer-events: none;
      }
 
      .cell-title {
        font-size: 10px;
        font-weight: 500;
        color: #222;
        height: 30px; // 固定标题高度
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 3px 4px;
        box-sizing: border-box;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.2;
        text-align: center;
        border-radius: 0 0 6px 6px;
      }
    }
 
    .active {
      border: 2px solid #2165f8;
      position: relative;
 
      .cell-title {
        color: #2165f8;
      }
    }
 
    .active::before {
      position: absolute;
      right: -4px;
      top: -4px;
      z-index: 2;
      width: 16px;
      height: 16px;
      content: "✔";
      font-size: 10px;
      color: #fff;
      background: #2165f8;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  
  // 分页组件样式
  .pagination-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    
    :deep(.el-pagination) {
      font-weight: 500;
      
      .el-pagination__total {
        color: #606266;
      }
      
      .el-input__inner {
        border-radius: 4px;
      }
      
      .btn-prev,
      .btn-next,
      .el-pager li {
        border-radius: 4px;
        margin: 0 2px;
      }
      
      .el-pager li.active {
        background-color: #2165f8;
      }
    }
  }
}
 
// tooltip 样式
.custom-tip-body {
  padding: 8px;
  
  .text {
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.4;
    color: #fff;
    word-break: break-word;
    
    &:first-child {
      margin-top: 0;
    }
    
    &:last-child {
      margin-bottom: 0;
    }
  }
}
 
// 确保tooltip在最上层
:global(.image-grid-tooltip) {
  z-index: 9999 !important;
  max-width: 320px !important;
  
  .el-tooltip__popper {
    max-width: 320px !important;
  }
}
</style>