perf: optimize reset theme settings config

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/3445/head
Ryan Wang 2022-10-10 16:55:25 +08:00
parent 7d17e6e60e
commit 7980639e91
1 changed files with 30 additions and 12 deletions

View File

@ -4,7 +4,14 @@ import { inject } from "vue";
import { RouterLink } from "vue-router"; import { RouterLink } from "vue-router";
// components // components
import { VAlert, VSpace, VTag, IconMore, VButton } from "@halo-dev/components"; import {
VAlert,
VSpace,
VTag,
IconMore,
VButton,
useDialog,
} from "@halo-dev/components";
// types // types
import type { ComputedRef, Ref } from "vue"; import type { ComputedRef, Ref } from "vue";
@ -15,17 +22,28 @@ import { apiClient } from "@/utils/api-client";
const selectedTheme = inject<Ref<Theme | undefined>>("selectedTheme"); const selectedTheme = inject<Ref<Theme | undefined>>("selectedTheme");
const isActivated = inject<ComputedRef<boolean>>("isActivated"); const isActivated = inject<ComputedRef<boolean>>("isActivated");
const dialog = useDialog();
const handleReloadThemeSetting = async () => { const handleReloadThemeSetting = async () => {
dialog.warning({
title: "是否确认刷新主题的设置表单?",
description: "此操作仅会刷新主题的设置表单,不会删除已有的配置。",
onConfirm: async () => {
try {
if (!selectedTheme?.value) { if (!selectedTheme?.value) {
return; return;
} }
try {
await apiClient.theme.reloadThemeSetting({ await apiClient.theme.reloadThemeSetting({
name: selectedTheme.value.metadata.name, name: selectedTheme.value.metadata.name,
}); });
} catch (error) {
console.error("Failed to reload theme setting", error); window.location.reload();
} catch (e) {
console.error("Failed to reload theme setting", e);
} }
},
});
}; };
</script> </script>
@ -69,7 +87,7 @@ const handleReloadThemeSetting = async () => {
<VButton <VButton
v-close-popper v-close-popper
block block
type="danger" type="secondary"
@click="handleReloadThemeSetting" @click="handleReloadThemeSetting"
> >
刷新设置表单 刷新设置表单