Proof of concept for image preview
This commit is contained in:
parent
86b460d09c
commit
c2dfa9be83
@ -67,6 +67,12 @@
|
|||||||
{{ a.file.mime }}
|
{{ a.file.mime }}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
<img
|
||||||
|
v-if="canPreview(a)"
|
||||||
|
:src="blobUrls.get(a.id)"
|
||||||
|
style="height: 20vh; min-height: 100px"
|
||||||
|
alt=""
|
||||||
|
>
|
||||||
<p>
|
<p>
|
||||||
<BaseButton
|
<BaseButton
|
||||||
v-tooltip="$t('task.attachment.downloadTooltip')"
|
v-tooltip="$t('task.attachment.downloadTooltip')"
|
||||||
@ -168,7 +174,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {ref, shallowReactive, computed} from 'vue'
|
import {ref, shallowReactive, computed, onMounted} from 'vue'
|
||||||
import {useDropZone} from '@vueuse/core'
|
import {useDropZone} from '@vueuse/core'
|
||||||
|
|
||||||
import User from '@/components/misc/user.vue'
|
import User from '@/components/misc/user.vue'
|
||||||
@ -222,6 +228,20 @@ function downloadAttachment(attachment: IAttachment) {
|
|||||||
|
|
||||||
const filesRef = ref<HTMLInputElement | null>(null)
|
const filesRef = ref<HTMLInputElement | null>(null)
|
||||||
|
|
||||||
|
const blobUrls = ref<Map<number, string>>(new Map())
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchBlobUrls(attachments.value as IAttachment[])
|
||||||
|
})
|
||||||
|
|
||||||
|
async function fetchBlobUrls(attachments: IAttachment[]) {
|
||||||
|
for (const attachment of attachments) {
|
||||||
|
const blobUrl = await attachmentService.getBlobUrl(attachment)
|
||||||
|
if (canPreview(attachment)) {
|
||||||
|
blobUrls.value.set(attachment.id, blobUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
function uploadNewAttachment() {
|
function uploadNewAttachment() {
|
||||||
const files = filesRef.value?.files
|
const files = filesRef.value?.files
|
||||||
|
|
||||||
@ -260,13 +280,17 @@ async function deleteAttachment() {
|
|||||||
const attachmentImageBlobUrl = ref<string | null>(null)
|
const attachmentImageBlobUrl = ref<string | null>(null)
|
||||||
|
|
||||||
async function viewOrDownload(attachment: IAttachment) {
|
async function viewOrDownload(attachment: IAttachment) {
|
||||||
if (SUPPORTED_IMAGE_SUFFIX.some((suffix) => attachment.file.name.endsWith(suffix))) {
|
if (canPreview(attachment)) {
|
||||||
attachmentImageBlobUrl.value = await attachmentService.getBlobUrl(attachment)
|
attachmentImageBlobUrl.value = await attachmentService.getBlobUrl(attachment)
|
||||||
} else {
|
} else {
|
||||||
downloadAttachment(attachment)
|
downloadAttachment(attachment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canPreview(attachment: IAttachment): boolean {
|
||||||
|
return SUPPORTED_IMAGE_SUFFIX.some((suffix) => attachment.file.name.endsWith(suffix))
|
||||||
|
}
|
||||||
|
|
||||||
const copy = useCopyToClipboard()
|
const copy = useCopyToClipboard()
|
||||||
|
|
||||||
function copyUrl(attachment: IAttachment) {
|
function copyUrl(attachment: IAttachment) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user