2023-11-13 08:56:08 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { apiClient } from "@/utils/api-client";
|
|
|
|
import {
|
|
|
|
VButton,
|
|
|
|
VDropdown,
|
|
|
|
VDropdownItem,
|
2024-04-25 00:33:09 +00:00
|
|
|
VTabbar,
|
2023-11-13 08:56:08 +00:00
|
|
|
} from "@halo-dev/components";
|
2024-04-25 00:33:09 +00:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
markRaw,
|
|
|
|
onMounted,
|
|
|
|
provide,
|
|
|
|
type Ref,
|
|
|
|
ref,
|
|
|
|
toRaw,
|
|
|
|
} from "vue";
|
2023-11-13 08:56:08 +00:00
|
|
|
import type { DetailedUser } from "@halo-dev/api-client";
|
|
|
|
import ProfileEditingModal from "./components/ProfileEditingModal.vue";
|
|
|
|
import PasswordChangeModal from "./components/PasswordChangeModal.vue";
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import UserAvatar from "@/components/user-avatar/UserAvatar.vue";
|
|
|
|
import DetailTab from "./tabs/Detail.vue";
|
|
|
|
import PersonalAccessTokensTab from "./tabs/PersonalAccessTokens.vue";
|
|
|
|
import { useRouteQuery } from "@vueuse/router";
|
|
|
|
import NotificationPreferences from "./tabs/NotificationPreferences.vue";
|
2024-01-15 07:21:27 +00:00
|
|
|
import TwoFactor from "./tabs/TwoFactor.vue";
|
2024-04-25 00:33:09 +00:00
|
|
|
import type { PluginModule, UserProfileTab } from "@halo-dev/console-shared";
|
|
|
|
import { usePluginModuleStore } from "@/stores/plugin";
|
2023-11-13 08:56:08 +00:00
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
|
|
|
const editingModal = ref(false);
|
|
|
|
const passwordChangeModal = ref(false);
|
|
|
|
|
|
|
|
const {
|
|
|
|
data: user,
|
|
|
|
isLoading,
|
|
|
|
refetch,
|
|
|
|
} = useQuery({
|
|
|
|
queryKey: ["user-detail"],
|
|
|
|
queryFn: async () => {
|
|
|
|
const { data } = await apiClient.user.getCurrentUserDetail();
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
provide<Ref<DetailedUser | undefined>>("user", user);
|
|
|
|
|
2024-04-25 00:33:09 +00:00
|
|
|
const tabs = ref<UserProfileTab[]>([
|
2023-11-13 08:56:08 +00:00
|
|
|
{
|
|
|
|
id: "detail",
|
2023-11-30 10:56:10 +00:00
|
|
|
label: t("core.uc_profile.tabs.detail"),
|
2023-11-13 08:56:08 +00:00
|
|
|
component: markRaw(DetailTab),
|
|
|
|
priority: 10,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "notification-preferences",
|
2023-11-30 10:56:10 +00:00
|
|
|
label: t("core.uc_profile.tabs.notification-preferences"),
|
2023-11-13 08:56:08 +00:00
|
|
|
component: markRaw(NotificationPreferences),
|
|
|
|
priority: 20,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "pat",
|
2023-11-30 10:56:10 +00:00
|
|
|
label: t("core.uc_profile.tabs.pat"),
|
2023-11-13 08:56:08 +00:00
|
|
|
component: markRaw(PersonalAccessTokensTab),
|
|
|
|
priority: 30,
|
|
|
|
},
|
2024-01-15 07:21:27 +00:00
|
|
|
{
|
|
|
|
id: "2fa",
|
|
|
|
label: "两步验证",
|
|
|
|
component: markRaw(TwoFactor),
|
|
|
|
priority: 40,
|
|
|
|
},
|
2024-04-25 00:33:09 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Collect uc:profile:tabs:create extension points
|
|
|
|
onMounted(() => {
|
|
|
|
const { pluginModules } = usePluginModuleStore();
|
|
|
|
|
|
|
|
pluginModules.forEach((pluginModule: PluginModule) => {
|
|
|
|
const { extensionPoints } = pluginModule;
|
|
|
|
if (!extensionPoints?.["uc:user:profile:tabs:create"]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const providers = extensionPoints[
|
|
|
|
"uc:user:profile:tabs:create"
|
|
|
|
]() as UserProfileTab[];
|
|
|
|
|
|
|
|
tabs.value.push(...providers);
|
|
|
|
});
|
|
|
|
});
|
2023-11-13 08:56:08 +00:00
|
|
|
|
|
|
|
const tabbarItems = computed(() => {
|
2024-04-25 00:33:09 +00:00
|
|
|
return toRaw(tabs)
|
|
|
|
.value.sort((a, b) => a.priority - b.priority)
|
|
|
|
.map((tab) => ({
|
|
|
|
id: tab.id,
|
|
|
|
label: tab.label,
|
|
|
|
}));
|
2023-11-13 08:56:08 +00:00
|
|
|
});
|
|
|
|
|
2024-04-25 00:33:09 +00:00
|
|
|
const activeTab = useRouteQuery<string>("tab", tabs.value[0].id, {
|
2023-11-13 08:56:08 +00:00
|
|
|
mode: "push",
|
|
|
|
});
|
2024-05-23 06:32:49 +00:00
|
|
|
|
|
|
|
function onPasswordChangeModalClose() {
|
|
|
|
passwordChangeModal.value = false;
|
|
|
|
refetch();
|
|
|
|
}
|
2023-11-13 08:56:08 +00:00
|
|
|
</script>
|
|
|
|
<template>
|
2024-05-23 06:32:49 +00:00
|
|
|
<ProfileEditingModal v-if="editingModal" @close="editingModal = false" />
|
2023-11-13 08:56:08 +00:00
|
|
|
|
|
|
|
<PasswordChangeModal
|
2024-05-23 06:32:49 +00:00
|
|
|
v-if="passwordChangeModal"
|
2023-11-13 08:56:08 +00:00
|
|
|
:user="user?.user"
|
2024-05-23 06:32:49 +00:00
|
|
|
@close="onPasswordChangeModalClose"
|
2023-11-13 08:56:08 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<header class="bg-white">
|
|
|
|
<div class="p-4">
|
|
|
|
<div class="flex items-center justify-between">
|
|
|
|
<div class="flex flex-row items-center gap-5">
|
|
|
|
<div class="group relative h-20 w-20">
|
2024-01-29 08:06:02 +00:00
|
|
|
<UserAvatar :name="user?.user.metadata.name" is-current-user />
|
2023-11-13 08:56:08 +00:00
|
|
|
</div>
|
|
|
|
<div class="block">
|
|
|
|
<h1 class="truncate text-lg font-bold text-gray-900">
|
|
|
|
{{ user?.user.spec.displayName }}
|
|
|
|
</h1>
|
|
|
|
<span v-if="!isLoading" class="text-sm text-gray-600">
|
|
|
|
@{{ user?.user.metadata.name }}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<VDropdown>
|
|
|
|
<VButton type="default">
|
|
|
|
{{ $t("core.common.buttons.edit") }}
|
|
|
|
</VButton>
|
|
|
|
<template #popper>
|
|
|
|
<VDropdownItem @click="editingModal = true">
|
2023-11-30 10:56:10 +00:00
|
|
|
{{ $t("core.uc_profile.actions.update_profile.title") }}
|
2023-11-13 08:56:08 +00:00
|
|
|
</VDropdownItem>
|
|
|
|
<VDropdownItem @click="passwordChangeModal = true">
|
2023-11-30 10:56:10 +00:00
|
|
|
{{ $t("core.uc_profile.actions.change_password.title") }}
|
2023-11-13 08:56:08 +00:00
|
|
|
</VDropdownItem>
|
|
|
|
</template>
|
|
|
|
</VDropdown>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<section class="bg-white p-4">
|
|
|
|
<VTabbar
|
|
|
|
v-model:active-id="activeTab"
|
|
|
|
:items="tabbarItems"
|
|
|
|
class="w-full"
|
|
|
|
type="outline"
|
|
|
|
></VTabbar>
|
|
|
|
<div class="mt-2">
|
|
|
|
<template v-for="tab in tabs" :key="tab.id">
|
|
|
|
<component
|
|
|
|
:is="tab.component"
|
2024-04-25 00:33:09 +00:00
|
|
|
v-if="activeTab === tab.id"
|
|
|
|
:user="user"
|
2023-11-13 08:56:08 +00:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|