2022-08-12 08:15:08 +00:00
|
|
|
<script lang="ts" setup>
|
2023-04-23 02:49:32 +00:00
|
|
|
import {
|
|
|
|
VButton,
|
|
|
|
VDescription,
|
|
|
|
VDescriptionItem,
|
|
|
|
VModal,
|
|
|
|
VSpace,
|
|
|
|
} from "@halo-dev/components";
|
2022-09-04 17:06:11 +00:00
|
|
|
import LazyImage from "@/components/image/LazyImage.vue";
|
2023-02-23 09:08:12 +00:00
|
|
|
import type { Attachment } from "@halo-dev/api-client";
|
2022-09-04 17:06:11 +00:00
|
|
|
import prettyBytes from "pretty-bytes";
|
2023-02-23 09:08:12 +00:00
|
|
|
import { computed, ref } from "vue";
|
2022-09-22 08:46:32 +00:00
|
|
|
import { apiClient } from "@/utils/api-client";
|
2022-09-04 17:06:11 +00:00
|
|
|
import { isImage } from "@/utils/image";
|
|
|
|
import { formatDatetime } from "@/utils/date";
|
|
|
|
import { useFetchAttachmentGroup } from "../composables/use-attachment-group";
|
2023-02-23 09:08:12 +00:00
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
2023-04-26 07:32:12 +00:00
|
|
|
import AttachmentPermalinkList from "./AttachmentPermalinkList.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<{
|
2023-04-26 07:32:12 +00:00
|
|
|
attachment: Attachment | undefined;
|
2022-09-04 17:06:11 +00:00
|
|
|
mountToBody?: boolean;
|
2022-08-15 09:56:13 +00:00
|
|
|
}>(),
|
|
|
|
{
|
2023-04-26 07:32:12 +00:00
|
|
|
attachment: 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
|
|
|
|
2023-02-23 09:08:12 +00:00
|
|
|
const { groups } = useFetchAttachmentGroup();
|
2022-09-04 17:06:11 +00:00
|
|
|
|
|
|
|
const onlyPreview = ref(false);
|
|
|
|
|
2023-02-23 09:08:12 +00:00
|
|
|
const policyName = computed(() => {
|
|
|
|
return props.attachment?.spec.policyName;
|
|
|
|
});
|
|
|
|
|
|
|
|
const { data: policy } = useQuery({
|
|
|
|
queryKey: ["attachment-policy", policyName],
|
|
|
|
queryFn: async () => {
|
|
|
|
if (!policyName.value) {
|
2022-09-04 17:06:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-02-23 09:08:12 +00:00
|
|
|
|
2022-09-04 17:06:11 +00:00
|
|
|
const { data } =
|
refactor: method parameters of api client (halo-dev/console#605)
<!-- Thanks for sending a pull request! Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->
#### What type of PR is this?
/kind improvement
/milestone 2.0
<!--
添加其中一个类别:
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind optimization
适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->
#### What this PR does / why we need it:
修改 api-client 的请求参数结构,改为所有参数由一个对象包裹,而不是将各个参数作为方法的参数,防止因为后端参数结构发生改变,或者生成 api-client 时参数顺序发生改变导致请求异常。如:
```diff
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
- formState.value.metadata.name,
- formState.value
+ {
+ name: formState.value.metadata.name,
+ group: formState.value,
+ }
);
```
#### Which issue(s) this PR fixes:
<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.
用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
None
#### Screenshots:
<!--
如果此 PR 有 UI 的改动,最好截图说明这个 PR 的改动。
If there are UI changes to this PR, it is best to take a screenshot to illustrate the changes to this PR.
eg.
Before:

After:

-->
None
#### Special notes for your reviewer:
/cc @halo-dev/sig-halo-admin
#### Does this PR introduce a user-facing change?
<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
None
```
2022-09-06 02:26:11 +00:00
|
|
|
await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy({
|
2023-02-23 09:08:12 +00:00
|
|
|
name: policyName.value,
|
refactor: method parameters of api client (halo-dev/console#605)
<!-- Thanks for sending a pull request! Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->
#### What type of PR is this?
/kind improvement
/milestone 2.0
<!--
添加其中一个类别:
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind optimization
适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->
#### What this PR does / why we need it:
修改 api-client 的请求参数结构,改为所有参数由一个对象包裹,而不是将各个参数作为方法的参数,防止因为后端参数结构发生改变,或者生成 api-client 时参数顺序发生改变导致请求异常。如:
```diff
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
- formState.value.metadata.name,
- formState.value
+ {
+ name: formState.value.metadata.name,
+ group: formState.value,
+ }
);
```
#### Which issue(s) this PR fixes:
<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.
用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
None
#### Screenshots:
<!--
如果此 PR 有 UI 的改动,最好截图说明这个 PR 的改动。
If there are UI changes to this PR, it is best to take a screenshot to illustrate the changes to this PR.
eg.
Before:

After:

-->
None
#### Special notes for your reviewer:
/cc @halo-dev/sig-halo-admin
#### Does this PR introduce a user-facing change?
<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
None
```
2022-09-06 02:26:11 +00:00
|
|
|
});
|
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
|
|
|
|
|
|
|
const getGroupName = (name: string | undefined) => {
|
2023-02-23 09:08:12 +00:00
|
|
|
const group = groups.value?.find((group) => group.metadata.name === name);
|
2022-09-04 17:06:11 +00:00
|
|
|
return group?.spec.displayName || name;
|
|
|
|
};
|
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>
|
|
|
|
<div class="overflow-hidden bg-white">
|
2022-09-04 17:06:11 +00:00
|
|
|
<div
|
|
|
|
v-if="onlyPreview && isImage(attachment?.spec.mediaType)"
|
2023-04-23 02:49:32 +00:00
|
|
|
class="flex justify-center p-4"
|
2022-09-04 17:06:11 +00:00
|
|
|
>
|
|
|
|
<img
|
2023-03-23 08:54:33 +00:00
|
|
|
v-tooltip.bottom="
|
|
|
|
$t('core.attachment.detail_modal.preview.click_to_exit')
|
|
|
|
"
|
2022-09-04 17:06:11 +00:00
|
|
|
:alt="attachment?.spec.displayName"
|
|
|
|
:src="attachment?.status?.permalink"
|
2023-04-24 03:20:19 +00:00
|
|
|
class="w-auto transform-gpu cursor-pointer rounded"
|
2022-09-04 17:06:11 +00:00
|
|
|
@click="onlyPreview = !onlyPreview"
|
|
|
|
/>
|
|
|
|
</div>
|
2023-04-23 02:49:32 +00:00
|
|
|
<div v-else>
|
|
|
|
<VDescription>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.preview')"
|
|
|
|
>
|
2022-11-03 07:26:18 +00:00
|
|
|
<div
|
2022-09-04 17:06:11 +00:00
|
|
|
v-if="isImage(attachment?.spec.mediaType)"
|
|
|
|
@click="onlyPreview = !onlyPreview"
|
|
|
|
>
|
2022-11-03 07:26:18 +00:00
|
|
|
<LazyImage
|
|
|
|
:alt="attachment?.spec.displayName"
|
|
|
|
:src="attachment?.status?.permalink"
|
|
|
|
classes="max-w-full cursor-pointer rounded sm:max-w-[50%]"
|
|
|
|
>
|
|
|
|
<template #loading>
|
2023-03-23 08:54:33 +00:00
|
|
|
<span class="text-gray-400">
|
|
|
|
{{ $t("core.common.status.loading") }}...
|
|
|
|
</span>
|
2022-11-03 07:26:18 +00:00
|
|
|
</template>
|
|
|
|
<template #error>
|
2023-03-23 08:54:33 +00:00
|
|
|
<span class="text-red-400">
|
|
|
|
{{ $t("core.common.status.loading_error") }}
|
|
|
|
</span>
|
2022-11-03 07:26:18 +00:00
|
|
|
</template>
|
|
|
|
</LazyImage>
|
|
|
|
</div>
|
2023-02-17 07:50:13 +00:00
|
|
|
<div v-else-if="attachment?.spec.mediaType?.startsWith('video/')">
|
|
|
|
<video
|
|
|
|
:src="attachment.status?.permalink"
|
|
|
|
controls
|
|
|
|
class="max-w-full rounded sm:max-w-[50%]"
|
|
|
|
>
|
2023-03-23 08:54:33 +00:00
|
|
|
{{
|
|
|
|
$t("core.attachment.detail_modal.preview.video_not_support")
|
|
|
|
}}
|
2023-02-17 07:50:13 +00:00
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="attachment?.spec.mediaType?.startsWith('audio/')">
|
|
|
|
<audio :src="attachment.status?.permalink" controls>
|
2023-03-23 08:54:33 +00:00
|
|
|
{{
|
|
|
|
$t("core.attachment.detail_modal.preview.audio_not_support")
|
|
|
|
}}
|
2023-02-17 07:50:13 +00:00
|
|
|
</audio>
|
|
|
|
</div>
|
2023-03-23 08:54:33 +00:00
|
|
|
<span v-else>
|
|
|
|
{{ $t("core.attachment.detail_modal.preview.not_support") }}
|
|
|
|
</span>
|
2023-04-23 02:49:32 +00:00
|
|
|
</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="
|
2023-03-23 08:54:33 +00:00
|
|
|
getGroupName(attachment?.spec.groupName) ||
|
2023-04-23 02:49:32 +00:00
|
|
|
$t('core.attachment.common.text.ungrouped')
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
<VDescriptionItem
|
|
|
|
:label="$t('core.attachment.detail_modal.fields.display_name')"
|
|
|
|
:content="attachment?.spec.displayName"
|
|
|
|
/>
|
|
|
|
<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')"
|
2022-08-12 08:15:08 +00:00
|
|
|
>
|
2023-04-26 07:32:12 +00:00
|
|
|
<AttachmentPermalinkList :attachment="attachment" />
|
2023-04-23 02:49:32 +00:00
|
|
|
</VDescriptionItem>
|
|
|
|
</VDescription>
|
|
|
|
</div>
|
2022-08-12 08:15:08 +00:00
|
|
|
</div>
|
|
|
|
<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>
|