This commit is contained in:
yangsy
2025-08-15 02:25:24 +08:00
parent bf2fb8ffef
commit 32e355c325
2 changed files with 22 additions and 7 deletions

View File

@@ -8,14 +8,30 @@ function renderIcon(icon: Component): () => VNode {
import { ChevronDown } from '@vicons/ionicons5';
import { AlertFilled, AreaChartOutlined, FileTextFilled, HomeFilled, LogoutOutlined, VideoCameraFilled } from '@vicons/antd';
import { NButton, NDropdown, NFlex, NIcon, NLayout, NLayoutContent, NLayoutFooter, NLayoutHeader, NLayoutSider, NMenu, NScrollbar, type DropdownOption, type MenuOption } from 'naive-ui';
import { h, ref, type Component, type VNode } from 'vue';
import { h, onBeforeMount, onBeforeUnmount, ref, type Component, type VNode } from 'vue';
import { RouterLink, useRoute, useRouter } from 'vue-router';
import { useStationListQuery } from '@/composables/query/use-station-list-query';
import ThemeSwitch from '@/components/theme-switch.vue';
import { useUserStore } from '@/stores/user';
import { useStationStore } from '@/stores/station';
import { storeToRefs } from 'pinia';
import { useStationListQuery } from '@/composables/query/use-station-list-query';
const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore);
useStationListQuery();
onBeforeUnmount(() => {
stationList.value = [];
});
onBeforeMount(() => {
userStore.userGetInfo().catch((err) => window.$message.error(err));
});
const route = useRoute();
const router = useRouter();
@@ -53,7 +69,6 @@ const dropdownOptions = ref<DropdownOption[]>([
key: 'logout',
icon: renderIcon(LogoutOutlined),
onClick: async () => {
const userStore = useUserStore();
await userStore.userLogout();
router.push('/login');
},
@@ -82,7 +97,7 @@ const selectDropdownOption = (key: string, option: DropdownOption) => {
<NDropdown trigger="hover" show-arrow :options="dropdownOptions" @select="selectDropdownOption">
<NButton secondary icon-placement="right" style="margin-right: 8px">
<template #default>
<span>你好</span>
<span>你好{{ userInfo?.nickName ?? '' }}</span>
</template>
<template #icon>
<NIcon :component="ChevronDown" />

View File

@@ -78,11 +78,11 @@ export const useUserStore = defineStore(
};
const userGetInfo = async () => {
const [err, userInfo] = await userClient.get<any>(`/api/oauth/anyone/getUserInfoById`);
if (err || !userInfo) {
const [err, info] = await userClient.get<any>(`/api/oauth/anyone/getUserInfoById`);
if (err || !info) {
throw err;
}
userInfo.value = userInfo;
userInfo.value = info;
};
const userGetResourceList = async () => {