2023-07-12 06:19:15 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
// core libs
|
2024-06-26 10:42:50 +00:00
|
|
|
import { provide, ref, type Ref } from "vue";
|
2023-07-12 06:19:15 +00:00
|
|
|
|
|
|
|
// components
|
2024-06-26 10:42:50 +00:00
|
|
|
import { usePermission } from "@/utils/permission";
|
|
|
|
import type { Setting, SettingForm } from "@halo-dev/api-client";
|
|
|
|
import { coreApiClient } from "@halo-dev/api-client";
|
2023-07-12 06:19:15 +00:00
|
|
|
import {
|
2024-06-26 10:42:50 +00:00
|
|
|
IconSettings,
|
2023-07-12 06:19:15 +00:00
|
|
|
VCard,
|
|
|
|
VPageHeader,
|
|
|
|
VTabbar,
|
|
|
|
} from "@halo-dev/components";
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
|
|
import { useRouteQuery } from "@vueuse/router";
|
2024-06-26 10:42:50 +00:00
|
|
|
import type { Component, Raw } from "vue";
|
|
|
|
import { markRaw } from "vue";
|
|
|
|
import { useI18n } from "vue-i18n";
|
2023-09-28 13:36:18 +00:00
|
|
|
import NotificationsTab from "./tabs/Notifications.vue";
|
2024-06-26 10:42:50 +00:00
|
|
|
import SettingTab from "./tabs/Setting.vue";
|
2023-07-12 06:19:15 +00:00
|
|
|
|
|
|
|
const { t } = useI18n();
|
2023-12-01 02:14:09 +00:00
|
|
|
const { currentUserHasPermission } = usePermission();
|
2023-07-12 06:19:15 +00:00
|
|
|
|
|
|
|
interface Tab {
|
|
|
|
id: string;
|
|
|
|
label: string;
|
|
|
|
component: Raw<Component>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tabs = ref<Tab[]>([
|
|
|
|
{
|
|
|
|
id: "loading",
|
|
|
|
label: t("core.common.status.loading"),
|
|
|
|
component: markRaw(SettingTab),
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2023-07-16 15:34:17 +00:00
|
|
|
const activeTab = useRouteQuery<string>("tab", "basic");
|
|
|
|
provide<Ref<string>>("activeTab", activeTab);
|
2023-07-12 06:19:15 +00:00
|
|
|
|
|
|
|
const { data: setting } = useQuery({
|
|
|
|
queryKey: ["system-setting"],
|
|
|
|
queryFn: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } = await coreApiClient.setting.getSetting({
|
2023-07-12 06:19:15 +00:00
|
|
|
name: "system",
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
async onSuccess(data) {
|
|
|
|
if (data) {
|
|
|
|
const { forms } = data.spec;
|
|
|
|
tabs.value = forms.map((item: SettingForm) => {
|
|
|
|
return {
|
|
|
|
id: item.group,
|
|
|
|
label: item.label || "",
|
|
|
|
component: markRaw(SettingTab),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!activeTab.value) {
|
|
|
|
activeTab.value = tabs.value[0].id;
|
|
|
|
}
|
2023-09-28 13:36:18 +00:00
|
|
|
|
|
|
|
// TODO: use integrations center to refactor this
|
2023-12-01 02:14:09 +00:00
|
|
|
if (currentUserHasPermission(["system:notifier:configuration"])) {
|
|
|
|
tabs.value.push({
|
|
|
|
id: "notification",
|
|
|
|
label: "通知设置",
|
|
|
|
component: markRaw(NotificationsTab),
|
|
|
|
});
|
|
|
|
}
|
2023-07-12 06:19:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
provide<Ref<Setting | undefined>>("setting", setting);
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<VPageHeader :title="$t('core.setting.title')">
|
|
|
|
<template #icon>
|
|
|
|
<IconSettings class="mr-2 self-center" />
|
|
|
|
</template>
|
|
|
|
</VPageHeader>
|
|
|
|
|
|
|
|
<div class="m-0 md:m-4">
|
2023-11-27 09:38:08 +00:00
|
|
|
<VCard :body-class="['!p-0', '!overflow-visible']">
|
2023-07-12 06:19:15 +00:00
|
|
|
<template #header>
|
|
|
|
<VTabbar
|
|
|
|
v-model:active-id="activeTab"
|
|
|
|
:items="tabs.map((item) => ({ id: item.id, label: item.label }))"
|
|
|
|
class="w-full !rounded-none"
|
|
|
|
type="outline"
|
|
|
|
></VTabbar>
|
|
|
|
</template>
|
2023-11-27 09:38:08 +00:00
|
|
|
<div class="rounded-b-base bg-white">
|
2023-07-12 06:19:15 +00:00
|
|
|
<template v-for="tab in tabs" :key="tab.id">
|
|
|
|
<component :is="tab.component" v-if="activeTab === tab.id" />
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</VCard>
|
|
|
|
</div>
|
|
|
|
</template>
|