Skip to content

Commit

Permalink
feat: image click to preview
Browse files Browse the repository at this point in the history
  • Loading branch information
OrenZhang committed Jul 30, 2024
1 parent 27619b5 commit 297b73e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/MessageContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const user = computed(() => store.state.user);
const regex = /(\.jpg|\.png|\.jepg|\.webp)/;
const emits = defineEmits(['reGenerate']);
const emits = defineEmits(['reGenerate', 'onImageClick']);
const onImageClick = (images, index) => emits('onImageClick', images[index]);
</script>

<template>
Expand Down Expand Up @@ -67,6 +69,7 @@ const emits = defineEmits(['reGenerate']);
v-show="message.content"
:text="message.content"
class="v-md-preview"
@image-click="onImageClick"
/>
<div v-if="message.file">
<a-image
Expand Down
16 changes: 15 additions & 1 deletion src/components/MessageDisplay.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import MessageContent from './MessageContent.vue';
import {onMounted, onUnmounted, watch} from 'vue';
import {onMounted, onUnmounted, ref, watch} from 'vue';
import {Role} from '@/constants';
// props
Expand Down Expand Up @@ -67,6 +67,14 @@ onUnmounted(() => {
el.removeEventListener('touchmove', () => {});
}
});
// image preview
const previewImageVisible = ref(false);
const previewImageUrl = ref('');
const onImageClick = (url) => {
previewImageUrl.value = url;
previewImageVisible.value = true;
};
</script>

<template>
Expand All @@ -89,10 +97,12 @@ onUnmounted(() => {
:is-last="index === localMessages.length - 1"
:chat-loading="chatLoading"
@re-generate="emits('reGenerate')"
@on-image-click="onImageClick"
/>
<message-content
v-show="promptForm.content"
:message="{role: Role.User, content: promptForm.content}"
@on-image-click="onImageClick"
/>
</a-space>
<div
Expand All @@ -108,6 +118,10 @@ onUnmounted(() => {
>
</div>
</div>
<a-image-preview
v-model:visible="previewImageVisible"
:src="previewImageUrl"
/>
</template>

<style scoped>
Expand Down

0 comments on commit 297b73e

Please sign in to comment.