mirror of https://github.com/halo-dev/halo-admin
feat: get the currently logged-in user information
Signed-off-by: Ryan Wang <i@ryanc.cc>pull/588/head
parent
1d09bc5af3
commit
ace341efef
|
@ -9,6 +9,7 @@ import {
|
||||||
VTag,
|
VTag,
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import type { MenuGroupType, MenuItemType } from "@/types/menus";
|
import type { MenuGroupType, MenuItemType } from "@/types/menus";
|
||||||
|
import type { User } from "../../../../src/types/extension";
|
||||||
import logo from "@/assets/logo.svg";
|
import logo from "@/assets/logo.svg";
|
||||||
import { RouterView, useRoute, useRouter } from "vue-router";
|
import { RouterView, useRoute, useRouter } from "vue-router";
|
||||||
import { inject, ref } from "vue";
|
import { inject, ref } from "vue";
|
||||||
|
@ -22,8 +23,10 @@ const moreMenuVisible = ref(false);
|
||||||
const moreMenuRootVisible = ref(false);
|
const moreMenuRootVisible = ref(false);
|
||||||
const spotlight = ref(false);
|
const spotlight = ref(false);
|
||||||
|
|
||||||
|
const currentUser = inject<User>("currentUser");
|
||||||
|
|
||||||
const handleRouteToProfile = () => {
|
const handleRouteToProfile = () => {
|
||||||
router.push({ path: "/users/profile/detail" });
|
router.push({ path: `/users/${currentUser?.metadata.name}/detail` });
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -47,11 +50,13 @@ const handleRouteToProfile = () => {
|
||||||
</div>
|
</div>
|
||||||
<VRoutesMenu :menus="menus" />
|
<VRoutesMenu :menus="menus" />
|
||||||
<div class="current-profile">
|
<div class="current-profile">
|
||||||
<div class="profile-avatar">
|
<div v-if="currentUser.spec.avatar" class="profile-avatar">
|
||||||
<img class="h-11 w-11 rounded-full" src="https://ryanc.cc/avatar" />
|
<img :src="currentUser.spec.avatar" class="h-11 w-11 rounded-full" />
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-name">
|
<div class="profile-name">
|
||||||
<div class="flex text-sm font-medium">Ryan Wang</div>
|
<div class="flex text-sm font-medium">
|
||||||
|
{{ currentUser.spec.displayName }}
|
||||||
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<VTag>
|
<VTag>
|
||||||
<template #leftIcon>
|
<template #leftIcon>
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { setupComponents } from "./setup/setupComponents";
|
||||||
import { coreModules } from "./modules";
|
import { coreModules } from "./modules";
|
||||||
import { useScriptTag } from "@vueuse/core";
|
import { useScriptTag } from "@vueuse/core";
|
||||||
import { usePluginStore } from "@/stores/plugin";
|
import { usePluginStore } from "@/stores/plugin";
|
||||||
|
import type { User } from "@/types/extension";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
|
@ -130,6 +131,11 @@ async function loadPluginModules() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadCurrentUser() {
|
||||||
|
const response = await axiosInstance.get(`/custom-api/v1alpha1/users/me`);
|
||||||
|
app.provide<User>("currentUser", response.data);
|
||||||
|
}
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
await initApp();
|
await initApp();
|
||||||
})();
|
})();
|
||||||
|
@ -138,6 +144,7 @@ async function initApp() {
|
||||||
try {
|
try {
|
||||||
loadCoreModules();
|
loadCoreModules();
|
||||||
await loadPluginModules();
|
await loadPluginModules();
|
||||||
|
await loadCurrentUser();
|
||||||
app.provide<MenuGroupType[]>("menus", menus);
|
app.provide<MenuGroupType[]>("menus", menus);
|
||||||
app.provide<MenuItemType[]>("minimenus", minimenus);
|
app.provide<MenuItemType[]>("minimenus", minimenus);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ const loginForm = ref<LoginFormState>({
|
||||||
state: {
|
state: {
|
||||||
_csrf: "",
|
_csrf: "",
|
||||||
username: "admin",
|
username: "admin",
|
||||||
password: "wsYdVrLTYnLbzN6e",
|
password: "{no}123456",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue