2022-08-12 08:15:08 +00:00
|
|
|
<script lang="ts" setup>
|
2024-06-26 10:42:50 +00:00
|
|
|
import LazyImage from "@/components/image/LazyImage.vue";
|
|
|
|
import { formatDatetime } from "@/utils/date";
|
|
|
|
import { isImage } from "@/utils/image";
|
|
|
|
import { coreApiClient } from "@halo-dev/api-client";
|
2023-04-23 02:49:32 +00:00
|
|
|
import {
|
2024-08-25 15:11:11 +00:00
|
|
|
IconRiPencilFill,
|
2023-04-23 02:49:32 +00:00
|
|
|
VButton,
|
|
|
|
VDescription,
|
|
|
|
VDescriptionItem,
|
2024-08-25 15:11:11 +00:00
|
|
|
VLoading,
|
2023-04-23 02:49:32 +00:00
|
|
|
VModal,
|
|
|
|
VSpace,
|
|
|
|
} from "@halo-dev/components";
|
2024-06-26 10:42:50 +00:00
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
2022-09-04 17:06:11 +00:00
|
|
|
import prettyBytes from "pretty-bytes";
|
2024-08-25 15:11:11 +00:00
|
|
|
import { computed, ref, toRefs } from "vue";
|
2023-04-26 07:32:12 +00:00
|
|
|
import AttachmentPermalinkList from "./AttachmentPermalinkList.vue";
|
2024-08-25 15:11:11 +00:00
|
|
|
import DisplayNameEditForm from "./DisplayNameEditForm.vue";
|
2022-08-12 08:15:08 +00:00
|
|
|
|
2022-09-04 17:06:11 +00:00
|
|
|
const props = withDefaults(
|
2022-08-15 09:56:13 +00:00
|
|
|
defineProps<{
|
2024-08-25 15:11:11 +00:00
|
|
|
name?: string;
|
2022-09-04 17:06:11 +00:00
|
|
|
mountToBody?: boolean;
|
2022-08-15 09:56:13 +00:00
|
|
|
}>(),
|
|
|
|
{
|
2024-08-25 15:11:11 +00:00
|
|
|
name: undefined,
|
2022-09-04 17:06:11 +00:00
|
|
|
mountToBody: false,
|
2022-08-15 09:56:13 +00:00
|
|
|
}
|
|
|
|
);
|
2022-08-12 08:15:08 +00:00
|
|
|
|
2022-08-15 12:31:51 +00:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: "close"): void;
|
|
|
|
}>();
|
2022-08-12 08:15:08 +00:00
|
|
|
|
2024-08-25 15:11:11 +00:00
|
|
|
const { name } = toRefs(props);
|
2022-09-04 17:06:11 +00:00
|
|
|
|
|
|
|
const onlyPreview = ref(false);
|
|
|
|
|
2024-08-25 15:11:11 +00:00
|
|
|
const { data: attachment, isLoading } = useQuery({
|
|
|
|
queryKey: ["core:attachment-by-name", name],
|
|
|
|
queryFn: async () => {
|
|
|
|
const { data } = await coreApiClient.storage.attachment.getAttachment({
|
|
|
|
name: name.value as string,
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
enabled: computed(() => !!name.value),
|
|
|
|
});
|
|
|
|
|
2023-02-23 09:08:12 +00:00
|
|
|
const policyName = computed(() => {
|
2024-08-25 15:11:11 +00:00
|
|
|
return attachment.value?.spec.policyName;
|
|
|
|
});
|
|
|
|
|
|
|
|
const groupName = computed(() => {
|
|
|
|
return attachment.value?.spec.groupName;
|
2023-02-23 09:08:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const { data: policy } = useQuery({
|
2024-08-25 15:11:11 +00:00
|
|
|
queryKey: ["core:attachment-policy-by-name", policyName],
|
2023-02-23 09:08:12 +00:00
|
|
|
queryFn: async () => {
|
|
|
|
if (!policyName.value) {
|
2022-09-04 17:06:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-02-23 09:08:12 +00:00
|
|
|
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } = await coreApiClient.storage.policy.getPolicy({
|
|
|
|
name: policyName.value,
|
|
|
|
});
|
2022-09-04 17:06:11 +00:00
|
|
|
|
2023-02-23 09:08:12 +00:00
|
|
|
return data;
|
|
|
|
},
|
|
|
|
enabled: computed(() => !!policyName.value),
|
|
|
|
});
|
2022-09-04 17:06:11 +00:00
|
|
|
|
2024-08-25 15:11:11 +00:00
|
|
|
const { data: group } = useQuery({
|
|
|
|
queryKey: ["core:attachment-group-by-name", groupName],
|
|
|
|
queryFn: async () => {
|
|
|
|
if (!groupName.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { data } = await coreApiClient.storage.group.getGroup({
|
|
|
|
name: groupName.value,
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
enabled: computed(() => !!groupName.value),
|
|
|
|
});
|
|
|
|
|
|
|
|
const showDisplayNameForm = ref(false);
|
2022-08-12 08:15:08 +00:00
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<VModal
|
2023-03-23 08:54:33 +00:00
|
|
|
:title="
|
|
|
|
$t('core.attachment.detail_modal.title', {
|
|
|
|
display_name: attachment?.spec.displayName || '',
|
|
|
|
})
|
|
|
|
"
|
2022-08-12 08:15:08 +00:00
|
|
|
:width="1000"
|
2022-09-04 17:06:11 +00:00
|
|
|
:mount-to-body="mountToBody"
|
2023-02-17 06:52:13 +00:00
|
|
|
:layer-closable="true"
|
2022-09-04 17:06:11 +00:00
|
|
|
height="calc(100vh - 20px)"
|
2023-04-23 02:49:32 +00:00
|
|
|
:body-class="['!p-0']"
|
2024-04-12 09:46:07 +00:00
|
|
|
@close="emit('close')"
|
2022-08-12 08:15:08 +00:00
|
|
|
>
|
|
|
|
<template #actions>
|
2022-09-04 17:06:11 +00:00
|
|
|
<slot name="actions"></slot>
|
2022-08-12 08:15:08 +00:00
|
|
|
</template>
|
2024-08-25 15:11:11 +00:00
|
|
|
<div>
|
|
|
|
<VLoading v-if="isLoading" />
|
|
|
|
<div v-else class="overflow-hidden bg-white">
|
|
|
|
<div
|
|
|
|
v-if="onlyPreview && isImage(attachment?.spec.mediaType)"
|
|
|
|
class="flex justify-center p-4"
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
v-tooltip.bottom="
|
|
|
|
$t('core.attachment.detail_modal.preview.click_to_exit')
|
2023-04-23 02:49:32 +00:00
|
|
|
"
|
2024-08-25 15:11:11 +00:00
|
|
|
:alt="attachment?.spec.displayName"
|
|
|
|
:src="attachment?.status?.permalink"
|
|
|
|
class="w-auto transform-gpu cursor-pointer rounded"
|
|
|
|
@click="onlyPreview = !onlyPreview"
|
2023-04-23 02:49:32 +00:00
|
|
|
/>
|
2024-08-25 15:11:11 +00:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<VDescription>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.preview')"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
v-if="isImage(attachment?.spec.mediaType)"
|
|
|
|
@click="onlyPreview = !onlyPreview"
|
|
|
|
>
|
|
|
|
<LazyImage
|
|
|
|
:alt="attachment?.spec.displayName"
|
|
|
|
:src="attachment?.status?.permalink"
|
|
|
|
classes="max-w-full cursor-pointer rounded sm:max-w-[50%]"
|
|
|
|
>
|
|
|
|
<template #loading>
|
|
|
|
<span class="text-gray-400">
|
|
|
|
{{ $t("core.common.status.loading") }}...
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<template #error>
|
|
|
|
<span class="text-red-400">
|
|
|
|
{{ $t("core.common.status.loading_error") }}
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</LazyImage>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="attachment?.spec.mediaType?.startsWith('video/')">
|
|
|
|
<video
|
|
|
|
:src="attachment.status?.permalink"
|
|
|
|
controls
|
|
|
|
class="max-w-full rounded sm:max-w-[50%]"
|
|
|
|
>
|
|
|
|
{{
|
|
|
|
$t("core.attachment.detail_modal.preview.video_not_support")
|
|
|
|
}}
|
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="attachment?.spec.mediaType?.startsWith('audio/')">
|
|
|
|
<audio :src="attachment.status?.permalink" controls>
|
|
|
|
{{
|
|
|
|
$t("core.attachment.detail_modal.preview.audio_not_support")
|
|
|
|
}}
|
|
|
|
</audio>
|
|
|
|
</div>
|
|
|
|
<span v-else>
|
|
|
|
{{ $t("core.attachment.detail_modal.preview.not_support") }}
|
|
|
|
</span>
|
|
|
|
</VDescriptionItem>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.storage_policy')"
|
|
|
|
:content="policy?.spec.displayName"
|
|
|
|
>
|
|
|
|
</VDescriptionItem>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.group')"
|
|
|
|
:content="
|
|
|
|
group?.spec.displayName ||
|
|
|
|
$t('core.attachment.common.text.ungrouped')
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.display_name')"
|
|
|
|
>
|
|
|
|
<DisplayNameEditForm
|
|
|
|
v-if="showDisplayNameForm && attachment"
|
|
|
|
:attachment="attachment"
|
|
|
|
@close="showDisplayNameForm = false"
|
|
|
|
/>
|
|
|
|
<div v-else class="flex items-center gap-3">
|
|
|
|
<span>
|
|
|
|
{{ attachment?.spec.displayName }}
|
|
|
|
</span>
|
|
|
|
<HasPermission :permissions="['system:attachments:manage']">
|
|
|
|
<IconRiPencilFill
|
|
|
|
class="cursor-pointer text-sm text-gray-600 hover:text-gray-900"
|
|
|
|
@click="showDisplayNameForm = true"
|
|
|
|
/>
|
|
|
|
</HasPermission>
|
|
|
|
</div>
|
|
|
|
</VDescriptionItem>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.media_type')"
|
|
|
|
:content="attachment?.spec.mediaType"
|
|
|
|
/>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.size')"
|
|
|
|
:content="prettyBytes(attachment?.spec.size || 0)"
|
|
|
|
/>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.owner')"
|
|
|
|
:content="attachment?.spec.ownerName"
|
|
|
|
/>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.creation_time')"
|
|
|
|
:content="formatDatetime(attachment?.metadata.creationTimestamp)"
|
|
|
|
/>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.permalink')"
|
|
|
|
>
|
|
|
|
<AttachmentPermalinkList :attachment="attachment" />
|
|
|
|
</VDescriptionItem>
|
|
|
|
</VDescription>
|
|
|
|
</div>
|
2023-04-23 02:49:32 +00:00
|
|
|
</div>
|
2022-08-12 08:15:08 +00:00
|
|
|
</div>
|
2024-08-25 15:11:11 +00:00
|
|
|
|
2022-08-12 08:15:08 +00:00
|
|
|
<template #footer>
|
2022-09-04 17:06:11 +00:00
|
|
|
<VSpace>
|
2024-04-12 09:46:07 +00:00
|
|
|
<VButton type="default" @click="emit('close')">
|
2023-03-23 08:54:33 +00:00
|
|
|
{{ $t("core.common.buttons.close_and_shortcut") }}
|
|
|
|
</VButton>
|
2022-09-04 17:06:11 +00:00
|
|
|
<slot name="footer" />
|
|
|
|
</VSpace>
|
2022-08-12 08:15:08 +00:00
|
|
|
</template>
|
|
|
|
</VModal>
|
|
|
|
</template>
|