Skip to content

Commit 50aad0b

Browse files
committed
fix: improve error handling and adjust image slider behavior in ImageGenerationCarousel and Swiper components
1 parent d479130 commit 50aad0b

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

custom/ImageGenerationCarousel.vue

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ onMounted(async () => {
168168
template = 'Generate image for field {{field}} in {{resource}}. No text should be on image.';
169169
}
170170
prompt.value = template;
171-
172-
const recordId = props.record[props.meta.recorPkFieldName];
173-
if (!recordId) {
174-
emit('error', {
175-
isError: true,
176-
errorMessage: 'Record ID not found, cannot generate images'
177-
});
178-
return;
179-
}
180171
});
181172
182173
@@ -334,7 +325,7 @@ async function generateImages() {
334325
335326
await nextTick();
336327
337-
sliderRef.value?.slideTo(images.value.length);
328+
sliderRef.value?.slideTo(images.value.length-1);
338329
339330
await nextTick();
340331

custom/Swiper.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,25 @@ const props = defineProps<{images: string[]}>()
1515
let swiperEl: any;
1616
1717
function getActiveIndex() {
18-
return swiperEl.swiper.activeIndex
18+
if (swiperEl && swiperEl.swiper) {
19+
return swiperEl.swiper.activeIndex;
20+
}
21+
return 0;
1922
}
2023
2124
function slideTo(index) {
22-
swiperEl.swiper.slideTo(index)
25+
26+
if (!swiperEl || !swiperEl.swiper) {
27+
setTimeout(() => slideTo(index), 50);
28+
return;
29+
}
30+
31+
if (index >= 0 && index < props.images.length) {
32+
swiperEl.swiper.update();
33+
setTimeout(() => {
34+
swiperEl.swiper.slideTo(index, 300);
35+
}, 10);
36+
}
2337
}
2438
2539
defineExpose({
@@ -29,24 +43,19 @@ defineExpose({
2943
3044
register()
3145
onMounted(() => {
32-
swiperEl = document.querySelector('swiper-container')
46+
swiperEl = document.querySelector('swiper-container')
3347
3448
const swiperParams: SwiperOptions = {
3549
slidesPerView: 1,
3650
navigation: true,
3751
pagination: {
3852
type: 'fraction',
3953
},
40-
on: {
41-
init() {
42-
console.log('swiper initialized')
43-
},
44-
},
54+
allowTouchMove: true,
4555
}
4656
4757
Object.assign(swiperEl, swiperParams)
4858
swiperEl.initialize()
49-
swiperEl.swiper;
5059
})
5160
</script>
5261

custom/VisionTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
<div v-if="isAiResponseReceivedImage[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])]">
9393
<div v-if="isInColumnImage(n)">
94-
<div class="mt-2 flex items-center justify-center gap-2">
94+
<div class="mt-2 flex items-center justify-start gap-2">
9595
<img v-if="isValidUrl(selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n])"
9696
:src="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
9797
class="w-20 h-20 object-cover rounded cursor-pointer border hover:border-blue-500 transition"

0 commit comments

Comments
 (0)