fix: not remembering the selected attachment policy in upload modal (#6115)

#### What type of PR is this?

/area ui
/kind bug
/milestone 2.17.x

#### What this PR does / why we need it:

修复首次上传附件时,没有默认选择第一个存储策略的问题。

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/6094

#### Does this PR introduce a user-facing change?

```release-note
修复首次上传附件时,没有默认选择第一个存储策略的问题。
```
pull/6128/head
Ryan Wang 2024-06-23 11:48:29 +08:00 committed by GitHub
parent 373229e9de
commit ae7dcbb317
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 29 deletions

View File

@ -8,7 +8,7 @@ import {
VModal,
} from "@halo-dev/components";
import { useLocalStorage } from "@vueuse/core";
import { ref, watch } from "vue";
import { onMounted, ref } from "vue";
import { useFetchAttachmentGroup } from "../composables/use-attachment-group";
import {
useFetchAttachmentPolicy,
@ -32,35 +32,11 @@ const selectedPolicyName = useLocalStorage("attachment-upload-policy", "");
const policyEditingModal = ref(false);
const policyTemplateNameToCreate = ref();
watch(
() => groups.value,
() => {
if (selectedGroupName.value === "") return;
const group = groups.value?.find(
(group) => group.metadata.name === selectedGroupName.value
);
if (!group) {
selectedGroupName.value = groups.value?.length
? groups.value[0].metadata.name
: "";
}
onMounted(() => {
if (!selectedPolicyName.value) {
selectedPolicyName.value = policies.value?.[0].metadata.name;
}
);
watch(
() => policies.value,
() => {
const policy = policies.value?.find(
(policy) => policy.metadata.name === selectedPolicyName.value
);
if (!policy) {
selectedPolicyName.value = policies.value?.length
? policies.value[0].metadata.name
: "";
}
}
);
});
const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
policyTemplateNameToCreate.value = policyTemplate.metadata.name;