diff --git a/package.json b/package.json index 5f9cefd0..e3459d07 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@formkit/themes": "^1.0.0-beta.12", "@formkit/utils": "^1.0.0-beta.12", "@formkit/vue": "^1.0.0-beta.12", - "@halo-dev/api-client": "^0.0.60", + "@halo-dev/api-client": "^0.0.62", "@halo-dev/components": "workspace:*", "@halo-dev/console-shared": "workspace:*", "@halo-dev/richtext-editor": "^0.0.0-alpha.17", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a81abe06..e29242df 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,7 +12,7 @@ importers: '@formkit/themes': ^1.0.0-beta.12 '@formkit/utils': ^1.0.0-beta.12 '@formkit/vue': ^1.0.0-beta.12 - '@halo-dev/api-client': ^0.0.60 + '@halo-dev/api-client': ^0.0.62 '@halo-dev/components': workspace:* '@halo-dev/console-shared': workspace:* '@halo-dev/richtext-editor': ^0.0.0-alpha.17 @@ -107,7 +107,7 @@ importers: '@formkit/themes': 1.0.0-beta.12-e579559_tailwindcss@3.2.4 '@formkit/utils': 1.0.0-beta.12-e579559 '@formkit/vue': 1.0.0-beta.12-e579559_ior6jr3fpijijuwpr34w2i25va - '@halo-dev/api-client': 0.0.60 + '@halo-dev/api-client': 0.0.62 '@halo-dev/components': link:packages/components '@halo-dev/console-shared': link:packages/shared '@halo-dev/richtext-editor': 0.0.0-alpha.17_vue@3.2.45 @@ -1968,8 +1968,8 @@ packages: - windicss dev: false - /@halo-dev/api-client/0.0.60: - resolution: {integrity: sha512-HAmJ1BDZxHj2Xp41oNOqZG/1vaR6r4EbBAUQ7ayvUY8SGJMHtJD9dyhCn7k23q6G7FmzFKFNGxajovsjBEM+yg==} + /@halo-dev/api-client/0.0.62: + resolution: {integrity: sha512-LVoAH4/+8iHxqHf7X6Ax3wy+IRSB2Tm9IC3zhfGdnbrdgyn/NnnpRIhTCKo6cK0Sr2j/3W4Pvmc0xCWNVzNAyw==} dev: false /@halo-dev/richtext-editor/0.0.0-alpha.17_vue@3.2.45: diff --git a/src/modules/interface/themes/ThemeDetail.vue b/src/modules/interface/themes/ThemeDetail.vue index c33afc91..112bc91f 100644 --- a/src/modules/interface/themes/ThemeDetail.vue +++ b/src/modules/interface/themes/ThemeDetail.vue @@ -2,6 +2,7 @@ // core libs import { inject, ref } from "vue"; import { RouterLink } from "vue-router"; +import { useThemeLifeCycle } from "./composables/use-theme"; // components import { @@ -16,15 +17,17 @@ import { import ThemeUploadModal from "./components/ThemeUploadModal.vue"; // types -import type { ComputedRef, Ref } from "vue"; +import type { Ref } from "vue"; import type { Theme } from "@halo-dev/api-client"; import { apiClient } from "@/utils/api-client"; -const selectedTheme = inject>("selectedTheme"); -const isActivated = inject>("isActivated"); +const selectedTheme = inject>("selectedTheme", ref()); const upgradeModal = ref(false); +const { isActivated, handleResetSettingConfig } = + useThemeLifeCycle(selectedTheme); + const handleReloadTheme = async () => { Dialog.warning({ title: "确定要重载主题的所有配置吗?", @@ -105,6 +108,14 @@ const onUpgradeModalClose = () => { > 重载主题配置 + + 重置 + diff --git a/src/modules/interface/themes/components/components/ThemeListItem.vue b/src/modules/interface/themes/components/components/ThemeListItem.vue index b521fa8a..333ad96f 100644 --- a/src/modules/interface/themes/components/components/ThemeListItem.vue +++ b/src/modules/interface/themes/components/components/ThemeListItem.vue @@ -36,7 +36,8 @@ const emit = defineEmits<{ const { theme } = toRefs(props); -const { isActivated, handleActiveTheme } = useThemeLifeCycle(theme); +const { isActivated, handleActiveTheme, handleResetSettingConfig } = + useThemeLifeCycle(theme); const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => { Dialog.warning({ @@ -201,6 +202,14 @@ const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => { + + 重置 + diff --git a/src/modules/interface/themes/composables/use-theme.ts b/src/modules/interface/themes/composables/use-theme.ts index ed69b68c..feab951a 100644 --- a/src/modules/interface/themes/composables/use-theme.ts +++ b/src/modules/interface/themes/composables/use-theme.ts @@ -2,7 +2,7 @@ import type { ComputedRef, Ref } from "vue"; import { computed, ref } from "vue"; import type { Theme } from "@halo-dev/api-client"; import { apiClient } from "@/utils/api-client"; -import { Dialog } from "@halo-dev/components"; +import { Dialog, Toast } from "@halo-dev/components"; import { useThemeStore } from "@/stores/theme"; import { storeToRefs } from "pinia"; @@ -10,6 +10,7 @@ interface useThemeLifeCycleReturn { loading: Ref; isActivated: ComputedRef; handleActiveTheme: () => void; + handleResetSettingConfig: () => void; } export function useThemeLifeCycle( @@ -57,10 +58,34 @@ export function useThemeLifeCycle( }); }; + const handleResetSettingConfig = async () => { + Dialog.warning({ + title: "确定要重置主题的所有配置吗?", + description: "该操作会删除已保存的配置,重置为默认配置。", + confirmType: "danger", + onConfirm: async () => { + try { + if (!theme?.value) { + return; + } + + await apiClient.theme.resetThemeConfig({ + name: theme.value.metadata.name as string, + }); + + Toast.success("重置配置成功"); + } catch (e) { + console.error("Failed to reset theme setting config", e); + } + }, + }); + }; + return { loading, isActivated, handleActiveTheme, + handleResetSettingConfig, }; } diff --git a/src/modules/interface/themes/layouts/ThemeLayout.vue b/src/modules/interface/themes/layouts/ThemeLayout.vue index b7154b67..dfd4ee05 100644 --- a/src/modules/interface/themes/layouts/ThemeLayout.vue +++ b/src/modules/interface/themes/layouts/ThemeLayout.vue @@ -1,6 +1,6 @@ + + 重置 +