From 82b1f3b2eac93624ce56e2927184adef05e67a2c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 24 Oct 2022 11:16:20 +0800 Subject: [PATCH] feat: add upgrade theme support (halo-dev/console#653) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature /milestone 2.0 #### What this PR does / why we need it: 支持升级主题。适配 https://github.com/halo-dev/halo/pull/2600 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2550 #### Screenshots: image image #### Special notes for your reviewer: 测试方式: 1. Halo 需要切换到 https://github.com/halo-dev/halo/pull/2600 2. 需要 `pnpm install` 3. 测试更主题功能是否正常。 #### Does this PR introduce a user-facing change? ```release-note 支持升级主题。 ``` --- src/modules/interface/themes/ThemeDetail.vue | 25 ++++++++++++++++-- .../themes/components/ThemeListModal.vue | 5 ++-- ...eInstallModal.vue => ThemeUploadModal.vue} | 26 ++++++++++++++++--- 3 files changed, 49 insertions(+), 7 deletions(-) rename src/modules/interface/themes/components/{ThemeInstallModal.vue => ThemeUploadModal.vue} (63%) diff --git a/src/modules/interface/themes/ThemeDetail.vue b/src/modules/interface/themes/ThemeDetail.vue index 1cffcb833..6cc916814 100644 --- a/src/modules/interface/themes/ThemeDetail.vue +++ b/src/modules/interface/themes/ThemeDetail.vue @@ -1,6 +1,6 @@ diff --git a/src/modules/interface/themes/components/ThemeListModal.vue b/src/modules/interface/themes/components/ThemeListModal.vue index 2dfb74db8..e9452c37a 100644 --- a/src/modules/interface/themes/components/ThemeListModal.vue +++ b/src/modules/interface/themes/components/ThemeListModal.vue @@ -15,7 +15,7 @@ import { VTabs, } from "@halo-dev/components"; import LazyImage from "@/components/image/LazyImage.vue"; -import ThemeInstallModal from "./ThemeInstallModal.vue"; +import ThemeUploadModal from "./ThemeUploadModal.vue"; import { computed, ref, watch } from "vue"; import type { Theme } from "@halo-dev/api-client"; import { apiClient } from "@/utils/api-client"; @@ -437,7 +437,8 @@ defineExpose({ - diff --git a/src/modules/interface/themes/components/ThemeInstallModal.vue b/src/modules/interface/themes/components/ThemeUploadModal.vue similarity index 63% rename from src/modules/interface/themes/components/ThemeInstallModal.vue rename to src/modules/interface/themes/components/ThemeUploadModal.vue index 18b9dbd7e..2b1dd48cd 100644 --- a/src/modules/interface/themes/components/ThemeInstallModal.vue +++ b/src/modules/interface/themes/components/ThemeUploadModal.vue @@ -2,14 +2,17 @@ import { VModal } from "@halo-dev/components"; import FilePondUpload from "@/components/upload/FilePondUpload.vue"; import { apiClient } from "@/utils/api-client"; -import { computed, ref } from "vue"; +import { computed, mergeProps, ref } from "vue"; +import type { Theme } from "@halo-dev/api-client"; -withDefaults( +const props = withDefaults( defineProps<{ visible: boolean; + upgradeTheme?: Theme; }>(), { visible: false, + upgradeTheme: undefined, } ); @@ -20,6 +23,12 @@ const emit = defineEmits<{ const FilePondUploadRef = ref(); +const modalTitle = computed(() => { + return props.upgradeTheme + ? `升级主题(${props.upgradeTheme.spec.displayName})` + : "安装主题"; +}); + const handleVisibleChange = (visible: boolean) => { emit("update:visible", visible); if (!visible) { @@ -29,6 +38,16 @@ const handleVisibleChange = (visible: boolean) => { }; const uploadHandler = computed(() => { + if (props.upgradeTheme) { + return (file, config) => + apiClient.theme.upgradeTheme( + { + name: props.upgradeTheme.metadata.name as string, + file: file, + }, + config + ); + } return (file, config) => apiClient.theme.installTheme( { @@ -42,10 +61,11 @@ const uploadHandler = computed(() => {