2022-08-04 01:44:13 +00:00
|
|
|
<script lang="ts" setup>
|
2022-08-04 03:15:42 +00:00
|
|
|
// core libs
|
2024-05-23 03:00:49 +00:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
nextTick,
|
|
|
|
onMounted,
|
|
|
|
provide,
|
|
|
|
type Ref,
|
|
|
|
ref,
|
|
|
|
watch,
|
|
|
|
} from "vue";
|
2022-08-04 03:15:42 +00:00
|
|
|
import { useRoute, useRouter } from "vue-router";
|
|
|
|
|
|
|
|
// libs
|
2023-12-28 09:13:38 +00:00
|
|
|
import { cloneDeep } from "lodash-es";
|
2022-08-04 03:15:42 +00:00
|
|
|
|
|
|
|
// hooks
|
|
|
|
import { useThemeLifeCycle } from "../composables/use-theme";
|
2022-08-22 08:49:07 +00:00
|
|
|
// types
|
2023-11-09 06:56:06 +00:00
|
|
|
import BasicLayout from "@console/layouts/BasicLayout.vue";
|
2022-08-04 03:15:42 +00:00
|
|
|
|
|
|
|
// components
|
2022-08-04 01:44:13 +00:00
|
|
|
import {
|
2024-05-23 03:00:49 +00:00
|
|
|
Dialog,
|
2022-08-04 01:44:13 +00:00
|
|
|
IconExchange,
|
|
|
|
IconEye,
|
2024-05-23 03:00:49 +00:00
|
|
|
IconListSettings,
|
2022-08-04 01:44:13 +00:00
|
|
|
IconPalette,
|
|
|
|
VButton,
|
|
|
|
VCard,
|
2022-08-22 08:49:07 +00:00
|
|
|
VEmpty,
|
2024-05-23 03:00:49 +00:00
|
|
|
VLoading,
|
2022-08-04 01:44:13 +00:00
|
|
|
VPageHeader,
|
|
|
|
VSpace,
|
|
|
|
VTabbar,
|
|
|
|
} from "@halo-dev/components";
|
|
|
|
import ThemeListModal from "../components/ThemeListModal.vue";
|
2022-11-07 07:12:15 +00:00
|
|
|
import ThemePreviewModal from "../components/preview/ThemePreviewModal.vue";
|
2023-01-30 06:36:10 +00:00
|
|
|
import type { Setting, SettingForm, Theme } from "@halo-dev/api-client";
|
2022-10-10 07:29:05 +00:00
|
|
|
import { usePermission } from "@/utils/permission";
|
2023-11-09 06:56:06 +00:00
|
|
|
import { useThemeStore } from "@console/stores/theme";
|
2022-11-02 06:40:16 +00:00
|
|
|
import { storeToRefs } from "pinia";
|
2023-01-30 06:36:10 +00:00
|
|
|
import { apiClient } from "@/utils/api-client";
|
2023-03-23 08:54:33 +00:00
|
|
|
import { useI18n } from "vue-i18n";
|
2023-03-29 13:26:13 +00:00
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
2023-05-19 02:10:24 +00:00
|
|
|
import { useRouteQuery } from "@vueuse/router";
|
2022-10-10 07:29:05 +00:00
|
|
|
|
|
|
|
const { currentUserHasPermission } = usePermission();
|
2023-03-23 08:54:33 +00:00
|
|
|
const { t } = useI18n();
|
2023-03-29 13:26:13 +00:00
|
|
|
const route = useRoute();
|
|
|
|
const router = useRouter();
|
2022-08-04 01:44:13 +00:00
|
|
|
|
|
|
|
interface ThemeTab {
|
|
|
|
id: string;
|
|
|
|
label: string;
|
2022-08-04 03:15:42 +00:00
|
|
|
route: {
|
|
|
|
name: string;
|
|
|
|
params?: Record<string, string>;
|
|
|
|
};
|
2022-08-04 01:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const initialTabs: ThemeTab[] = [
|
|
|
|
{
|
|
|
|
id: "detail",
|
2023-03-23 08:54:33 +00:00
|
|
|
label: t("core.theme.tabs.detail"),
|
2022-08-04 01:44:13 +00:00
|
|
|
route: {
|
|
|
|
name: "ThemeDetail",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const tabs = ref<ThemeTab[]>(cloneDeep(initialTabs));
|
2022-11-07 07:12:15 +00:00
|
|
|
const selectedTheme = ref<Theme>();
|
2022-08-04 01:44:13 +00:00
|
|
|
const themesModal = ref(false);
|
2022-11-07 07:12:15 +00:00
|
|
|
const previewModal = ref(false);
|
2023-03-29 13:26:13 +00:00
|
|
|
const activeTab = ref(tabs.value[0].id);
|
2023-07-19 03:26:13 +00:00
|
|
|
provide<Ref<string>>("activeTab", activeTab);
|
2023-08-30 04:54:15 +00:00
|
|
|
provide<Ref<boolean>>("themesModal", themesModal);
|
2022-08-04 01:44:13 +00:00
|
|
|
|
2022-11-02 06:40:16 +00:00
|
|
|
const { loading, isActivated, handleActiveTheme } =
|
2022-08-04 01:44:13 +00:00
|
|
|
useThemeLifeCycle(selectedTheme);
|
|
|
|
|
2022-09-10 15:11:15 +00:00
|
|
|
provide<Ref<Theme | undefined>>("selectedTheme", selectedTheme);
|
2022-08-04 01:44:13 +00:00
|
|
|
|
2023-03-29 13:26:13 +00:00
|
|
|
const { data: setting } = useQuery<Setting>({
|
|
|
|
queryKey: ["theme-setting", selectedTheme],
|
|
|
|
queryFn: async () => {
|
|
|
|
const { data } = await apiClient.theme.fetchThemeSetting({
|
|
|
|
name: selectedTheme.value?.metadata.name as string,
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
enabled: computed(() => {
|
|
|
|
return (
|
|
|
|
!!selectedTheme.value &&
|
|
|
|
!!selectedTheme.value.spec.settingName &&
|
|
|
|
currentUserHasPermission(["system:themes:view"])
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
async onSuccess(data) {
|
|
|
|
if (data) {
|
|
|
|
const { forms } = data.spec;
|
|
|
|
tabs.value = [
|
2023-04-10 07:10:22 +00:00
|
|
|
...initialTabs,
|
2023-03-29 13:26:13 +00:00
|
|
|
...forms.map((item: SettingForm) => {
|
|
|
|
return {
|
|
|
|
id: item.group,
|
|
|
|
label: item.label || "",
|
|
|
|
route: {
|
|
|
|
name: "ThemeSetting",
|
|
|
|
params: {
|
|
|
|
group: item.group,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
] as ThemeTab[];
|
|
|
|
}
|
2023-01-30 06:36:10 +00:00
|
|
|
|
2023-03-29 13:26:13 +00:00
|
|
|
await nextTick();
|
2023-01-30 06:36:10 +00:00
|
|
|
|
2023-03-29 13:26:13 +00:00
|
|
|
handleTriggerTabChange();
|
|
|
|
},
|
|
|
|
});
|
2023-01-30 06:36:10 +00:00
|
|
|
|
2023-03-29 13:26:13 +00:00
|
|
|
provide<Ref<Setting | undefined>>("setting", setting);
|
2023-01-30 06:36:10 +00:00
|
|
|
|
2024-05-22 12:42:47 +00:00
|
|
|
const handleTabChange = (id: string | number) => {
|
2022-08-04 01:44:13 +00:00
|
|
|
const tab = tabs.value.find((item) => item.id === id);
|
|
|
|
if (tab) {
|
2022-09-10 15:11:15 +00:00
|
|
|
activeTab.value = tab.id;
|
2022-08-04 01:44:13 +00:00
|
|
|
router.push(tab.route);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-10 15:11:15 +00:00
|
|
|
const handleTriggerTabChange = () => {
|
|
|
|
if (route.name === "ThemeSetting") {
|
2022-08-04 01:44:13 +00:00
|
|
|
const tab = tabs.value.find((tab) => {
|
|
|
|
return (
|
2022-09-10 15:11:15 +00:00
|
|
|
tab.route.name === route.name &&
|
2022-08-04 03:15:42 +00:00
|
|
|
tab.route.params?.group === route.params.group
|
2022-08-04 01:44:13 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
if (tab) {
|
|
|
|
activeTab.value = tab.id;
|
|
|
|
return;
|
|
|
|
}
|
2022-09-10 15:11:15 +00:00
|
|
|
handleTabChange(tabs.value[0].id);
|
2022-08-04 01:44:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tab = tabs.value.find((tab) => tab.route.name === route.name);
|
|
|
|
activeTab.value = tab ? tab.id : tabs.value[0].id;
|
|
|
|
};
|
|
|
|
|
2023-03-29 13:26:13 +00:00
|
|
|
const onSelectTheme = () => {
|
|
|
|
tabs.value = cloneDeep(initialTabs);
|
|
|
|
handleTabChange(tabs.value[0].id);
|
|
|
|
};
|
2022-11-02 06:40:16 +00:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
const themeStore = useThemeStore();
|
|
|
|
|
|
|
|
const { activatedTheme } = storeToRefs(themeStore);
|
|
|
|
|
|
|
|
selectedTheme.value = activatedTheme?.value;
|
|
|
|
});
|
2023-03-29 13:26:13 +00:00
|
|
|
|
|
|
|
watch([() => route.name, () => route.params], async () => {
|
|
|
|
handleTriggerTabChange();
|
|
|
|
});
|
2023-05-19 02:10:24 +00:00
|
|
|
|
|
|
|
// handle remote download url from route
|
|
|
|
const remoteDownloadUrl = useRouteQuery<string | null>("remote-download-url");
|
|
|
|
onMounted(() => {
|
|
|
|
if (remoteDownloadUrl.value) {
|
|
|
|
Dialog.warning({
|
|
|
|
title: t("core.theme.operations.remote_download.title"),
|
|
|
|
description: t("core.theme.operations.remote_download.description", {
|
|
|
|
url: remoteDownloadUrl.value,
|
|
|
|
}),
|
|
|
|
confirmText: t("core.common.buttons.download"),
|
|
|
|
cancelText: t("core.common.buttons.cancel"),
|
|
|
|
onConfirm() {
|
|
|
|
themesModal.value = true;
|
|
|
|
},
|
|
|
|
onCancel() {
|
|
|
|
remoteDownloadUrl.value = null;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-08-04 01:44:13 +00:00
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<BasicLayout>
|
2022-09-10 15:11:15 +00:00
|
|
|
<VPageHeader :title="selectedTheme?.spec.displayName">
|
2022-08-04 01:44:13 +00:00
|
|
|
<template #icon>
|
|
|
|
<IconPalette class="mr-2 self-center" />
|
|
|
|
</template>
|
|
|
|
<template #actions>
|
|
|
|
<VSpace>
|
|
|
|
<VButton
|
2023-05-15 06:43:55 +00:00
|
|
|
v-show="!isActivated"
|
2022-09-30 09:48:19 +00:00
|
|
|
v-permission="['system:themes:manage']"
|
2022-08-04 01:44:13 +00:00
|
|
|
size="sm"
|
|
|
|
type="primary"
|
2023-04-19 02:23:00 +00:00
|
|
|
@click="handleActiveTheme()"
|
2022-08-04 01:44:13 +00:00
|
|
|
>
|
2023-08-25 16:00:13 +00:00
|
|
|
{{ $t("core.common.buttons.activate") }}
|
2022-08-04 01:44:13 +00:00
|
|
|
</VButton>
|
2023-08-30 04:54:15 +00:00
|
|
|
<VButton type="default" size="sm" @click="previewModal = true">
|
2022-08-04 01:44:13 +00:00
|
|
|
<template #icon>
|
|
|
|
<IconEye class="h-full w-full" />
|
|
|
|
</template>
|
2023-03-23 08:54:33 +00:00
|
|
|
{{ $t("core.common.buttons.preview") }}
|
2022-08-04 01:44:13 +00:00
|
|
|
</VButton>
|
2023-08-30 04:54:15 +00:00
|
|
|
<VButton type="secondary" @click="themesModal = true">
|
2022-12-16 02:46:11 +00:00
|
|
|
<template #icon>
|
2023-08-30 04:54:15 +00:00
|
|
|
<IconListSettings class="h-full w-full" />
|
2022-12-16 02:46:11 +00:00
|
|
|
</template>
|
2023-03-23 08:54:33 +00:00
|
|
|
{{ $t("core.theme.actions.management") }}
|
2022-12-16 02:46:11 +00:00
|
|
|
</VButton>
|
2022-08-04 01:44:13 +00:00
|
|
|
</VSpace>
|
|
|
|
</template>
|
|
|
|
</VPageHeader>
|
|
|
|
|
|
|
|
<div class="m-0 md:m-4">
|
2022-08-22 08:49:07 +00:00
|
|
|
<VEmpty
|
2022-09-10 15:11:15 +00:00
|
|
|
v-if="!selectedTheme && !loading"
|
2023-03-23 08:54:33 +00:00
|
|
|
:message="$t('core.theme.empty.message')"
|
|
|
|
:title="$t('core.theme.empty.title')"
|
2022-08-22 08:49:07 +00:00
|
|
|
>
|
|
|
|
<template #actions>
|
|
|
|
<VSpace>
|
2023-03-23 08:54:33 +00:00
|
|
|
<VButton @click="themesModal = true">
|
|
|
|
{{ $t("core.theme.common.buttons.install") }}
|
|
|
|
</VButton>
|
2022-08-22 08:49:07 +00:00
|
|
|
<VButton type="primary" @click="themesModal = true">
|
|
|
|
<template #icon>
|
|
|
|
<IconExchange class="h-full w-full" />
|
|
|
|
</template>
|
2023-03-23 08:54:33 +00:00
|
|
|
{{ $t("core.theme.empty.actions.switch") }}
|
2022-08-22 08:49:07 +00:00
|
|
|
</VButton>
|
|
|
|
</VSpace>
|
2022-08-04 01:44:13 +00:00
|
|
|
</template>
|
2022-08-22 08:49:07 +00:00
|
|
|
</VEmpty>
|
|
|
|
|
|
|
|
<div v-else>
|
2023-11-27 09:04:08 +00:00
|
|
|
<VCard :body-class="['!p-0', '!overflow-visible']">
|
2022-08-22 08:49:07 +00:00
|
|
|
<template #header>
|
|
|
|
<VTabbar
|
|
|
|
v-model:active-id="activeTab"
|
2023-06-26 03:54:17 +00:00
|
|
|
:items="tabs.map((item) => ({ id: item.id, label: item.label }))"
|
2022-08-22 08:49:07 +00:00
|
|
|
class="w-full !rounded-none"
|
|
|
|
type="outline"
|
|
|
|
@change="handleTabChange"
|
|
|
|
></VTabbar>
|
|
|
|
</template>
|
2023-11-27 09:04:08 +00:00
|
|
|
<div class="rounded-b-base bg-white">
|
2023-03-29 13:26:13 +00:00
|
|
|
<RouterView
|
|
|
|
:key="`${selectedTheme?.metadata.name}-${activeTab}`"
|
|
|
|
v-slot="{ Component }"
|
|
|
|
>
|
2023-02-08 06:24:13 +00:00
|
|
|
<template v-if="Component">
|
|
|
|
<Suspense>
|
|
|
|
<component :is="Component"></component>
|
|
|
|
<template #fallback>
|
|
|
|
<VLoading />
|
|
|
|
</template>
|
|
|
|
</Suspense>
|
|
|
|
</template>
|
|
|
|
</RouterView>
|
|
|
|
</div>
|
2022-08-22 08:49:07 +00:00
|
|
|
</VCard>
|
2022-08-04 01:44:13 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-07 07:12:15 +00:00
|
|
|
|
2024-05-23 03:00:49 +00:00
|
|
|
<ThemeListModal
|
|
|
|
v-if="themesModal"
|
|
|
|
@close="themesModal = false"
|
|
|
|
@select="onSelectTheme"
|
|
|
|
/>
|
2024-03-19 06:58:22 +00:00
|
|
|
<ThemePreviewModal
|
|
|
|
v-if="previewModal"
|
|
|
|
:theme="selectedTheme"
|
|
|
|
@close="previewModal = false"
|
|
|
|
/>
|
2022-08-04 01:44:13 +00:00
|
|
|
</BasicLayout>
|
|
|
|
</template>
|