From 46848b3c8425605dbc513e0baa917856342ac184 Mon Sep 17 00:00:00 2001 From: Type-32 <87076491+Type-32@users.noreply.github.com> Date: Fri, 12 Jul 2024 22:44:27 +0800 Subject: [PATCH] Changed Table Interaction and Preview Modal Signed-off-by: Type-32 <87076491+Type-32@users.noreply.github.com> --- app/components/MediaBrowserTable.vue | 57 +++- app/components/TiptapEditor.vue | 387 ++++++++++++++---------- app/composables/useMedia.ts | 18 +- app/layouts/DashboardLayout.vue | 2 +- app/pages/admin/article/[articleId].vue | 6 +- 5 files changed, 296 insertions(+), 174 deletions(-) diff --git a/app/components/MediaBrowserTable.vue b/app/components/MediaBrowserTable.vue index 10abe01..eb7203b 100644 --- a/app/components/MediaBrowserTable.vue +++ b/app/components/MediaBrowserTable.vue @@ -13,8 +13,11 @@ const columns = [ } ] +const $toast = useToast() + const emits = defineEmits<{ (e: 'onforwards', fordir: string, forPseudo: string): void + (e: 'update:modelValue', value: any[]): void }>() const props = defineProps({ @@ -36,6 +39,17 @@ const props = defineProps({ } }) +const localModelValue = ref(props.modelValue || []) +// Watch for changes in the prop and update the local ref + +watch(() => localModelValue.value, () => { + emits('update:modelValue', localModelValue.value) +}) + +watch(() => props.modelValue, (newValue) => { + localModelValue.value = newValue || [] +}, { deep: true }) + const handleForwards = async (fordir: string, forPseudo: string) => { emits('onforwards', fordir, forPseudo) if(props.routeForwards) { @@ -48,13 +62,13 @@ function joinUrl(str: string): string{ return runtimeConfig.public.siteUrl + str } -function select (row: any) { +function select(row: any) { //@ts-ignore - const index = props.modelValue.findIndex((item) => item.id === row.id) + const index = localModelValue.value.findIndex((item) => item.id === row.id) if (index === -1) { - props.modelValue.push(row as never) + localModelValue.value.push(row) } else { - props.modelValue.splice(index, 1) + localModelValue.value.splice(index, 1) } } @@ -69,14 +83,42 @@ function parseAndFormatDate(dateString: string): string { return `${year}/${month}/${day}, ${hours}:${minutes}`; } + +function copyFileUrl(fileUrl: string) { + const textarea = document.createElement('textarea'); + textarea.value = fileUrl; + + // Set the textarea to be out of view + textarea.style.position = 'absolute'; + textarea.style.left = '-9999px'; + + // Append the textarea to the DOM + document.body.appendChild(textarea); + + // Select the text inside the textarea + textarea.select(); + + try { + document.execCommand('copy'); + $toast.add({title: 'Copied File URL to Clipboard.', color: 'green'}) + } catch (err) { + console.error('Unable to copy text to clipboard:', err); + $toast.add({title: `Unable to copy text to clipboard: ${err}`, color: 'red'}) + } finally { + document.body.removeChild(textarea); + } +} + +const imagePreviewModal = ref(false), previewingImage = ref('') - + - {{row.fileName}} + {{row.fileName}} + @@ -86,6 +128,9 @@ function parseAndFormatDate(dateString: string): string { {{ parseAndFormatDate(row.updatedAt) }} + + +