You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.2 KiB
130 lines
3.2 KiB
<script lang="ts" setup>
|
|
import { computed, onMounted, watch } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
|
|
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
|
import { useWatermark } from '@vben/hooks';
|
|
import { UserOutlined } from '@vben/icons';
|
|
import {
|
|
BasicLayout,
|
|
LockScreen,
|
|
Notification,
|
|
UserDropdown,
|
|
} from '@vben/layouts';
|
|
import { preferences } from '@vben/preferences';
|
|
import { useAccessStore, useUserStore } from '@vben/stores';
|
|
|
|
import { message } from 'ant-design-vue';
|
|
|
|
import { TenantToggle } from '#/components/tenant-toggle';
|
|
import { $t } from '#/locales';
|
|
import { resetRoutes } from '#/router';
|
|
import { useAuthStore, useNotifyStore } from '#/store';
|
|
import { useTenantStore } from '#/store/tenant';
|
|
import LoginForm from '#/views/_core/authentication/login.vue';
|
|
|
|
const userStore = useUserStore();
|
|
const authStore = useAuthStore();
|
|
const accessStore = useAccessStore();
|
|
const router = useRouter();
|
|
const { destroyWatermark, updateWatermark } = useWatermark();
|
|
|
|
const tenantStore = useTenantStore();
|
|
const menus = computed(() => {
|
|
const defaultMenus = [
|
|
{
|
|
handler: () => {
|
|
router.push('/profile');
|
|
},
|
|
icon: UserOutlined,
|
|
text: $t('ui.widgets.profile'),
|
|
},
|
|
];
|
|
/**
|
|
* 租户选中状态 不显示个人中心
|
|
*/
|
|
if (tenantStore.checked) {
|
|
defaultMenus.splice(1, 1);
|
|
}
|
|
return defaultMenus;
|
|
});
|
|
|
|
const avatar = computed(() => {
|
|
return userStore.userInfo?.avatar || preferences.app.defaultAvatar;
|
|
});
|
|
|
|
async function handleLogout() {
|
|
/**
|
|
* 主动登出不需要带跳转地址
|
|
*/
|
|
await authStore.logout(false);
|
|
resetRoutes();
|
|
}
|
|
|
|
const notifyStore = useNotifyStore();
|
|
onMounted(() => notifyStore.startListeningMessage());
|
|
|
|
function handleViewAll() {
|
|
message.warning('暂未开放');
|
|
}
|
|
watch(
|
|
() => ({
|
|
enable: preferences.app.watermark,
|
|
content: preferences.app.watermarkContent,
|
|
}),
|
|
async ({ enable, content }) => {
|
|
if (enable) {
|
|
await updateWatermark({
|
|
content:
|
|
content ||
|
|
`${userStore.userInfo?.username} - ${userStore.userInfo?.realName}`,
|
|
});
|
|
} else {
|
|
destroyWatermark();
|
|
}
|
|
},
|
|
{
|
|
immediate: true,
|
|
},
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<BasicLayout @clear-preferences-and-logout="handleLogout">
|
|
<template #header-right-1>
|
|
<TenantToggle />
|
|
</template>
|
|
<template #user-dropdown>
|
|
<UserDropdown
|
|
:avatar
|
|
:menus
|
|
:text="userStore.userInfo?.realName"
|
|
:description="userStore.userInfo?.email || '未设置邮箱'"
|
|
:tag-text="userStore.userInfo?.username"
|
|
@logout="handleLogout"
|
|
/>
|
|
</template>
|
|
<template #notification>
|
|
<Notification
|
|
:dot="notifyStore.showDot"
|
|
:notifications="notifyStore.notifications"
|
|
@clear="notifyStore.clearAllMessage"
|
|
@make-all="notifyStore.setAllRead"
|
|
@read="notifyStore.setRead"
|
|
@view-all="handleViewAll"
|
|
/>
|
|
</template>
|
|
<template #extra>
|
|
<AuthenticationLoginExpiredModal
|
|
v-model:open="accessStore.loginExpired"
|
|
:avatar
|
|
>
|
|
<LoginForm />
|
|
</AuthenticationLoginExpiredModal>
|
|
</template>
|
|
<template #lock-screen>
|
|
<LockScreen :avatar @to-login="handleLogout" />
|
|
</template>
|
|
</BasicLayout>
|
|
</template>
|