diff --git a/src/modules/interface/themes/components/ThemeListModal.vue b/src/modules/interface/themes/components/ThemeListModal.vue index 308cde515..2dfb74db8 100644 --- a/src/modules/interface/themes/components/ThemeListModal.vue +++ b/src/modules/interface/themes/components/ThemeListModal.vue @@ -11,10 +11,12 @@ import { VEntity, VEntityField, VStatusDot, + VTabItem, + VTabs, } from "@halo-dev/components"; import LazyImage from "@/components/image/LazyImage.vue"; import ThemeInstallModal from "./ThemeInstallModal.vue"; -import { ref, watch } from "vue"; +import { computed, ref, watch } from "vue"; import type { Theme } from "@halo-dev/api-client"; import { apiClient } from "@/utils/api-client"; import { usePermission } from "@/utils/permission"; @@ -41,15 +43,22 @@ const emit = defineEmits<{ (event: "select", theme: Theme | null): void; }>(); -const themes = ref([]); +const activeTab = ref("installed"); +const themes = ref([] as Theme[]); const loading = ref(false); const themeInstall = ref(false); +const creating = ref(false); + +const modalTitle = computed(() => { + return activeTab.value === "installed" ? "已安装的主题" : "未安装的主题"; +}); const handleFetchThemes = async () => { try { loading.value = true; - const { data } = - await apiClient.extension.theme.listthemeHaloRunV1alpha1Theme(); + const { data } = await apiClient.theme.listThemes({ + uninstalled: activeTab.value !== "installed", + }); themes.value = data.items; } catch (e) { console.error("Failed to fetch themes", e); @@ -58,6 +67,13 @@ const handleFetchThemes = async () => { } }; +watch( + () => activeTab.value, + () => { + handleFetchThemes(); + } +); + const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => { Dialog.warning({ title: `${ @@ -99,6 +115,27 @@ const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => { }); }; +const handleCreateTheme = async (theme: Theme) => { + try { + creating.value = true; + + const { data } = + await apiClient.extension.theme.createthemeHaloRunV1alpha1Theme({ + theme, + }); + + // create theme settings + apiClient.theme.reloadThemeSetting({ name: data.metadata.name }); + + activeTab.value = "installed"; + } catch (error) { + console.error("Failed to create theme", error); + } finally { + creating.value = false; + handleFetchThemes(); + } +}; + const onVisibleChange = (visible: boolean) => { emit("update:visible", visible); if (!visible) { @@ -131,143 +168,261 @@ defineExpose({ :visible="visible" :width="888" height="calc(100vh - 20px)" - title="已安装的主题" + :title="modalTitle" @update:visible="onVisibleChange" > - - - + + + + -
    -
  • - - -