From 0a7cbd30181e21c256c8db027b31d8f73a193d37 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 19 Dec 2022 16:25:47 +0800 Subject: [PATCH] feat: add support for resetting configmap of plugin and theme (#777) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature #### What this PR does / why we need it: 支持重置主题和插件的设置选项。适配 https://github.com/halo-dev/halo/pull/2964 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2789 #### Screenshots: image #### Special notes for your reviewer: 测试方式: 1. 安装若干带有设置选项主题和插件。 2. 进入主题和插件设置,改变部分设置并保存。 3. 重置主题和插件的设置,然后进入设置表单,检查是否已经恢复为了默认。 #### Does this PR introduce a user-facing change? ```release-note 支持重置主题和插件的设置选项。 ``` --- package.json | 2 +- pnpm-lock.yaml | 8 ++--- src/modules/interface/themes/ThemeDetail.vue | 17 ++++++++-- .../components/components/ThemeListItem.vue | 11 +++++- .../interface/themes/composables/use-theme.ts | 27 ++++++++++++++- .../interface/themes/layouts/ThemeLayout.vue | 3 +- .../plugins/components/PluginListItem.vue | 34 +++++++++++++++++++ 7 files changed, 90 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 5f9cefd0a..e3459d07a 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 a81abe060..e29242dfc 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 c33afc911..112bc91f2 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 b521fa8a1..333ad96fb 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 ed69b68cc..feab951a4 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 b7154b678..dfd4ee05c 100644 --- a/src/modules/interface/themes/layouts/ThemeLayout.vue +++ b/src/modules/interface/themes/layouts/ThemeLayout.vue @@ -1,6 +1,6 @@ + + 重置 +