ruoyi-plus-vben5/apps/web-antd/src/layouts/basic.vue

139 lines
3.4 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script lang="ts" setup>
2024-08-07 08:57:56 +08:00
import { computed, onMounted } from 'vue';
2024-09-02 15:13:17 +08:00
import { useRouter } from 'vue-router';
2024-06-01 23:15:29 +08:00
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
2024-08-07 08:57:56 +08:00
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
2024-09-02 15:13:17 +08:00
import { BookOpenText, CircleHelp, MdiGithub, ProfileIcon } from '@vben/icons';
import {
BasicLayout,
LockScreen,
Notification,
UserDropdown,
} from '@vben/layouts';
import { preferences } from '@vben/preferences';
2024-08-07 08:57:56 +08:00
import { storeToRefs, useAccessStore, useUserStore } from '@vben/stores';
import { openWindow } from '@vben/utils';
2024-05-19 21:20:42 +08:00
2024-08-07 08:57:56 +08:00
import { message } from 'ant-design-vue';
2024-08-07 11:55:13 +08:00
import TenantToggle from '#/components/TenantToggle/index.vue';
import { $t } from '#/locales';
import { resetRoutes } from '#/router';
2024-08-07 08:57:56 +08:00
import { useAuthStore, useNotifyStore } from '#/store';
import { useTenantStore } from '#/store/tenant';
2024-05-19 21:20:42 +08:00
2024-07-30 21:10:28 +08:00
const userStore = useUserStore();
const authStore = useAuthStore();
const accessStore = useAccessStore();
2024-09-02 15:13:17 +08:00
const router = useRouter();
const tenantStore = useTenantStore();
const menus = computed(() => {
const defaultMenus = [
{
handler: () => {
openWindow(VBEN_DOC_URL, {
target: '_blank',
});
},
icon: BookOpenText,
text: $t('widgets.document'),
2024-05-19 21:20:42 +08:00
},
{
handler: () => {
router.push('/profile');
},
icon: ProfileIcon,
text: $t('widgets.profile'),
2024-09-02 15:13:17 +08:00
},
{
handler: () => {
openWindow(VBEN_GITHUB_URL, {
target: '_blank',
});
},
icon: MdiGithub,
text: 'GitHub',
2024-05-19 21:20:42 +08:00
},
{
handler: () => {
openWindow(`${VBEN_GITHUB_URL}/issues`, {
target: '_blank',
});
},
icon: CircleHelp,
text: $t('widgets.qa'),
2024-05-19 21:20:42 +08:00
},
];
/**
* 租户选中状态 不显示个人中心
*/
if (tenantStore.checked) {
defaultMenus.splice(1, 1);
}
return defaultMenus;
});
2024-05-19 21:20:42 +08:00
2024-07-30 21:10:28 +08:00
const { loginLoading } = storeToRefs(authStore);
const avatar = computed(() => {
2024-07-30 21:10:28 +08:00
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
});
async function handleLogout() {
2024-08-07 08:57:56 +08:00
// resetAllStores();
resetRoutes();
2024-08-07 08:57:56 +08:00
// await router.replace(LOGIN_PATH);
authStore.logout();
2024-05-19 21:20:42 +08:00
}
2024-08-07 08:57:56 +08:00
const notifyStore = useNotifyStore();
onMounted(() => notifyStore.startListeningMessage());
2024-08-07 08:57:56 +08:00
function handleViewAll() {
message.warning('暂未开放');
}
2024-05-19 21:20:42 +08:00
</script>
<template>
<BasicLayout @clear-preferences-and-logout="handleLogout">
2024-08-07 11:55:13 +08:00
<template #header-right-1>
<TenantToggle />
</template>
2024-05-19 21:20:42 +08:00
<template #user-dropdown>
<UserDropdown
:avatar
:menus
2024-07-30 21:10:28 +08:00
:text="userStore.userInfo?.realName"
2024-05-19 21:20:42 +08:00
description="ann.vben@gmail.com"
tag-text="Pro"
@logout="handleLogout"
/>
</template>
<template #notification>
<Notification
2024-08-07 08:57:56 +08:00
:dot="notifyStore.showDot"
:notifications="notifyStore.notifications"
2024-08-07 08:57:56 +08:00
@clear="notifyStore.clearAllMessage"
@make-all="notifyStore.setAllRead"
@read="notifyStore.setRead"
@view-all="handleViewAll"
2024-05-19 21:20:42 +08:00
/>
</template>
<template #extra>
<AuthenticationLoginExpiredModal
2024-07-30 21:10:28 +08:00
v-model:open="accessStore.loginExpired"
2024-07-18 21:31:34 +08:00
:avatar
2024-07-11 21:48:56 +08:00
:loading="loginLoading"
password-placeholder="123456"
username-placeholder="vben"
2024-07-30 21:10:28 +08:00
@submit="authStore.authLogin"
/>
</template>
<template #lock-screen>
<LockScreen :avatar @to-login="handleLogout" />
</template>
2024-05-19 21:20:42 +08:00
</BasicLayout>
</template>